]>
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 ]; | |
79 | imports = builtins.attrValues (import ../..); | |
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 | ||
8bf83d7a | 85 | users.users.backup = { |
8bf83d7a IB |
86 | hashedPassword = "!"; |
87 | isSystemUser = true; | |
5dda316b | 88 | extraGroups = [ "keys" ]; |
8bf83d7a IB |
89 | shell = pkgs.bashInteractive; |
90 | openssh.authorizedKeys.keys = let | |
5dda316b | 91 | zreplConfig = config.secrets.fullPaths."zrepl/zrepl.yml"; |
8bf83d7a | 92 | in |
5dda316b | 93 | ["command=\"${pkgs.zrepl}/bin/zrepl stdinserver --config ${zreplConfig} eldiron\",restrict ${config.myEnv.zrepl_backup.ssh_key.public}"]; |
8bf83d7a | 94 | }; |
50c100ba | 95 | security.sudo.extraRules = pkgs.lib.mkAfter [ |
50c100ba IB |
96 | { |
97 | commands = [ | |
98 | { command = "/home/immae/.nix-profile/root_scripts/*"; options = [ "NOPASSWD" ]; } | |
99 | ]; | |
100 | users = [ "immae" ]; | |
101 | runAs = "root"; | |
102 | } | |
8bf83d7a IB |
103 | ]; |
104 | ||
6c95e93c IB |
105 | system.activationScripts.libvirtd_exports = '' |
106 | install -m 0755 -o root -g root -d /var/lib/caldance | |
107 | ''; | |
f2bc9fcc | 108 | virtualisation.docker.enable = true; |
740a6506 | 109 | virtualisation.docker.storageDriver = "zfs"; |
7067c25c | 110 | virtualisation.libvirtd.enable = true; |
f2bc9fcc | 111 | users.extraUsers.immae.extraGroups = [ "libvirtd" "docker" ]; |
7067c25c IB |
112 | systemd.services.libvirtd.postStart = '' |
113 | install -m 0770 -g libvirtd -d /var/lib/libvirt/images | |
114 | ''; | |
6c95e93c IB |
115 | systemd.services.socat-caldance = { |
116 | description = "Forward ssh port to caldance"; | |
117 | wantedBy = [ "multi-user.target" ]; | |
118 | after = [ "network.target" ]; | |
119 | ||
120 | serviceConfig = { | |
121 | ExecStart = "${pkgs.socat}/bin/socat TCP-LISTEN:8022,fork TCP:nixops-99a7e1ba-54dc-11ea-a965-10bf487fe63b-caldance:22"; | |
122 | }; | |
123 | }; | |
7067c25c | 124 | |
8a304ef4 IB |
125 | time.timeZone = "Europe/Paris"; |
126 | nix = { | |
127 | useSandbox = "relaxed"; | |
128 | extraOptions = '' | |
129 | keep-outputs = true | |
130 | keep-derivations = true | |
969d8daf | 131 | allow-unsafe-native-code-during-evaluation = true |
bb9bc238 | 132 | experimental-features = nix-command flakes |
8a304ef4 IB |
133 | #Assumed in NUR |
134 | allow-import-from-derivation = true | |
135 | ''; | |
136 | }; | |
137 | ||
50c100ba IB |
138 | security.pki.certificateFiles = [ |
139 | (pkgs.fetchurl { | |
140 | url = "http://downloads.e.eriomem.net/eriomemca.pem"; | |
141 | sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh"; | |
142 | }) | |
143 | ]; | |
144 | ||
8a304ef4 IB |
145 | # This is equivalent to setting environment.sessionVariables.NIX_PATH |
146 | nix.nixPath = [ | |
38ac9a57 IB |
147 | "home-manager=${pkgs.sources.home-manager.url}" |
148 | "nixpkgs=${pkgs.sources.nixpkgs-home-manager.url}" | |
8a304ef4 | 149 | ]; |
75d88eda | 150 | nix.binaryCaches = [ "https://hydra.iohk.io" "https://cache.nixos.org" ]; |
50c100ba | 151 | nix.binaryCachePublicKeys = [ "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" ]; |
8a304ef4 | 152 | |
6ee77836 | 153 | myServices.monitoring.enable = true; |
ba941296 IB |
154 | myServices.certificates.enable = true; |
155 | security.acme.certs."${name}" = { | |
156 | user = config.services.nginx.user; | |
157 | group = config.services.nginx.group; | |
158 | extraDomains = { | |
63500b22 | 159 | "dev.immae.eu" = null; |
6c95e93c | 160 | "caldance.immae.eu" = null; |
ba941296 IB |
161 | }; |
162 | }; | |
163 | services.nginx = { | |
164 | enable = true; | |
165 | recommendedOptimisation = true; | |
166 | recommendedGzipSettings = true; | |
167 | recommendedProxySettings = true; | |
6c95e93c IB |
168 | upstreams = { |
169 | caldance.servers."nixops-99a7e1ba-54dc-11ea-a965-10bf487fe63b-caldance:3031" = {}; | |
170 | }; | |
ba941296 | 171 | virtualHosts = { |
63500b22 IB |
172 | "dev.immae.eu" = { |
173 | acmeRoot = config.myServices.certificates.webroot; | |
174 | useACMEHost = name; | |
175 | forceSSL = true; | |
176 | root = "/home/immae/www"; | |
177 | }; | |
6c95e93c IB |
178 | "caldance.immae.eu" = { |
179 | acmeRoot = config.myServices.certificates.webroot; | |
180 | useACMEHost = name; | |
181 | forceSSL = true; | |
182 | locations."/".extraConfig = '' | |
183 | uwsgi_pass caldance; | |
184 | ''; | |
185 | locations."/static/".alias = "/var/lib/caldance/caldance/app/www/static/"; | |
186 | locations."/media/".alias = "/var/lib/caldance/caldance/media/"; | |
187 | extraConfig = '' | |
188 | auth_basic "Authentification requise"; | |
189 | auth_basic_user_file ${pkgs.writeText "htpasswd" config.myEnv.websites.caldance.integration.password}; | |
190 | ''; | |
191 | }; | |
ba941296 IB |
192 | }; |
193 | }; | |
194 | ||
5dda316b IB |
195 | systemd.services.zrepl.serviceConfig.RuntimeDirectory = lib.mkForce "zrepl zrepl/stdinserver"; |
196 | systemd.services.zrepl.serviceConfig.User = "backup"; | |
197 | # zfs allow backup create,mount,receive,destroy,rename,snapshot,hold,bookmark,release zpool/backup | |
198 | services.zrepl = { | |
199 | enable = true; | |
200 | config = '' | |
201 | global: | |
202 | control: | |
203 | sockpath: /run/zrepl/control | |
204 | serve: | |
205 | stdinserver: | |
206 | sockdir: /run/zrepl/stdinserver | |
207 | jobs: | |
208 | - type: sink | |
209 | # must not change | |
210 | name: "backup-from-eldiron" | |
211 | root_fs: "zpool/backup" | |
212 | serve: | |
213 | type: stdinserver | |
214 | client_identities: | |
215 | - eldiron | |
216 | ''; | |
217 | }; | |
8a304ef4 IB |
218 | # This value determines the NixOS release with which your system is |
219 | # to be compatible, in order to avoid breaking some software such as | |
220 | # database servers. You should change this only after NixOS release | |
221 | # notes say you should. | |
222 | # https://nixos.org/nixos/manual/release-notes.html | |
d43e0c61 | 223 | system.stateVersion = "20.03"; # Did you read the comment? |
8a304ef4 IB |
224 | } |
225 |