]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/system/dilion.nix
Switch to colemna
[perso/Immae/Config/Nix.git] / modules / private / system / dilion.nix
1 { config, pkgs, name, lib, ... }:
2 {
3 deployment = {
4 targetUser = "root";
5 targetHost = lib.head config.hostEnv.ips.main.ip4;
6 };
7 # ssh-keyscan dilion | nix-shell -p ssh-to-age --run ssh-to-age
8 secrets.ageKeys = [ "age1x49n6qa0arkdpq8530s7umgm0gqkq90exv4jep97q30rfnzknpaqate06a" ];
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" ];
20 kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;
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
27 # available in nixos-20.09
28 #zfs.requestEncryptionCredentials = [ "zpool/root" ];
29 };
30 powerManagement.cpuFreqGovernor = "powersave";
31 hardware.enableRedistributableFirmware = true;
32
33 myEnv = import ../../../nixops/secrets/environment.nix;
34
35 swapDevices = [ { label = "swap"; } ];
36 fileSystems = {
37 "/" = { fsType = "zfs"; device = "zpool/root"; };
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"; };
44 "/data" = { fsType = "ext4"; label = "data"; };
45 "/nix" = { fsType = "ext4"; label = "nix"; };
46 };
47
48 services.udev.extraRules = ''
49 ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="10:bf:48:7f:e6:3b", NAME="eth0"
50 '';
51
52 networking = {
53 hostId = "27c3048d"; # generated with head -c4 /dev/urandom | od -A none -t x4
54 firewall.enable = false;
55 interfaces."eth0".ipv4.addresses =
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));
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 ];
75 };
76
77 myServices.ssh.modules = [ config.myServices.ssh.predefinedModules.regular ];
78 imports = builtins.attrValues (import ../..) ++ [ ./dilion/vms.nix ];
79
80 system.nssModules = [ pkgs.libvirt ];
81 system.nssDatabases.hosts = lib.mkForce [ "files" "libvirt_guest" "mymachines" "dns" "myhostname" ];
82 programs.zsh.enable = true;
83
84 users.users.libvirt = {
85 hashedPassword = "!";
86 shell = pkgs.bashInteractive;
87 isSystemUser = true;
88 group = "libvirtd";
89 packages = [ pkgs.libressl.nc ];
90 openssh.authorizedKeys.keys = [
91 config.myEnv.buildbot.ssh_key.public
92 config.myEnv.sshd.rootKeys.ismael_flony
93 ];
94 };
95
96 users.groups.backup = {};
97 users.users.backup = {
98 hashedPassword = "!";
99 isSystemUser = true;
100 extraGroups = [ "keys" ];
101 group = "backup";
102 shell = pkgs.bashInteractive;
103 openssh.authorizedKeys.keys = let
104 zreplConfig = config.secrets.fullPaths."zrepl/zrepl.yml";
105 in
106 ["command=\"${pkgs.zrepl}/bin/zrepl stdinserver --config ${zreplConfig} eldiron\",restrict ${config.myEnv.zrepl_backup.ssh_key.public}"];
107 };
108 security.sudo.extraRules = pkgs.lib.mkAfter [
109 {
110 commands = [
111 { command = "/home/immae/.nix-profile/root_scripts/*"; options = [ "NOPASSWD" ]; }
112 ];
113 users = [ "immae" ];
114 runAs = "root";
115 }
116 ];
117
118 system.activationScripts.libvirtd_exports = ''
119 install -m 0755 -o root -g root -d /var/lib/caldance
120 '';
121 virtualisation.docker.enable = true;
122 virtualisation.docker.storageDriver = "zfs";
123 virtualisation.libvirtd.enable = true;
124 systemd.services.libvirtd.path = lib.mkAfter [ config.boot.zfs.package ];
125 users.groups.immae = {};
126 users.extraUsers.immae.extraGroups = [ "immae" "libvirtd" "docker" ];
127 systemd.services.libvirtd.postStart = ''
128 install -m 0770 -g libvirtd -d /var/lib/libvirt/images
129 '';
130 systemd.services.socat-caldance = {
131 description = "Forward ssh port to caldance";
132 wantedBy = [ "multi-user.target" ];
133 after = [ "network.target" ];
134
135 serviceConfig = {
136 ExecStart = "${pkgs.socat}/bin/socat TCP-LISTEN:8022,fork TCP:caldance:22";
137 };
138 };
139
140 time.timeZone = "Europe/Paris";
141 nix = {
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 };
148 extraOptions = ''
149 keep-outputs = true
150 keep-derivations = true
151 allow-unsafe-native-code-during-evaluation = true
152 experimental-features = nix-command flakes
153 #Assumed in NUR
154 allow-import-from-derivation = true
155 '';
156 };
157
158 security.pki.certificateFiles = [
159 (pkgs.fetchurl {
160 url = "http://downloads.e.eriomem.net/eriomemca.pem";
161 sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh";
162 })
163 ];
164
165 # This is equivalent to setting environment.sessionVariables.NIX_PATH
166 nix.nixPath = [
167 "home-manager=${pkgs.sources.home-manager.url}"
168 "nixpkgs=${pkgs.sources.nixpkgs-home-manager.url}"
169 ];
170
171 myServices.monitoring.enable = true;
172 myServices.certificates.enable = true;
173 security.acme.certs."${name}-immae" = config.myServices.certificates.certConfig // {
174 group = "immae";
175 domain = "dilion.immae.eu";
176 };
177 security.acme.certs."${name}" = {
178 group = config.services.nginx.group;
179 extraDomainNames = [
180 "dilion.immae.dev"
181 "caldance.cs.immae.dev"
182 "zulip.carpentier.earth"
183 "zulip.tof.carpentier.earth"
184 "zulip.dine.carpentier.earth"
185 "zulip.quentin.carpentier.earth"
186 "zulip.agnes.carpentier.earth"
187
188 "ofn.nc.immae.dev"
189
190 "bookstack.cc.immae.dev"
191 ];
192 };
193 systemd.services.nginx.serviceConfig.ProtectHome = "read-only";
194 services.nginx = {
195 enable = true;
196 recommendedOptimisation = true;
197 recommendedGzipSettings = true;
198 recommendedProxySettings = true;
199 upstreams = {
200 caldance.servers."caldance:3031" = {};
201 };
202 virtualHosts = {
203 "dilion.immae.dev" = {
204 acmeRoot = config.myServices.certificates.webroot;
205 useACMEHost = name;
206 forceSSL = true;
207 locations."/".root = "/home/immae/www";
208 };
209 "caldance.cs.immae.dev" = {
210 acmeRoot = config.myServices.certificates.webroot;
211 useACMEHost = name;
212 forceSSL = true;
213 locations."/".extraConfig = ''
214 uwsgi_pass caldance;
215 '';
216 locations."/static/".alias = "/var/lib/caldance/caldance/app/www/static/";
217 locations."/media/".alias = "/var/lib/caldance/caldance/media/";
218 extraConfig = ''
219 auth_basic "Authentification requise";
220 auth_basic_user_file ${pkgs.writeText "htpasswd" config.myEnv.websites.caldance.integration.password};
221 '';
222 };
223 "bookstack.cc.immae.dev" = {
224 acmeRoot = config.myServices.certificates.webroot;
225 useACMEHost = name;
226 forceSSL = true;
227 locations."/".proxyPass = "http://localhost:4003";
228 };
229 "ofn.nc.immae.dev" = {
230 acmeRoot = config.myServices.certificates.webroot;
231 useACMEHost = name;
232 forceSSL = true;
233 locations."/".proxyPass = "http://localhost:3000";
234 };
235 "zulip.carpentier.earth" = {
236 acmeRoot = config.myServices.certificates.webroot;
237 useACMEHost = name;
238 forceSSL = true;
239 locations."/".proxyPass = "http://localhost:4002";
240 };
241 "zulip.tof.carpentier.earth" = {
242 acmeRoot = config.myServices.certificates.webroot;
243 useACMEHost = name;
244 forceSSL = true;
245 locations."/".proxyPass = "http://localhost:4002";
246 };
247 "zulip.dine.carpentier.earth" = {
248 acmeRoot = config.myServices.certificates.webroot;
249 useACMEHost = name;
250 forceSSL = true;
251 locations."/".proxyPass = "http://localhost:4002";
252 };
253 "zulip.quentin.carpentier.earth" = {
254 acmeRoot = config.myServices.certificates.webroot;
255 useACMEHost = name;
256 forceSSL = true;
257 locations."/".proxyPass = "http://localhost:4002";
258 };
259 "zulip.agnes.carpentier.earth" = {
260 acmeRoot = config.myServices.certificates.webroot;
261 useACMEHost = name;
262 forceSSL = true;
263 locations."/".proxyPass = "http://localhost:4002";
264 };
265 };
266 };
267
268 systemd.services.zrepl.serviceConfig.RuntimeDirectory = lib.mkForce "zrepl zrepl/stdinserver";
269 systemd.services.zrepl.serviceConfig.User = "backup";
270 # pour eldiron:
271 # zfs allow backup create,mount,receive,destroy,rename,snapshot,hold,bookmark,release zpool/backup
272 # pour flony:
273 # zfs allow backup hold,release,bookmark,snapshot,send zpool
274 immaeServices.zrepl = {
275 enable = true;
276 config = ''
277 global:
278 control:
279 sockpath: /run/zrepl/control
280 serve:
281 stdinserver:
282 sockdir: /run/zrepl/stdinserver
283 jobs:
284 - type: sink
285 # must not change
286 name: "backup-from-eldiron"
287 root_fs: "zpool/backup"
288 serve:
289 type: tls
290 listen: :19000
291 ca: ${config.secrets.fullPaths."zrepl/certificates/eldiron.crt"}
292 cert: ${config.secrets.fullPaths."zrepl/certificates/dilion.crt"}
293 key: ${config.secrets.fullPaths."zrepl/dilion.key"}
294 client_cns:
295 - eldiron
296 - type: source
297 # must not change
298 name: "backup-to-wd-zpool"
299 # not encrypted!
300 serve:
301 type: tls
302 listen: :19001
303 ca: ${config.secrets.fullPaths."zrepl/certificates/flony.crt"}
304 cert: ${config.secrets.fullPaths."zrepl/certificates/dilion.crt"}
305 key: ${config.secrets.fullPaths."zrepl/dilion.key"}
306 client_cns:
307 - flony
308 filesystems:
309 "zpool/libvirt<": true
310 "zpool/root<": true
311 snapshotting:
312 type: manual
313 - type: source
314 # must not change
315 name: "backup-to-wd-zpool-docker"
316 # not encrypted!
317 serve:
318 type: tls
319 listen: :19002
320 ca: ${config.secrets.fullPaths."zrepl/certificates/flony.crt"}
321 cert: ${config.secrets.fullPaths."zrepl/certificates/dilion.crt"}
322 key: ${config.secrets.fullPaths."zrepl/dilion.key"}
323 client_cns:
324 - flony
325 filesystems:
326 "zpool/docker<": true
327 snapshotting:
328 type: manual
329 '';
330 };
331 # This value determines the NixOS release with which your system is
332 # to be compatible, in order to avoid breaking some software such as
333 # database servers. You should change this only after NixOS release
334 # notes say you should.
335 # https://nixos.org/nixos/manual/release-notes.html
336 system.stateVersion = "20.03"; # Did you read the comment?
337 }
338