]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/system/dilion.nix
Add monitoring for dilion and quatresaisons
[perso/Immae/Config/Nix.git] / modules / private / system / dilion.nix
CommitLineData
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
8a304ef4
IB
132 #Assumed in NUR
133 allow-import-from-derivation = true
134 '';
135 };
136
50c100ba
IB
137 security.pki.certificateFiles = [
138 (pkgs.fetchurl {
139 url = "http://downloads.e.eriomem.net/eriomemca.pem";
140 sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh";
141 })
142 ];
143
8a304ef4
IB
144 # This is equivalent to setting environment.sessionVariables.NIX_PATH
145 nix.nixPath = [
38ac9a57
IB
146 "home-manager=${pkgs.sources.home-manager.url}"
147 "nixpkgs=${pkgs.sources.nixpkgs-home-manager.url}"
8a304ef4 148 ];
75d88eda 149 nix.binaryCaches = [ "https://hydra.iohk.io" "https://cache.nixos.org" ];
50c100ba 150 nix.binaryCachePublicKeys = [ "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" ];
8a304ef4 151
6ee77836 152 myServices.monitoring.enable = true;
ba941296
IB
153 myServices.certificates.enable = true;
154 security.acme.certs."${name}" = {
155 user = config.services.nginx.user;
156 group = config.services.nginx.group;
157 extraDomains = {
63500b22 158 "dev.immae.eu" = null;
6c95e93c 159 "caldance.immae.eu" = null;
ba941296
IB
160 };
161 };
162 services.nginx = {
163 enable = true;
164 recommendedOptimisation = true;
165 recommendedGzipSettings = true;
166 recommendedProxySettings = true;
6c95e93c
IB
167 upstreams = {
168 caldance.servers."nixops-99a7e1ba-54dc-11ea-a965-10bf487fe63b-caldance:3031" = {};
169 };
ba941296 170 virtualHosts = {
63500b22
IB
171 "dev.immae.eu" = {
172 acmeRoot = config.myServices.certificates.webroot;
173 useACMEHost = name;
174 forceSSL = true;
175 root = "/home/immae/www";
176 };
6c95e93c
IB
177 "caldance.immae.eu" = {
178 acmeRoot = config.myServices.certificates.webroot;
179 useACMEHost = name;
180 forceSSL = true;
181 locations."/".extraConfig = ''
182 uwsgi_pass caldance;
183 '';
184 locations."/static/".alias = "/var/lib/caldance/caldance/app/www/static/";
185 locations."/media/".alias = "/var/lib/caldance/caldance/media/";
186 extraConfig = ''
187 auth_basic "Authentification requise";
188 auth_basic_user_file ${pkgs.writeText "htpasswd" config.myEnv.websites.caldance.integration.password};
189 '';
190 };
ba941296
IB
191 };
192 };
193
5dda316b
IB
194 systemd.services.zrepl.serviceConfig.RuntimeDirectory = lib.mkForce "zrepl zrepl/stdinserver";
195 systemd.services.zrepl.serviceConfig.User = "backup";
196 # zfs allow backup create,mount,receive,destroy,rename,snapshot,hold,bookmark,release zpool/backup
197 services.zrepl = {
198 enable = true;
199 config = ''
200 global:
201 control:
202 sockpath: /run/zrepl/control
203 serve:
204 stdinserver:
205 sockdir: /run/zrepl/stdinserver
206 jobs:
207 - type: sink
208 # must not change
209 name: "backup-from-eldiron"
210 root_fs: "zpool/backup"
211 serve:
212 type: stdinserver
213 client_identities:
214 - eldiron
215 '';
216 };
8a304ef4
IB
217 # This value determines the NixOS release with which your system is
218 # to be compatible, in order to avoid breaking some software such as
219 # database servers. You should change this only after NixOS release
220 # notes say you should.
221 # https://nixos.org/nixos/manual/release-notes.html
d43e0c61 222 system.stateVersion = "20.03"; # Did you read the comment?
8a304ef4
IB
223}
224