]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/system/dilion.nix
Use list for ip4 addresses
[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";
05becbbb 5 targetHost = lib.head config.hostEnv.ips.main.ip4;
34abd6af
IB
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 57 interfaces."eth0".ipv4.addresses =
05becbbb
IB
58 [ { address = lib.head config.hostEnv.ips.main.ip4; prefixLength = 27; } ]
59 ++ pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
60 (n: ips: map (ip: { address = ip; prefixLength = 32; }) (ips.ip4 or []))
61 (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips));
34abd6af
IB
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;
cca9aa2e
IB
185
186 "bookstack.cc.immae.dev" = null;
ba941296
IB
187 };
188 };
189 services.nginx = {
190 enable = true;
191 recommendedOptimisation = true;
192 recommendedGzipSettings = true;
193 recommendedProxySettings = true;
6c95e93c 194 upstreams = {
200690c9 195 caldance.servers."caldance:3031" = {};
6c95e93c 196 };
ba941296 197 virtualHosts = {
7c5e6fe8 198 "dilion.immae.dev" = {
63500b22
IB
199 acmeRoot = config.myServices.certificates.webroot;
200 useACMEHost = name;
201 forceSSL = true;
202 root = "/home/immae/www";
203 };
7c5e6fe8 204 "caldance.cs.immae.dev" = {
6c95e93c
IB
205 acmeRoot = config.myServices.certificates.webroot;
206 useACMEHost = name;
207 forceSSL = true;
208 locations."/".extraConfig = ''
209 uwsgi_pass caldance;
210 '';
211 locations."/static/".alias = "/var/lib/caldance/caldance/app/www/static/";
212 locations."/media/".alias = "/var/lib/caldance/caldance/media/";
213 extraConfig = ''
214 auth_basic "Authentification requise";
215 auth_basic_user_file ${pkgs.writeText "htpasswd" config.myEnv.websites.caldance.integration.password};
216 '';
217 };
cca9aa2e
IB
218 "bookstack.cc.immae.dev" = {
219 acmeRoot = config.myServices.certificates.webroot;
220 useACMEHost = name;
221 forceSSL = true;
222 locations."/".proxyPass = "http://localhost:4003";
223 };
27da4e10
IB
224 "ofn.nc.immae.dev" = {
225 acmeRoot = config.myServices.certificates.webroot;
226 useACMEHost = name;
227 forceSSL = true;
228 locations."/".proxyPass = "http://localhost:3000";
229 };
55b6d76b
IB
230 "zulip.carpentier.earth" = {
231 acmeRoot = config.myServices.certificates.webroot;
232 useACMEHost = name;
233 forceSSL = true;
234 locations."/".proxyPass = "http://localhost:4002";
235 };
236 "zulip.tof.carpentier.earth" = {
237 acmeRoot = config.myServices.certificates.webroot;
238 useACMEHost = name;
239 forceSSL = true;
240 locations."/".proxyPass = "http://localhost:4002";
241 };
242 "zulip.dine.carpentier.earth" = {
243 acmeRoot = config.myServices.certificates.webroot;
244 useACMEHost = name;
245 forceSSL = true;
246 locations."/".proxyPass = "http://localhost:4002";
247 };
248 "zulip.quentin.carpentier.earth" = {
249 acmeRoot = config.myServices.certificates.webroot;
250 useACMEHost = name;
251 forceSSL = true;
252 locations."/".proxyPass = "http://localhost:4002";
253 };
254 "zulip.agnes.carpentier.earth" = {
255 acmeRoot = config.myServices.certificates.webroot;
256 useACMEHost = name;
257 forceSSL = true;
258 locations."/".proxyPass = "http://localhost:4002";
259 };
ba941296
IB
260 };
261 };
262
5dda316b
IB
263 systemd.services.zrepl.serviceConfig.RuntimeDirectory = lib.mkForce "zrepl zrepl/stdinserver";
264 systemd.services.zrepl.serviceConfig.User = "backup";
265 # zfs allow backup create,mount,receive,destroy,rename,snapshot,hold,bookmark,release zpool/backup
266 services.zrepl = {
267 enable = true;
268 config = ''
269 global:
270 control:
271 sockpath: /run/zrepl/control
272 serve:
273 stdinserver:
274 sockdir: /run/zrepl/stdinserver
275 jobs:
276 - type: sink
277 # must not change
278 name: "backup-from-eldiron"
279 root_fs: "zpool/backup"
280 serve:
281 type: stdinserver
282 client_identities:
283 - eldiron
284 '';
285 };
8a304ef4
IB
286 # This value determines the NixOS release with which your system is
287 # to be compatible, in order to avoid breaking some software such as
288 # database servers. You should change this only after NixOS release
289 # notes say you should.
290 # https://nixos.org/nixos/manual/release-notes.html
d43e0c61 291 system.stateVersion = "20.03"; # Did you read the comment?
8a304ef4
IB
292}
293