]>
Commit | Line | Data |
---|---|---|
776aa360 | 1 | { config, pkgs, name, lib, flakes, ... }: |
8a304ef4 | 2 | { |
34abd6af IB |
3 | deployment = { |
4 | targetUser = "root"; | |
05becbbb | 5 | targetHost = lib.head config.hostEnv.ips.main.ip4; |
34abd6af | 6 | }; |
282c67a1 IB |
7 | # ssh-keyscan dilion | nix-shell -p ssh-to-age --run ssh-to-age |
8 | secrets.ageKeys = [ "age1x49n6qa0arkdpq8530s7umgm0gqkq90exv4jep97q30rfnzknpaqate06a" ]; | |
34abd6af IB |
9 | nixpkgs.system = lib.mkOverride 900 "x86_64-linux"; |
10 | boot = { | |
11 | loader = { | |
12 | grub = { | |
13 | version = 2; | |
14 | devices = [ "/dev/sda" "/dev/sdb" "/dev/sdc" "/dev/sdd" ]; | |
15 | }; | |
16 | timeout = 1; | |
17 | }; | |
18 | blacklistedKernelModules = [ "nvidiafb" ]; | |
19 | supportedFilesystems = [ "zfs" ]; | |
e34b3079 | 20 | kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages; |
34abd6af IB |
21 | kernelModules = [ "kvm-intel" ]; |
22 | initrd.availableKernelModules = [ "ahci" "sd_mod" ]; | |
23 | initrd.secrets = { | |
24 | "/boot/pass.key" = "/boot/pass.key"; | |
25 | }; | |
26 | kernel.sysctl."vm.nr_hugepages" = 256; # for xmr-stak | |
6ee77836 IB |
27 | # available in nixos-20.09 |
28 | #zfs.requestEncryptionCredentials = [ "zpool/root" ]; | |
34abd6af | 29 | }; |
34abd6af IB |
30 | powerManagement.cpuFreqGovernor = "powersave"; |
31 | hardware.enableRedistributableFirmware = true; | |
32 | ||
282c67a1 | 33 | myEnv = import ../../../nixops/secrets/environment.nix; |
8a304ef4 | 34 | |
34abd6af | 35 | swapDevices = [ { label = "swap"; } ]; |
740a6506 | 36 | fileSystems = { |
34abd6af | 37 | "/" = { fsType = "zfs"; device = "zpool/root"; }; |
740a6506 IB |
38 | "/boot" = { fsType = "ext4"; device = "/dev/disk/by-uuid/fd1c511e-2bc0-49d5-b8bb-95e7e8c8c816"; }; |
39 | "/etc" = { fsType = "zfs"; device = "zpool/root/etc"; }; | |
40 | "/home" = { fsType = "zfs"; device = "zpool/root/home"; }; | |
41 | "/home/immae" = { fsType = "zfs"; device = "zpool/root/home/immae"; }; | |
42 | "/tmp" = { fsType = "zfs"; device = "zpool/root/tmp"; }; | |
43 | "/var" = { fsType = "zfs"; device = "zpool/root/var"; }; | |
34abd6af IB |
44 | "/data" = { fsType = "ext4"; label = "data"; }; |
45 | "/nix" = { fsType = "ext4"; label = "nix"; }; | |
740a6506 | 46 | }; |
34abd6af IB |
47 | |
48 | services.udev.extraRules = '' | |
49 | ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="10:bf:48:7f:e6:3b", NAME="eth0" | |
50 | ''; | |
740a6506 | 51 | |
8a304ef4 | 52 | networking = { |
31e11cdf | 53 | hostId = "27c3048d"; # generated with head -c4 /dev/urandom | od -A none -t x4 |
8a304ef4 | 54 | firewall.enable = false; |
34abd6af | 55 | interfaces."eth0".ipv4.addresses = |
05becbbb IB |
56 | [ { address = lib.head config.hostEnv.ips.main.ip4; prefixLength = 27; } ] |
57 | ++ pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList | |
58 | (n: ips: map (ip: { address = ip; prefixLength = 32; }) (ips.ip4 or [])) | |
59 | (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips)); | |
34abd6af IB |
60 | interfaces."eth0".ipv6.addresses = |
61 | [ { address = "2a01:4f8:141:53e7::"; prefixLength = 64; } ] | |
62 | ++ pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList | |
63 | (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or [])) | |
64 | config.hostEnv.ips); | |
65 | defaultGateway = { address = "176.9.10.225"; interface = "eth0"; }; | |
66 | defaultGateway6 = { address = "fe80::1"; interface = "eth0"; }; | |
67 | nameservers = [ | |
68 | "213.133.98.98" | |
69 | "213.133.99.99" | |
70 | "213.133.100.100" | |
71 | "2a01:4f8:0:a0a1::add:1010" | |
72 | "2a01:4f8:0:a102::add:9999" | |
73 | "2a01:4f8:0:a111::add:9898" | |
74 | ]; | |
8a304ef4 IB |
75 | }; |
76 | ||
77 | myServices.ssh.modules = [ config.myServices.ssh.predefinedModules.regular ]; | |
776aa360 | 78 | imports = builtins.attrValues (import ../.. flakes) ++ [ ./dilion/vms.nix ]; |
8a304ef4 | 79 | |
6c95e93c | 80 | system.nssModules = [ pkgs.libvirt ]; |
2053ddac | 81 | system.nssDatabases.hosts = lib.mkForce [ "files" "libvirt_guest" "mymachines" "dns" "myhostname" ]; |
8a304ef4 IB |
82 | programs.zsh.enable = true; |
83 | ||
200690c9 IB |
84 | users.users.libvirt = { |
85 | hashedPassword = "!"; | |
86 | shell = pkgs.bashInteractive; | |
87 | isSystemUser = true; | |
88 | group = "libvirtd"; | |
e34b3079 | 89 | packages = [ pkgs.libressl.nc ]; |
282c67a1 IB |
90 | openssh.authorizedKeys.keys = [ |
91 | config.myEnv.buildbot.ssh_key.public | |
92 | config.myEnv.sshd.rootKeys.ismael_flony | |
200690c9 | 93 | ]; |
200690c9 IB |
94 | }; |
95 | ||
e34b3079 | 96 | users.groups.backup = {}; |
8bf83d7a | 97 | users.users.backup = { |
8bf83d7a IB |
98 | hashedPassword = "!"; |
99 | isSystemUser = true; | |
5dda316b | 100 | extraGroups = [ "keys" ]; |
e34b3079 | 101 | group = "backup"; |
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; |
e34b3079 IB |
124 | systemd.services.libvirtd.path = lib.mkAfter [ config.boot.zfs.package ]; |
125 | users.groups.immae = {}; | |
126 | users.extraUsers.immae.extraGroups = [ "immae" "libvirtd" "docker" ]; | |
7067c25c IB |
127 | systemd.services.libvirtd.postStart = '' |
128 | install -m 0770 -g libvirtd -d /var/lib/libvirt/images | |
129 | ''; | |
6c95e93c IB |
130 | systemd.services.socat-caldance = { |
131 | description = "Forward ssh port to caldance"; | |
132 | wantedBy = [ "multi-user.target" ]; | |
133 | after = [ "network.target" ]; | |
134 | ||
135 | serviceConfig = { | |
200690c9 | 136 | ExecStart = "${pkgs.socat}/bin/socat TCP-LISTEN:8022,fork TCP:caldance:22"; |
6c95e93c IB |
137 | }; |
138 | }; | |
7067c25c | 139 | |
8a304ef4 IB |
140 | time.timeZone = "Europe/Paris"; |
141 | nix = { | |
e34b3079 IB |
142 | settings = { |
143 | sandbox = "relaxed"; | |
144 | max-jobs = 8; | |
145 | substituters = [ "https://hydra.iohk.io" "https://cache.nixos.org" ]; | |
146 | trusted-public-keys = [ "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" ]; | |
147 | }; | |
8a304ef4 IB |
148 | extraOptions = '' |
149 | keep-outputs = true | |
150 | keep-derivations = true | |
969d8daf | 151 | allow-unsafe-native-code-during-evaluation = true |
bb9bc238 | 152 | experimental-features = nix-command flakes |
8a304ef4 IB |
153 | #Assumed in NUR |
154 | allow-import-from-derivation = true | |
155 | ''; | |
156 | }; | |
157 | ||
50c100ba IB |
158 | security.pki.certificateFiles = [ |
159 | (pkgs.fetchurl { | |
160 | url = "http://downloads.e.eriomem.net/eriomemca.pem"; | |
161 | sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh"; | |
162 | }) | |
163 | ]; | |
164 | ||
8a304ef4 IB |
165 | # This is equivalent to setting environment.sessionVariables.NIX_PATH |
166 | nix.nixPath = [ | |
38ac9a57 IB |
167 | "home-manager=${pkgs.sources.home-manager.url}" |
168 | "nixpkgs=${pkgs.sources.nixpkgs-home-manager.url}" | |
8a304ef4 IB |
169 | ]; |
170 | ||
6ee77836 | 171 | myServices.monitoring.enable = true; |
ba941296 | 172 | myServices.certificates.enable = true; |
83e79a89 | 173 | security.acme.certs."${name}-immae" = config.myServices.certificates.certConfig // { |
e34b3079 | 174 | group = "immae"; |
83e79a89 IB |
175 | domain = "dilion.immae.eu"; |
176 | }; | |
ba941296 | 177 | security.acme.certs."${name}" = { |
ba941296 | 178 | group = config.services.nginx.group; |
e34b3079 IB |
179 | extraDomainNames = [ |
180 | "dilion.immae.dev" | |
181 | "caldance.cs.immae.dev" | |
27da4e10 | 182 | |
cc0ec972 | 183 | "mobilizon.lesateliersduchangement.org" |
e34b3079 | 184 | ]; |
ba941296 | 185 | }; |
5db88013 | 186 | systemd.services.nginx.serviceConfig.ProtectHome = "read-only"; |
ba941296 IB |
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; | |
5db88013 | 200 | locations."/".root = "/home/immae/www"; |
63500b22 | 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 | }; | |
cc0ec972 | 216 | "mobilizon.lesateliersduchangement.org" = { |
55b6d76b IB |
217 | acmeRoot = config.myServices.certificates.webroot; |
218 | useACMEHost = name; | |
219 | forceSSL = true; | |
cc0ec972 | 220 | locations."/".proxyPass = "http://localhost:19003"; |
55b6d76b | 221 | }; |
ba941296 IB |
222 | }; |
223 | }; | |
224 | ||
5dda316b IB |
225 | systemd.services.zrepl.serviceConfig.RuntimeDirectory = lib.mkForce "zrepl zrepl/stdinserver"; |
226 | systemd.services.zrepl.serviceConfig.User = "backup"; | |
17069bb6 | 227 | # pour eldiron: |
5dda316b | 228 | # zfs allow backup create,mount,receive,destroy,rename,snapshot,hold,bookmark,release zpool/backup |
17069bb6 IB |
229 | # pour flony: |
230 | # zfs allow backup hold,release,bookmark,snapshot,send zpool | |
e34b3079 | 231 | immaeServices.zrepl = { |
5dda316b IB |
232 | enable = true; |
233 | config = '' | |
234 | global: | |
235 | control: | |
236 | sockpath: /run/zrepl/control | |
237 | serve: | |
238 | stdinserver: | |
239 | sockdir: /run/zrepl/stdinserver | |
240 | jobs: | |
241 | - type: sink | |
242 | # must not change | |
243 | name: "backup-from-eldiron" | |
244 | root_fs: "zpool/backup" | |
245 | serve: | |
17069bb6 IB |
246 | type: tls |
247 | listen: :19000 | |
248 | ca: ${config.secrets.fullPaths."zrepl/certificates/eldiron.crt"} | |
249 | cert: ${config.secrets.fullPaths."zrepl/certificates/dilion.crt"} | |
250 | key: ${config.secrets.fullPaths."zrepl/dilion.key"} | |
251 | client_cns: | |
5dda316b | 252 | - eldiron |
17069bb6 IB |
253 | - type: source |
254 | # must not change | |
255 | name: "backup-to-wd-zpool" | |
256 | # not encrypted! | |
257 | serve: | |
258 | type: tls | |
259 | listen: :19001 | |
260 | ca: ${config.secrets.fullPaths."zrepl/certificates/flony.crt"} | |
261 | cert: ${config.secrets.fullPaths."zrepl/certificates/dilion.crt"} | |
262 | key: ${config.secrets.fullPaths."zrepl/dilion.key"} | |
263 | client_cns: | |
264 | - flony | |
265 | filesystems: | |
17069bb6 IB |
266 | "zpool/libvirt<": true |
267 | "zpool/root<": true | |
268 | snapshotting: | |
269 | type: manual | |
e34b3079 IB |
270 | - type: source |
271 | # must not change | |
272 | name: "backup-to-wd-zpool-docker" | |
273 | # not encrypted! | |
274 | serve: | |
275 | type: tls | |
276 | listen: :19002 | |
277 | ca: ${config.secrets.fullPaths."zrepl/certificates/flony.crt"} | |
278 | cert: ${config.secrets.fullPaths."zrepl/certificates/dilion.crt"} | |
279 | key: ${config.secrets.fullPaths."zrepl/dilion.key"} | |
280 | client_cns: | |
281 | - flony | |
282 | filesystems: | |
283 | "zpool/docker<": true | |
284 | snapshotting: | |
285 | type: manual | |
5dda316b IB |
286 | ''; |
287 | }; | |
8a304ef4 IB |
288 | # This value determines the NixOS release with which your system is |
289 | # to be compatible, in order to avoid breaking some software such as | |
290 | # database servers. You should change this only after NixOS release | |
291 | # notes say you should. | |
292 | # https://nixos.org/nixos/manual/release-notes.html | |
d43e0c61 | 293 | system.stateVersion = "20.03"; # Did you read the comment? |
8a304ef4 IB |
294 | } |
295 |