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