]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/system/dilion.nix
Update secrets
[perso/Immae/Config/Nix.git] / modules / private / system / dilion.nix
CommitLineData
6c95e93c 1{ config, pkgs, name, lib, ... }:
8a304ef4 2{
34abd6af
IB
3 deployment = {
4 targetUser = "root";
5 targetHost = config.hostEnv.ips.main.ip4;
6 substituteOnDestination = true;
7 };
282c67a1
IB
8 # ssh-keyscan dilion | nix-shell -p ssh-to-age --run ssh-to-age
9 secrets.ageKeys = [ "age1x49n6qa0arkdpq8530s7umgm0gqkq90exv4jep97q30rfnzknpaqate06a" ];
34abd6af
IB
10 nixpkgs.system = lib.mkOverride 900 "x86_64-linux";
11 boot = {
12 loader = {
13 grub = {
14 version = 2;
15 devices = [ "/dev/sda" "/dev/sdb" "/dev/sdc" "/dev/sdd" ];
16 };
17 timeout = 1;
18 };
19 blacklistedKernelModules = [ "nvidiafb" ];
20 supportedFilesystems = [ "zfs" ];
21 kernelPackages = pkgs.linuxPackages_latest;
22 kernelModules = [ "kvm-intel" ];
23 initrd.availableKernelModules = [ "ahci" "sd_mod" ];
24 initrd.secrets = {
25 "/boot/pass.key" = "/boot/pass.key";
26 };
27 kernel.sysctl."vm.nr_hugepages" = 256; # for xmr-stak
6ee77836
IB
28 # available in nixos-20.09
29 #zfs.requestEncryptionCredentials = [ "zpool/root" ];
34abd6af
IB
30 };
31 nix.maxJobs = 8;
32 powerManagement.cpuFreqGovernor = "powersave";
33 hardware.enableRedistributableFirmware = true;
34
282c67a1 35 myEnv = import ../../../nixops/secrets/environment.nix;
8a304ef4 36
34abd6af 37 swapDevices = [ { label = "swap"; } ];
740a6506 38 fileSystems = {
34abd6af 39 "/" = { fsType = "zfs"; device = "zpool/root"; };
740a6506
IB
40 "/boot" = { fsType = "ext4"; device = "/dev/disk/by-uuid/fd1c511e-2bc0-49d5-b8bb-95e7e8c8c816"; };
41 "/etc" = { fsType = "zfs"; device = "zpool/root/etc"; };
42 "/home" = { fsType = "zfs"; device = "zpool/root/home"; };
43 "/home/immae" = { fsType = "zfs"; device = "zpool/root/home/immae"; };
44 "/tmp" = { fsType = "zfs"; device = "zpool/root/tmp"; };
45 "/var" = { fsType = "zfs"; device = "zpool/root/var"; };
34abd6af
IB
46 "/data" = { fsType = "ext4"; label = "data"; };
47 "/nix" = { fsType = "ext4"; label = "nix"; };
740a6506 48 };
34abd6af
IB
49
50 services.udev.extraRules = ''
51 ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="10:bf:48:7f:e6:3b", NAME="eth0"
52 '';
740a6506 53
8a304ef4 54 networking = {
31e11cdf 55 hostId = "27c3048d"; # generated with head -c4 /dev/urandom | od -A none -t x4
8a304ef4 56 firewall.enable = false;
34abd6af
IB
57 interfaces."eth0".ipv4.addresses =
58 [ { address = config.hostEnv.ips.main.ip4; prefixLength = 27; } ]
59 ++ pkgs.lib.attrsets.mapAttrsToList
60 (n: ips: { address = ips.ip4; prefixLength = 32; })
61 (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips);
62 interfaces."eth0".ipv6.addresses =
63 [ { address = "2a01:4f8:141:53e7::"; prefixLength = 64; } ]
64 ++ pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
65 (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or []))
66 config.hostEnv.ips);
67 defaultGateway = { address = "176.9.10.225"; interface = "eth0"; };
68 defaultGateway6 = { address = "fe80::1"; interface = "eth0"; };
69 nameservers = [
70 "213.133.98.98"
71 "213.133.99.99"
72 "213.133.100.100"
73 "2a01:4f8:0:a0a1::add:1010"
74 "2a01:4f8:0:a102::add:9999"
75 "2a01:4f8:0:a111::add:9898"
76 ];
8a304ef4
IB
77 };
78
79 myServices.ssh.modules = [ config.myServices.ssh.predefinedModules.regular ];
200690c9 80 imports = builtins.attrValues (import ../..) ++ [ ./dilion/vms.nix ];
8a304ef4 81
6c95e93c 82 system.nssModules = [ pkgs.libvirt ];
2053ddac 83 system.nssDatabases.hosts = lib.mkForce [ "files" "libvirt_guest" "mymachines" "dns" "myhostname" ];
8a304ef4
IB
84 programs.zsh.enable = true;
85
200690c9
IB
86 users.users.libvirt = {
87 hashedPassword = "!";
88 shell = pkgs.bashInteractive;
89 isSystemUser = true;
90 group = "libvirtd";
91 packages = [ pkgs.netcat-openbsd ];
282c67a1
IB
92 openssh.authorizedKeys.keys = [
93 config.myEnv.buildbot.ssh_key.public
94 config.myEnv.sshd.rootKeys.ismael_flony
200690c9 95 ];
200690c9
IB
96 };
97
8bf83d7a 98 users.users.backup = {
8bf83d7a
IB
99 hashedPassword = "!";
100 isSystemUser = true;
5dda316b 101 extraGroups = [ "keys" ];
8bf83d7a
IB
102 shell = pkgs.bashInteractive;
103 openssh.authorizedKeys.keys = let
5dda316b 104 zreplConfig = config.secrets.fullPaths."zrepl/zrepl.yml";
8bf83d7a 105 in
5dda316b 106 ["command=\"${pkgs.zrepl}/bin/zrepl stdinserver --config ${zreplConfig} eldiron\",restrict ${config.myEnv.zrepl_backup.ssh_key.public}"];
8bf83d7a 107 };
50c100ba 108 security.sudo.extraRules = pkgs.lib.mkAfter [
50c100ba
IB
109 {
110 commands = [
111 { command = "/home/immae/.nix-profile/root_scripts/*"; options = [ "NOPASSWD" ]; }
112 ];
113 users = [ "immae" ];
114 runAs = "root";
115 }
8bf83d7a
IB
116 ];
117
6c95e93c
IB
118 system.activationScripts.libvirtd_exports = ''
119 install -m 0755 -o root -g root -d /var/lib/caldance
120 '';
f2bc9fcc 121 virtualisation.docker.enable = true;
740a6506 122 virtualisation.docker.storageDriver = "zfs";
7067c25c 123 virtualisation.libvirtd.enable = true;
f2bc9fcc 124 users.extraUsers.immae.extraGroups = [ "libvirtd" "docker" ];
7067c25c
IB
125 systemd.services.libvirtd.postStart = ''
126 install -m 0770 -g libvirtd -d /var/lib/libvirt/images
127 '';
6c95e93c
IB
128 systemd.services.socat-caldance = {
129 description = "Forward ssh port to caldance";
130 wantedBy = [ "multi-user.target" ];
131 after = [ "network.target" ];
132
133 serviceConfig = {
200690c9 134 ExecStart = "${pkgs.socat}/bin/socat TCP-LISTEN:8022,fork TCP:caldance:22";
6c95e93c
IB
135 };
136 };
7067c25c 137
8a304ef4
IB
138 time.timeZone = "Europe/Paris";
139 nix = {
140 useSandbox = "relaxed";
141 extraOptions = ''
142 keep-outputs = true
143 keep-derivations = true
969d8daf 144 allow-unsafe-native-code-during-evaluation = true
bb9bc238 145 experimental-features = nix-command flakes
8a304ef4
IB
146 #Assumed in NUR
147 allow-import-from-derivation = true
148 '';
149 };
150
50c100ba
IB
151 security.pki.certificateFiles = [
152 (pkgs.fetchurl {
153 url = "http://downloads.e.eriomem.net/eriomemca.pem";
154 sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh";
155 })
156 ];
157
8a304ef4
IB
158 # This is equivalent to setting environment.sessionVariables.NIX_PATH
159 nix.nixPath = [
38ac9a57
IB
160 "home-manager=${pkgs.sources.home-manager.url}"
161 "nixpkgs=${pkgs.sources.nixpkgs-home-manager.url}"
8a304ef4 162 ];
75d88eda 163 nix.binaryCaches = [ "https://hydra.iohk.io" "https://cache.nixos.org" ];
50c100ba 164 nix.binaryCachePublicKeys = [ "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" ];
8a304ef4 165
6ee77836 166 myServices.monitoring.enable = true;
ba941296 167 myServices.certificates.enable = true;
83e79a89
IB
168 security.acme.certs."${name}-immae" = config.myServices.certificates.certConfig // {
169 user = "immae";
170 domain = "dilion.immae.eu";
171 };
ba941296
IB
172 security.acme.certs."${name}" = {
173 user = config.services.nginx.user;
174 group = config.services.nginx.group;
175 extraDomains = {
7c5e6fe8
IB
176 "dilion.immae.dev" = null;
177 "caldance.cs.immae.dev" = null;
55b6d76b
IB
178 "zulip.carpentier.earth" = null;
179 "zulip.tof.carpentier.earth" = null;
180 "zulip.dine.carpentier.earth" = null;
181 "zulip.quentin.carpentier.earth" = null;
182 "zulip.agnes.carpentier.earth" = null;
27da4e10
IB
183
184 "ofn.nc.immae.dev" = null;
ba941296
IB
185 };
186 };
187 services.nginx = {
188 enable = true;
189 recommendedOptimisation = true;
190 recommendedGzipSettings = true;
191 recommendedProxySettings = true;
6c95e93c 192 upstreams = {
200690c9 193 caldance.servers."caldance:3031" = {};
6c95e93c 194 };
ba941296 195 virtualHosts = {
7c5e6fe8 196 "dilion.immae.dev" = {
63500b22
IB
197 acmeRoot = config.myServices.certificates.webroot;
198 useACMEHost = name;
199 forceSSL = true;
200 root = "/home/immae/www";
201 };
7c5e6fe8 202 "caldance.cs.immae.dev" = {
6c95e93c
IB
203 acmeRoot = config.myServices.certificates.webroot;
204 useACMEHost = name;
205 forceSSL = true;
206 locations."/".extraConfig = ''
207 uwsgi_pass caldance;
208 '';
209 locations."/static/".alias = "/var/lib/caldance/caldance/app/www/static/";
210 locations."/media/".alias = "/var/lib/caldance/caldance/media/";
211 extraConfig = ''
212 auth_basic "Authentification requise";
213 auth_basic_user_file ${pkgs.writeText "htpasswd" config.myEnv.websites.caldance.integration.password};
214 '';
215 };
27da4e10
IB
216 "ofn.nc.immae.dev" = {
217 acmeRoot = config.myServices.certificates.webroot;
218 useACMEHost = name;
219 forceSSL = true;
220 locations."/".proxyPass = "http://localhost:3000";
221 };
55b6d76b
IB
222 "zulip.carpentier.earth" = {
223 acmeRoot = config.myServices.certificates.webroot;
224 useACMEHost = name;
225 forceSSL = true;
226 locations."/".proxyPass = "http://localhost:4002";
227 };
228 "zulip.tof.carpentier.earth" = {
229 acmeRoot = config.myServices.certificates.webroot;
230 useACMEHost = name;
231 forceSSL = true;
232 locations."/".proxyPass = "http://localhost:4002";
233 };
234 "zulip.dine.carpentier.earth" = {
235 acmeRoot = config.myServices.certificates.webroot;
236 useACMEHost = name;
237 forceSSL = true;
238 locations."/".proxyPass = "http://localhost:4002";
239 };
240 "zulip.quentin.carpentier.earth" = {
241 acmeRoot = config.myServices.certificates.webroot;
242 useACMEHost = name;
243 forceSSL = true;
244 locations."/".proxyPass = "http://localhost:4002";
245 };
246 "zulip.agnes.carpentier.earth" = {
247 acmeRoot = config.myServices.certificates.webroot;
248 useACMEHost = name;
249 forceSSL = true;
250 locations."/".proxyPass = "http://localhost:4002";
251 };
ba941296
IB
252 };
253 };
254
5dda316b
IB
255 systemd.services.zrepl.serviceConfig.RuntimeDirectory = lib.mkForce "zrepl zrepl/stdinserver";
256 systemd.services.zrepl.serviceConfig.User = "backup";
257 # zfs allow backup create,mount,receive,destroy,rename,snapshot,hold,bookmark,release zpool/backup
258 services.zrepl = {
259 enable = true;
260 config = ''
261 global:
262 control:
263 sockpath: /run/zrepl/control
264 serve:
265 stdinserver:
266 sockdir: /run/zrepl/stdinserver
267 jobs:
268 - type: sink
269 # must not change
270 name: "backup-from-eldiron"
271 root_fs: "zpool/backup"
272 serve:
273 type: stdinserver
274 client_identities:
275 - eldiron
276 '';
277 };
8a304ef4
IB
278 # This value determines the NixOS release with which your system is
279 # to be compatible, in order to avoid breaking some software such as
280 # database servers. You should change this only after NixOS release
281 # notes say you should.
282 # https://nixos.org/nixos/manual/release-notes.html
d43e0c61 283 system.stateVersion = "20.03"; # Did you read the comment?
8a304ef4
IB
284}
285