]>
Commit | Line | Data |
---|---|---|
8a304ef4 | 1 | { privateFiles }: |
6c95e93c | 2 | { config, pkgs, name, lib, ... }: |
8a304ef4 | 3 | { |
31e11cdf | 4 | boot.supportedFilesystems = [ "zfs" ]; |
8a304ef4 IB |
5 | boot.kernelPackages = pkgs.linuxPackages_latest; |
6 | myEnv = import "${privateFiles}/environment.nix" // { inherit privateFiles; }; | |
7 | ||
740a6506 IB |
8 | fileSystems = { |
9 | "/" = lib.mkForce { fsType = "zfs"; device = "zpool/root"; }; | |
10 | "/boot" = { fsType = "ext4"; device = "/dev/disk/by-uuid/fd1c511e-2bc0-49d5-b8bb-95e7e8c8c816"; }; | |
11 | "/etc" = { fsType = "zfs"; device = "zpool/root/etc"; }; | |
12 | "/home" = { fsType = "zfs"; device = "zpool/root/home"; }; | |
13 | "/home/immae" = { fsType = "zfs"; device = "zpool/root/home/immae"; }; | |
14 | "/tmp" = { fsType = "zfs"; device = "zpool/root/tmp"; }; | |
15 | "/var" = { fsType = "zfs"; device = "zpool/root/var"; }; | |
16 | }; | |
17 | boot.initrd.secrets = { | |
18 | "/boot/pass.key" = "/boot/pass.key"; | |
19 | }; | |
20 | ||
8a304ef4 | 21 | networking = { |
31e11cdf | 22 | hostId = "27c3048d"; # generated with head -c4 /dev/urandom | od -A none -t x4 |
8a304ef4 IB |
23 | firewall.enable = false; |
24 | interfaces."eth0".ipv4.addresses = pkgs.lib.attrsets.mapAttrsToList | |
25 | (n: ips: { address = ips.ip4; prefixLength = 32; }) | |
26 | (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips); | |
27 | interfaces."eth0".ipv6.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList | |
28 | (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or [])) | |
29 | config.hostEnv.ips); | |
30 | }; | |
31 | ||
32 | myServices.ssh.modules = [ config.myServices.ssh.predefinedModules.regular ]; | |
33 | imports = builtins.attrValues (import ../..); | |
34 | ||
35 | deployment = { | |
36 | targetEnv = "hetzner"; | |
37 | hetzner = { | |
38 | robotUser = config.myEnv.hetzner.user; | |
39 | robotPass = config.myEnv.hetzner.pass; | |
40 | mainIPv4 = config.hostEnv.ips.main.ip4; | |
41 | partitions = '' | |
42 | clearpart --all --initlabel --drives=sda,sdb,sdc,sdd | |
43 | ||
44 | part swap --recommended --label=swap --fstype=swap --ondisk=sda | |
45 | ||
46 | part raid.1 --grow --ondisk=sdc | |
47 | part raid.2 --grow --ondisk=sdd | |
48 | ||
49 | raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2 | |
50 | ||
51 | part /nix --grow --label=nix --ondisk=sda | |
52 | part /data --grow --label=data --ondisk=sdb | |
53 | ''; | |
54 | }; | |
55 | }; | |
56 | ||
6c95e93c | 57 | system.nssModules = [ pkgs.libvirt ]; |
2053ddac | 58 | system.nssDatabases.hosts = lib.mkForce [ "files" "libvirt_guest" "mymachines" "dns" "myhostname" ]; |
8a304ef4 IB |
59 | programs.zsh.enable = true; |
60 | ||
8bf83d7a | 61 | users.users.backup = { |
8bf83d7a IB |
62 | hashedPassword = "!"; |
63 | isSystemUser = true; | |
5dda316b | 64 | extraGroups = [ "keys" ]; |
8bf83d7a IB |
65 | shell = pkgs.bashInteractive; |
66 | openssh.authorizedKeys.keys = let | |
5dda316b | 67 | zreplConfig = config.secrets.fullPaths."zrepl/zrepl.yml"; |
8bf83d7a | 68 | in |
5dda316b | 69 | ["command=\"${pkgs.zrepl}/bin/zrepl stdinserver --config ${zreplConfig} eldiron\",restrict ${config.myEnv.zrepl_backup.ssh_key.public}"]; |
8bf83d7a | 70 | }; |
50c100ba | 71 | security.sudo.extraRules = pkgs.lib.mkAfter [ |
50c100ba IB |
72 | { |
73 | commands = [ | |
74 | { command = "/home/immae/.nix-profile/root_scripts/*"; options = [ "NOPASSWD" ]; } | |
75 | ]; | |
76 | users = [ "immae" ]; | |
77 | runAs = "root"; | |
78 | } | |
8bf83d7a IB |
79 | ]; |
80 | ||
52549f2e | 81 | boot.kernel.sysctl."vm.nr_hugepages" = 256; # for xmr-stak |
6c95e93c IB |
82 | system.activationScripts.libvirtd_exports = '' |
83 | install -m 0755 -o root -g root -d /var/lib/caldance | |
84 | ''; | |
f2bc9fcc | 85 | virtualisation.docker.enable = true; |
740a6506 | 86 | virtualisation.docker.storageDriver = "zfs"; |
7067c25c | 87 | virtualisation.libvirtd.enable = true; |
f2bc9fcc | 88 | users.extraUsers.immae.extraGroups = [ "libvirtd" "docker" ]; |
7067c25c IB |
89 | systemd.services.libvirtd.postStart = '' |
90 | install -m 0770 -g libvirtd -d /var/lib/libvirt/images | |
91 | ''; | |
6c95e93c IB |
92 | systemd.services.socat-caldance = { |
93 | description = "Forward ssh port to caldance"; | |
94 | wantedBy = [ "multi-user.target" ]; | |
95 | after = [ "network.target" ]; | |
96 | ||
97 | serviceConfig = { | |
98 | ExecStart = "${pkgs.socat}/bin/socat TCP-LISTEN:8022,fork TCP:nixops-99a7e1ba-54dc-11ea-a965-10bf487fe63b-caldance:22"; | |
99 | }; | |
100 | }; | |
7067c25c | 101 | |
8a304ef4 IB |
102 | time.timeZone = "Europe/Paris"; |
103 | nix = { | |
104 | useSandbox = "relaxed"; | |
105 | extraOptions = '' | |
106 | keep-outputs = true | |
107 | keep-derivations = true | |
108 | #Assumed in NUR | |
109 | allow-import-from-derivation = true | |
110 | ''; | |
111 | }; | |
112 | ||
50c100ba IB |
113 | security.pki.certificateFiles = [ |
114 | (pkgs.fetchurl { | |
115 | url = "http://downloads.e.eriomem.net/eriomemca.pem"; | |
116 | sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh"; | |
117 | }) | |
118 | ]; | |
119 | ||
8a304ef4 IB |
120 | # This is equivalent to setting environment.sessionVariables.NIX_PATH |
121 | nix.nixPath = [ | |
38ac9a57 IB |
122 | "home-manager=${pkgs.sources.home-manager.url}" |
123 | "nixpkgs=${pkgs.sources.nixpkgs-home-manager.url}" | |
8a304ef4 | 124 | ]; |
75d88eda | 125 | nix.binaryCaches = [ "https://hydra.iohk.io" "https://cache.nixos.org" ]; |
50c100ba | 126 | nix.binaryCachePublicKeys = [ "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" ]; |
8a304ef4 | 127 | |
ba941296 IB |
128 | myServices.certificates.enable = true; |
129 | security.acme.certs."${name}" = { | |
130 | user = config.services.nginx.user; | |
131 | group = config.services.nginx.group; | |
132 | extraDomains = { | |
63500b22 | 133 | "dev.immae.eu" = null; |
6c95e93c | 134 | "caldance.immae.eu" = null; |
ba941296 IB |
135 | }; |
136 | }; | |
137 | services.nginx = { | |
138 | enable = true; | |
139 | recommendedOptimisation = true; | |
140 | recommendedGzipSettings = true; | |
141 | recommendedProxySettings = true; | |
6c95e93c IB |
142 | upstreams = { |
143 | caldance.servers."nixops-99a7e1ba-54dc-11ea-a965-10bf487fe63b-caldance:3031" = {}; | |
144 | }; | |
ba941296 | 145 | virtualHosts = { |
63500b22 IB |
146 | "dev.immae.eu" = { |
147 | acmeRoot = config.myServices.certificates.webroot; | |
148 | useACMEHost = name; | |
149 | forceSSL = true; | |
150 | root = "/home/immae/www"; | |
151 | }; | |
6c95e93c IB |
152 | "caldance.immae.eu" = { |
153 | acmeRoot = config.myServices.certificates.webroot; | |
154 | useACMEHost = name; | |
155 | forceSSL = true; | |
156 | locations."/".extraConfig = '' | |
157 | uwsgi_pass caldance; | |
158 | ''; | |
159 | locations."/static/".alias = "/var/lib/caldance/caldance/app/www/static/"; | |
160 | locations."/media/".alias = "/var/lib/caldance/caldance/media/"; | |
161 | extraConfig = '' | |
162 | auth_basic "Authentification requise"; | |
163 | auth_basic_user_file ${pkgs.writeText "htpasswd" config.myEnv.websites.caldance.integration.password}; | |
164 | ''; | |
165 | }; | |
ba941296 IB |
166 | }; |
167 | }; | |
168 | ||
5dda316b IB |
169 | systemd.services.zrepl.serviceConfig.RuntimeDirectory = lib.mkForce "zrepl zrepl/stdinserver"; |
170 | systemd.services.zrepl.serviceConfig.User = "backup"; | |
171 | # zfs allow backup create,mount,receive,destroy,rename,snapshot,hold,bookmark,release zpool/backup | |
172 | services.zrepl = { | |
173 | enable = true; | |
174 | config = '' | |
175 | global: | |
176 | control: | |
177 | sockpath: /run/zrepl/control | |
178 | serve: | |
179 | stdinserver: | |
180 | sockdir: /run/zrepl/stdinserver | |
181 | jobs: | |
182 | - type: sink | |
183 | # must not change | |
184 | name: "backup-from-eldiron" | |
185 | root_fs: "zpool/backup" | |
186 | serve: | |
187 | type: stdinserver | |
188 | client_identities: | |
189 | - eldiron | |
190 | ''; | |
191 | }; | |
8a304ef4 IB |
192 | # This value determines the NixOS release with which your system is |
193 | # to be compatible, in order to avoid breaking some software such as | |
194 | # database servers. You should change this only after NixOS release | |
195 | # notes say you should. | |
196 | # https://nixos.org/nixos/manual/release-notes.html | |
d43e0c61 | 197 | system.stateVersion = "20.03"; # Did you read the comment? |
8a304ef4 IB |
198 | } |
199 |