]>
Commit | Line | Data |
---|---|---|
6c95e93c | 1 | { config, pkgs, name, lib, ... }: |
8a304ef4 | 2 | { |
34abd6af IB |
3 | deployment = { |
4 | targetUser = "root"; | |
5 | targetHost = config.hostEnv.ips.main.ip4; | |
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 IB |
57 | interfaces."eth0".ipv4.addresses = |
58 | [ { address = config.hostEnv.ips.main.ip4; prefixLength = 27; } ] | |
59 | ++ pkgs.lib.attrsets.mapAttrsToList | |
60 | (n: ips: { address = ips.ip4; prefixLength = 32; }) | |
61 | (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips); | |
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 = { | |
63500b22 | 176 | "dev.immae.eu" = null; |
6c95e93c | 177 | "caldance.immae.eu" = null; |
ba941296 IB |
178 | }; |
179 | }; | |
180 | services.nginx = { | |
181 | enable = true; | |
182 | recommendedOptimisation = true; | |
183 | recommendedGzipSettings = true; | |
184 | recommendedProxySettings = true; | |
6c95e93c | 185 | upstreams = { |
200690c9 | 186 | caldance.servers."caldance:3031" = {}; |
6c95e93c | 187 | }; |
ba941296 | 188 | virtualHosts = { |
63500b22 IB |
189 | "dev.immae.eu" = { |
190 | acmeRoot = config.myServices.certificates.webroot; | |
191 | useACMEHost = name; | |
192 | forceSSL = true; | |
193 | root = "/home/immae/www"; | |
194 | }; | |
6c95e93c IB |
195 | "caldance.immae.eu" = { |
196 | acmeRoot = config.myServices.certificates.webroot; | |
197 | useACMEHost = name; | |
198 | forceSSL = true; | |
199 | locations."/".extraConfig = '' | |
200 | uwsgi_pass caldance; | |
201 | ''; | |
202 | locations."/static/".alias = "/var/lib/caldance/caldance/app/www/static/"; | |
203 | locations."/media/".alias = "/var/lib/caldance/caldance/media/"; | |
204 | extraConfig = '' | |
205 | auth_basic "Authentification requise"; | |
206 | auth_basic_user_file ${pkgs.writeText "htpasswd" config.myEnv.websites.caldance.integration.password}; | |
207 | ''; | |
208 | }; | |
ba941296 IB |
209 | }; |
210 | }; | |
211 | ||
5dda316b IB |
212 | systemd.services.zrepl.serviceConfig.RuntimeDirectory = lib.mkForce "zrepl zrepl/stdinserver"; |
213 | systemd.services.zrepl.serviceConfig.User = "backup"; | |
214 | # zfs allow backup create,mount,receive,destroy,rename,snapshot,hold,bookmark,release zpool/backup | |
215 | services.zrepl = { | |
216 | enable = true; | |
217 | config = '' | |
218 | global: | |
219 | control: | |
220 | sockpath: /run/zrepl/control | |
221 | serve: | |
222 | stdinserver: | |
223 | sockdir: /run/zrepl/stdinserver | |
224 | jobs: | |
225 | - type: sink | |
226 | # must not change | |
227 | name: "backup-from-eldiron" | |
228 | root_fs: "zpool/backup" | |
229 | serve: | |
230 | type: stdinserver | |
231 | client_identities: | |
232 | - eldiron | |
233 | ''; | |
234 | }; | |
8a304ef4 IB |
235 | # This value determines the NixOS release with which your system is |
236 | # to be compatible, in order to avoid breaking some software such as | |
237 | # database servers. You should change this only after NixOS release | |
238 | # notes say you should. | |
239 | # https://nixos.org/nixos/manual/release-notes.html | |
d43e0c61 | 240 | system.stateVersion = "20.03"; # Did you read the comment? |
8a304ef4 IB |
241 | } |
242 |