]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - systems/dilion/base.nix
Remove private nginx configuration
[perso/Immae/Config/Nix.git] / systems / dilion / base.nix
CommitLineData
1a64deeb 1{ config, pkgs, name, lib, pkgs-no-overlay, secrets, ... }:
8a304ef4 2{
282c67a1
IB
3 # ssh-keyscan dilion | nix-shell -p ssh-to-age --run ssh-to-age
4 secrets.ageKeys = [ "age1x49n6qa0arkdpq8530s7umgm0gqkq90exv4jep97q30rfnzknpaqate06a" ];
34abd6af
IB
5 boot = {
6 loader = {
7 grub = {
34abd6af
IB
8 devices = [ "/dev/sda" "/dev/sdb" "/dev/sdc" "/dev/sdd" ];
9 };
10 timeout = 1;
11 };
12 blacklistedKernelModules = [ "nvidiafb" ];
13 supportedFilesystems = [ "zfs" ];
1a64deeb 14 kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;
34abd6af
IB
15 kernelModules = [ "kvm-intel" ];
16 initrd.availableKernelModules = [ "ahci" "sd_mod" ];
17 initrd.secrets = {
18 "/boot/pass.key" = "/boot/pass.key";
19 };
20 kernel.sysctl."vm.nr_hugepages" = 256; # for xmr-stak
6ee77836
IB
21 # available in nixos-20.09
22 #zfs.requestEncryptionCredentials = [ "zpool/root" ];
34abd6af 23 };
34abd6af
IB
24 powerManagement.cpuFreqGovernor = "powersave";
25 hardware.enableRedistributableFirmware = true;
26
34abd6af 27 swapDevices = [ { label = "swap"; } ];
740a6506 28 fileSystems = {
34abd6af 29 "/" = { fsType = "zfs"; device = "zpool/root"; };
740a6506
IB
30 "/boot" = { fsType = "ext4"; device = "/dev/disk/by-uuid/fd1c511e-2bc0-49d5-b8bb-95e7e8c8c816"; };
31 "/etc" = { fsType = "zfs"; device = "zpool/root/etc"; };
32 "/home" = { fsType = "zfs"; device = "zpool/root/home"; };
740a6506
IB
33 "/tmp" = { fsType = "zfs"; device = "zpool/root/tmp"; };
34 "/var" = { fsType = "zfs"; device = "zpool/root/var"; };
34abd6af
IB
35 "/data" = { fsType = "ext4"; label = "data"; };
36 "/nix" = { fsType = "ext4"; label = "nix"; };
740a6506 37 };
34abd6af
IB
38
39 services.udev.extraRules = ''
40 ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="10:bf:48:7f:e6:3b", NAME="eth0"
41 '';
740a6506 42
1a64deeb
IB
43 nixpkgs.config.permittedInsecurePackages = [
44 "python-2.7.18.6" # for nagios-cli
45 ];
46
8a304ef4 47 networking = {
31e11cdf 48 hostId = "27c3048d"; # generated with head -c4 /dev/urandom | od -A none -t x4
8a304ef4 49 firewall.enable = false;
34abd6af 50 interfaces."eth0".ipv4.addresses =
1a64deeb
IB
51 [ { address = lib.head config.hostEnv.ips.main.ip4; prefixLength = 27; } ]
52 ++ pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
53 (n: ips: map (ip: { address = ip; prefixLength = 32; }) (ips.ip4 or []))
54 (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips));
34abd6af
IB
55 interfaces."eth0".ipv6.addresses =
56 [ { address = "2a01:4f8:141:53e7::"; prefixLength = 64; } ]
57 ++ pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
58 (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or []))
59 config.hostEnv.ips);
60 defaultGateway = { address = "176.9.10.225"; interface = "eth0"; };
61 defaultGateway6 = { address = "fe80::1"; interface = "eth0"; };
62 nameservers = [
63 "213.133.98.98"
64 "213.133.99.99"
65 "213.133.100.100"
66 "2a01:4f8:0:a0a1::add:1010"
67 "2a01:4f8:0:a102::add:9999"
68 "2a01:4f8:0:a111::add:9898"
69 ];
8a304ef4
IB
70 };
71
1a64deeb
IB
72 imports = [
73 secrets.nixosModules.users-config-dilion
74 ./monitoring.nix
75 ./vms.nix
76 ];
77
78 myServices.vms.libvirt-guests = {
79 buildbot = {
80 pool = "zfspool";
81 network = "immae";
82 cpus = 1;
83 memory = 3;
84 diskSize = 10;
85 destroyVolumeOnExit = true;
86 };
87 };
88 myServices.vms.libvirt-images = {
89 nixos = ./vms/base_configuration.nix;
90 buildbot = ./vms/buildbot_configuration.nix;
91 };
92 myServices.vms.libvirt-networks.immae = {
93 bridgeNumber = 1;
94 ipRange = "192.168.100";
95 };
96 myServices.vms.libvirt-pools = {
97 niximages = {
98 type = "dir";
99 target = "/etc/libvirtd/base-images";
100 };
101 buildbot-disks = rec {
102 type = "dir";
103 target = "/var/lib/libvirt/images/buildbot-disks";
104 preStart = ''
105 mkdir -p ${target}
106 '';
107 };
108 zfspool = {
109 # pool-define-as --name zfspool --source-name zpool/libvirt --type zfs
110 type = "zfs";
111 xml = ''
112 <source>
113 <name>zpool/libvirt</name>
114 </source>
115 '';
116 };
117 };
8a304ef4 118
6c95e93c 119 system.nssModules = [ pkgs.libvirt ];
2053ddac 120 system.nssDatabases.hosts = lib.mkForce [ "files" "libvirt_guest" "mymachines" "dns" "myhostname" ];
8a304ef4
IB
121 programs.zsh.enable = true;
122
200690c9
IB
123 users.users.libvirt = {
124 hashedPassword = "!";
125 shell = pkgs.bashInteractive;
126 isSystemUser = true;
127 group = "libvirtd";
1a64deeb 128 packages = [ pkgs.libressl.nc ];
282c67a1
IB
129 openssh.authorizedKeys.keys = [
130 config.myEnv.buildbot.ssh_key.public
131 config.myEnv.sshd.rootKeys.ismael_flony
200690c9 132 ];
200690c9
IB
133 };
134
1a64deeb 135 users.groups.backup = {};
8bf83d7a 136 users.users.backup = {
8bf83d7a
IB
137 hashedPassword = "!";
138 isSystemUser = true;
5dda316b 139 extraGroups = [ "keys" ];
1a64deeb 140 group = "backup";
8bf83d7a
IB
141 shell = pkgs.bashInteractive;
142 openssh.authorizedKeys.keys = let
1a64deeb 143 zreplConfig = "/etc/zrepl/zrepl.yml";
8bf83d7a 144 in
5dda316b 145 ["command=\"${pkgs.zrepl}/bin/zrepl stdinserver --config ${zreplConfig} eldiron\",restrict ${config.myEnv.zrepl_backup.ssh_key.public}"];
8bf83d7a 146 };
8bf83d7a 147
f2bc9fcc 148 virtualisation.docker.enable = true;
740a6506 149 virtualisation.docker.storageDriver = "zfs";
7067c25c 150 virtualisation.libvirtd.enable = true;
1a64deeb
IB
151 virtualisation.libvirtd.qemu.package = pkgs-no-overlay.qemu;
152 systemd.services.libvirtd.path = lib.mkAfter [ config.boot.zfs.package ];
7067c25c
IB
153 systemd.services.libvirtd.postStart = ''
154 install -m 0770 -g libvirtd -d /var/lib/libvirt/images
155 '';
156
8a304ef4
IB
157 time.timeZone = "Europe/Paris";
158 nix = {
1a64deeb
IB
159 settings = {
160 sandbox = "relaxed";
161 max-jobs = 8;
162 substituters = [ "https://hydra.iohk.io" "https://cache.nixos.org" ];
163 trusted-public-keys = [ "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" ];
164 trusted-users = [ "root" "@wheel"] ;
165 };
8a304ef4
IB
166 extraOptions = ''
167 keep-outputs = true
168 keep-derivations = true
969d8daf 169 allow-unsafe-native-code-during-evaluation = true
bb9bc238 170 experimental-features = nix-command flakes
8a304ef4
IB
171 #Assumed in NUR
172 allow-import-from-derivation = true
173 '';
174 };
175
50c100ba
IB
176 security.pki.certificateFiles = [
177 (pkgs.fetchurl {
178 url = "http://downloads.e.eriomem.net/eriomemca.pem";
179 sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh";
180 })
181 ];
182
6ee77836 183 myServices.monitoring.enable = true;
1a64deeb
IB
184 security.acme.certs."${name}-immae" = {
185 group = "immae";
83e79a89
IB
186 domain = "dilion.immae.eu";
187 };
ba941296 188 security.acme.certs."${name}" = {
ba941296 189 group = config.services.nginx.group;
1a64deeb
IB
190 extraDomainNames = [
191 "dilion.immae.dev"
192 ];
ba941296 193 };
1a64deeb 194 systemd.services.nginx.serviceConfig.ProtectHome = "read-only";
ba941296
IB
195 services.nginx = {
196 enable = true;
197 recommendedOptimisation = true;
198 recommendedGzipSettings = true;
199 recommendedProxySettings = true;
200 virtualHosts = {
7c5e6fe8 201 "dilion.immae.dev" = {
1a64deeb 202 acmeRoot = config.security.acme.defaults.webroot;
63500b22
IB
203 useACMEHost = name;
204 forceSSL = true;
6c95e93c 205 };
ba941296
IB
206 };
207 };
208
1a64deeb
IB
209 secrets.keys = {
210 "zrepl/${name}.key" = {
211 permissions = "0400";
212 text = config.myEnv.zrepl_backup.certs."${name}".key;
213 user = "backup";
214 group = "root";
215 };
216 } // builtins.listToAttrs (map (x: lib.attrsets.nameValuePair "zrepl/certificates/${x}.crt" {
217 permissions = "0400";
218 text = config.myEnv.zrepl_backup.certs."${x}".certificate;
219 user = "backup";
220 group = "root";
221 }) (builtins.attrNames config.myEnv.zrepl_backup.certs));
222
223 environment.etc."mdadm.conf" = {
224 enable = true;
225 mode = "0644";
226 user = "root";
227 text = "MAILADDR ${config.myEnv.monitoring.email}";
228 };
229
230
5dda316b 231 systemd.services.zrepl.serviceConfig.User = "backup";
1a64deeb
IB
232 systemd.services.zrepl.path = [ pkgs.openssh ];
233 # pour eldiron:
5dda316b 234 # zfs allow backup create,mount,receive,destroy,rename,snapshot,hold,bookmark,release zpool/backup
1a64deeb
IB
235 # pour flony:
236 # zfs allow backup hold,release,bookmark,snapshot,send zpool
5dda316b
IB
237 services.zrepl = {
238 enable = true;
1a64deeb
IB
239 settings = {
240 global.control.sockpath = "/run/zrepl/control";
241 global.serve.stdinserver.sockdir = "/run/zrepl/stdinserver";
242 jobs = [
243 {
244 type = "sink";
5dda316b 245 # must not change
1a64deeb
IB
246 name = "backup-from-eldiron";
247 root_fs = "zpool/backup";
248 serve.type = "tls";
249 serve.listen = ":19000";
250 serve.ca = config.secrets.fullPaths."zrepl/certificates/eldiron.crt";
251 serve.cert = config.secrets.fullPaths."zrepl/certificates/dilion.crt";
252 serve.key = config.secrets.fullPaths."zrepl/dilion.key";
253 serve.client_cns = [ "eldiron" ];
254 }
255 {
256 type = "source";
257 # must not change
258 name = "backup-to-wd-zpool";
259 # not encrypted!
260 serve.type = "tls";
261 serve.listen = ":19001";
262 serve.ca = config.secrets.fullPaths."zrepl/certificates/flony.crt";
263 serve.cert = config.secrets.fullPaths."zrepl/certificates/dilion.crt";
264 serve.key = config.secrets.fullPaths."zrepl/dilion.key";
265 serve.client_cns = [ "flony" ];
266 filesystems."zpool/libvirt<" = true;
267 filesystems."zpool/root<" = true;
268 snapshotting.type = "manual";
269 }
270 {
271 type = "source";
272 # must not change
273 name = "backup-to-wd-zpool-docker";
274 # not encrypted!
275 serve.type = "tls";
276 serve.listen = ":19002";
277 serve.ca = config.secrets.fullPaths."zrepl/certificates/flony.crt";
278 serve.cert = config.secrets.fullPaths."zrepl/certificates/dilion.crt";
279 serve.key = config.secrets.fullPaths."zrepl/dilion.key";
280 serve.client_cns = [ "flony" ];
281 filesystems."zpool/docker<" = true;
282 snapshotting.type = "manual";
283 }
284 ];
285 };
5dda316b 286 };
8a304ef4
IB
287 # This value determines the NixOS release with which your system is
288 # to be compatible, in order to avoid breaking some software such as
289 # database servers. You should change this only after NixOS release
290 # notes say you should.
291 # https://nixos.org/nixos/manual/release-notes.html
1a64deeb 292 system.stateVersion = "23.05"; # Did you read the comment?
8a304ef4
IB
293}
294