]>
Commit | Line | Data |
---|---|---|
8a304ef4 | 1 | { privateFiles }: |
6c95e93c | 2 | { config, pkgs, name, lib, ... }: |
8a304ef4 | 3 | { |
34abd6af IB |
4 | deployment = { |
5 | targetUser = "root"; | |
6 | targetHost = config.hostEnv.ips.main.ip4; | |
7 | substituteOnDestination = true; | |
8 | }; | |
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 = pkgs.linuxPackages_latest; | |
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 IB |
29 | }; |
30 | nix.maxJobs = 8; | |
31 | powerManagement.cpuFreqGovernor = "powersave"; | |
32 | hardware.enableRedistributableFirmware = true; | |
33 | ||
8a304ef4 IB |
34 | myEnv = import "${privateFiles}/environment.nix" // { inherit privateFiles; }; |
35 | ||
34abd6af | 36 | swapDevices = [ { label = "swap"; } ]; |
740a6506 | 37 | fileSystems = { |
34abd6af | 38 | "/" = { fsType = "zfs"; device = "zpool/root"; }; |
740a6506 IB |
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"; }; | |
34abd6af IB |
45 | "/data" = { fsType = "ext4"; label = "data"; }; |
46 | "/nix" = { fsType = "ext4"; label = "nix"; }; | |
740a6506 | 47 | }; |
34abd6af IB |
48 | |
49 | services.udev.extraRules = '' | |
50 | ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="10:bf:48:7f:e6:3b", NAME="eth0" | |
51 | ''; | |
740a6506 | 52 | |
8a304ef4 | 53 | networking = { |
31e11cdf | 54 | hostId = "27c3048d"; # generated with head -c4 /dev/urandom | od -A none -t x4 |
8a304ef4 | 55 | firewall.enable = false; |
34abd6af IB |
56 | interfaces."eth0".ipv4.addresses = |
57 | [ { address = config.hostEnv.ips.main.ip4; prefixLength = 27; } ] | |
58 | ++ pkgs.lib.attrsets.mapAttrsToList | |
59 | (n: ips: { address = ips.ip4; prefixLength = 32; }) | |
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 | ]; | |
8a304ef4 IB |
76 | }; |
77 | ||
78 | myServices.ssh.modules = [ config.myServices.ssh.predefinedModules.regular ]; | |
200690c9 | 79 | imports = builtins.attrValues (import ../..) ++ [ ./dilion/vms.nix ]; |
8a304ef4 | 80 | |
6c95e93c | 81 | system.nssModules = [ pkgs.libvirt ]; |
2053ddac | 82 | system.nssDatabases.hosts = lib.mkForce [ "files" "libvirt_guest" "mymachines" "dns" "myhostname" ]; |
8a304ef4 IB |
83 | programs.zsh.enable = true; |
84 | ||
200690c9 IB |
85 | users.users.libvirt = { |
86 | hashedPassword = "!"; | |
87 | shell = pkgs.bashInteractive; | |
88 | isSystemUser = true; | |
89 | group = "libvirtd"; | |
90 | packages = [ pkgs.netcat-openbsd ]; | |
91 | openssh.authorizedKeys.keyFiles = [ | |
92 | "${privateFiles}/buildbot_ssh_key.pub" | |
93 | ]; | |
94 | openssh.authorizedKeys.keys = [ config.myEnv.sshd.rootKeys.ismael_flony ]; | |
95 | }; | |
96 | ||
8bf83d7a | 97 | users.users.backup = { |
8bf83d7a IB |
98 | hashedPassword = "!"; |
99 | isSystemUser = true; | |
5dda316b | 100 | extraGroups = [ "keys" ]; |
8bf83d7a IB |
101 | shell = pkgs.bashInteractive; |
102 | openssh.authorizedKeys.keys = let | |
5dda316b | 103 | zreplConfig = config.secrets.fullPaths."zrepl/zrepl.yml"; |
8bf83d7a | 104 | in |
5dda316b | 105 | ["command=\"${pkgs.zrepl}/bin/zrepl stdinserver --config ${zreplConfig} eldiron\",restrict ${config.myEnv.zrepl_backup.ssh_key.public}"]; |
8bf83d7a | 106 | }; |
50c100ba | 107 | security.sudo.extraRules = pkgs.lib.mkAfter [ |
50c100ba IB |
108 | { |
109 | commands = [ | |
110 | { command = "/home/immae/.nix-profile/root_scripts/*"; options = [ "NOPASSWD" ]; } | |
111 | ]; | |
112 | users = [ "immae" ]; | |
113 | runAs = "root"; | |
114 | } | |
8bf83d7a IB |
115 | ]; |
116 | ||
6c95e93c IB |
117 | system.activationScripts.libvirtd_exports = '' |
118 | install -m 0755 -o root -g root -d /var/lib/caldance | |
119 | ''; | |
f2bc9fcc | 120 | virtualisation.docker.enable = true; |
740a6506 | 121 | virtualisation.docker.storageDriver = "zfs"; |
7067c25c | 122 | virtualisation.libvirtd.enable = true; |
f2bc9fcc | 123 | users.extraUsers.immae.extraGroups = [ "libvirtd" "docker" ]; |
7067c25c IB |
124 | systemd.services.libvirtd.postStart = '' |
125 | install -m 0770 -g libvirtd -d /var/lib/libvirt/images | |
126 | ''; | |
6c95e93c IB |
127 | systemd.services.socat-caldance = { |
128 | description = "Forward ssh port to caldance"; | |
129 | wantedBy = [ "multi-user.target" ]; | |
130 | after = [ "network.target" ]; | |
131 | ||
132 | serviceConfig = { | |
200690c9 | 133 | ExecStart = "${pkgs.socat}/bin/socat TCP-LISTEN:8022,fork TCP:caldance:22"; |
6c95e93c IB |
134 | }; |
135 | }; | |
7067c25c | 136 | |
8a304ef4 IB |
137 | time.timeZone = "Europe/Paris"; |
138 | nix = { | |
139 | useSandbox = "relaxed"; | |
140 | extraOptions = '' | |
141 | keep-outputs = true | |
142 | keep-derivations = true | |
969d8daf | 143 | allow-unsafe-native-code-during-evaluation = true |
bb9bc238 | 144 | experimental-features = nix-command flakes |
8a304ef4 IB |
145 | #Assumed in NUR |
146 | allow-import-from-derivation = true | |
147 | ''; | |
148 | }; | |
149 | ||
50c100ba IB |
150 | security.pki.certificateFiles = [ |
151 | (pkgs.fetchurl { | |
152 | url = "http://downloads.e.eriomem.net/eriomemca.pem"; | |
153 | sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh"; | |
154 | }) | |
155 | ]; | |
156 | ||
8a304ef4 IB |
157 | # This is equivalent to setting environment.sessionVariables.NIX_PATH |
158 | nix.nixPath = [ | |
38ac9a57 IB |
159 | "home-manager=${pkgs.sources.home-manager.url}" |
160 | "nixpkgs=${pkgs.sources.nixpkgs-home-manager.url}" | |
8a304ef4 | 161 | ]; |
75d88eda | 162 | nix.binaryCaches = [ "https://hydra.iohk.io" "https://cache.nixos.org" ]; |
50c100ba | 163 | nix.binaryCachePublicKeys = [ "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" ]; |
8a304ef4 | 164 | |
6ee77836 | 165 | myServices.monitoring.enable = true; |
ba941296 | 166 | myServices.certificates.enable = true; |
83e79a89 IB |
167 | security.acme.certs."${name}-immae" = config.myServices.certificates.certConfig // { |
168 | user = "immae"; | |
169 | domain = "dilion.immae.eu"; | |
170 | }; | |
ba941296 IB |
171 | security.acme.certs."${name}" = { |
172 | user = config.services.nginx.user; | |
173 | group = config.services.nginx.group; | |
174 | extraDomains = { | |
63500b22 | 175 | "dev.immae.eu" = null; |
6c95e93c | 176 | "caldance.immae.eu" = null; |
ba941296 IB |
177 | }; |
178 | }; | |
179 | services.nginx = { | |
180 | enable = true; | |
181 | recommendedOptimisation = true; | |
182 | recommendedGzipSettings = true; | |
183 | recommendedProxySettings = true; | |
6c95e93c | 184 | upstreams = { |
200690c9 | 185 | caldance.servers."caldance:3031" = {}; |
6c95e93c | 186 | }; |
ba941296 | 187 | virtualHosts = { |
63500b22 IB |
188 | "dev.immae.eu" = { |
189 | acmeRoot = config.myServices.certificates.webroot; | |
190 | useACMEHost = name; | |
191 | forceSSL = true; | |
192 | root = "/home/immae/www"; | |
193 | }; | |
6c95e93c IB |
194 | "caldance.immae.eu" = { |
195 | acmeRoot = config.myServices.certificates.webroot; | |
196 | useACMEHost = name; | |
197 | forceSSL = true; | |
198 | locations."/".extraConfig = '' | |
199 | uwsgi_pass caldance; | |
200 | ''; | |
201 | locations."/static/".alias = "/var/lib/caldance/caldance/app/www/static/"; | |
202 | locations."/media/".alias = "/var/lib/caldance/caldance/media/"; | |
203 | extraConfig = '' | |
204 | auth_basic "Authentification requise"; | |
205 | auth_basic_user_file ${pkgs.writeText "htpasswd" config.myEnv.websites.caldance.integration.password}; | |
206 | ''; | |
207 | }; | |
ba941296 IB |
208 | }; |
209 | }; | |
210 | ||
5dda316b IB |
211 | systemd.services.zrepl.serviceConfig.RuntimeDirectory = lib.mkForce "zrepl zrepl/stdinserver"; |
212 | systemd.services.zrepl.serviceConfig.User = "backup"; | |
213 | # zfs allow backup create,mount,receive,destroy,rename,snapshot,hold,bookmark,release zpool/backup | |
214 | services.zrepl = { | |
215 | enable = true; | |
216 | config = '' | |
217 | global: | |
218 | control: | |
219 | sockpath: /run/zrepl/control | |
220 | serve: | |
221 | stdinserver: | |
222 | sockdir: /run/zrepl/stdinserver | |
223 | jobs: | |
224 | - type: sink | |
225 | # must not change | |
226 | name: "backup-from-eldiron" | |
227 | root_fs: "zpool/backup" | |
228 | serve: | |
229 | type: stdinserver | |
230 | client_identities: | |
231 | - eldiron | |
232 | ''; | |
233 | }; | |
8a304ef4 IB |
234 | # This value determines the NixOS release with which your system is |
235 | # to be compatible, in order to avoid breaking some software such as | |
236 | # database servers. You should change this only after NixOS release | |
237 | # notes say you should. | |
238 | # https://nixos.org/nixos/manual/release-notes.html | |
d43e0c61 | 239 | system.stateVersion = "20.03"; # Did you read the comment? |
8a304ef4 IB |
240 | } |
241 |