]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/system/dilion.nix
Add OpenARC flake
[perso/Immae/Config/Nix.git] / modules / private / system / dilion.nix
1 { privateFiles }:
2 { config, pkgs, name, lib, ... }:
3 {
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
27 # available in nixos-20.09
28 #zfs.requestEncryptionCredentials = [ "zpool/root" ];
29 };
30 nix.maxJobs = 8;
31 powerManagement.cpuFreqGovernor = "powersave";
32 hardware.enableRedistributableFirmware = true;
33
34 myEnv = import "${privateFiles}/environment.nix" // { inherit privateFiles; };
35
36 swapDevices = [ { label = "swap"; } ];
37 fileSystems = {
38 "/" = { fsType = "zfs"; device = "zpool/root"; };
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"; };
45 "/data" = { fsType = "ext4"; label = "data"; };
46 "/nix" = { fsType = "ext4"; label = "nix"; };
47 };
48
49 services.udev.extraRules = ''
50 ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="10:bf:48:7f:e6:3b", NAME="eth0"
51 '';
52
53 networking = {
54 hostId = "27c3048d"; # generated with head -c4 /dev/urandom | od -A none -t x4
55 firewall.enable = false;
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 ];
76 };
77
78 myServices.ssh.modules = [ config.myServices.ssh.predefinedModules.regular ];
79 imports = builtins.attrValues (import ../..);
80
81 system.nssModules = [ pkgs.libvirt ];
82 system.nssDatabases.hosts = lib.mkForce [ "files" "libvirt_guest" "mymachines" "dns" "myhostname" ];
83 programs.zsh.enable = true;
84
85 users.users.backup = {
86 hashedPassword = "!";
87 isSystemUser = true;
88 extraGroups = [ "keys" ];
89 shell = pkgs.bashInteractive;
90 openssh.authorizedKeys.keys = let
91 zreplConfig = config.secrets.fullPaths."zrepl/zrepl.yml";
92 in
93 ["command=\"${pkgs.zrepl}/bin/zrepl stdinserver --config ${zreplConfig} eldiron\",restrict ${config.myEnv.zrepl_backup.ssh_key.public}"];
94 };
95 security.sudo.extraRules = pkgs.lib.mkAfter [
96 {
97 commands = [
98 { command = "/home/immae/.nix-profile/root_scripts/*"; options = [ "NOPASSWD" ]; }
99 ];
100 users = [ "immae" ];
101 runAs = "root";
102 }
103 ];
104
105 system.activationScripts.libvirtd_exports = ''
106 install -m 0755 -o root -g root -d /var/lib/caldance
107 '';
108 virtualisation.docker.enable = true;
109 virtualisation.docker.storageDriver = "zfs";
110 virtualisation.libvirtd.enable = true;
111 users.extraUsers.immae.extraGroups = [ "libvirtd" "docker" ];
112 systemd.services.libvirtd.postStart = ''
113 install -m 0770 -g libvirtd -d /var/lib/libvirt/images
114 '';
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 };
124
125 time.timeZone = "Europe/Paris";
126 nix = {
127 useSandbox = "relaxed";
128 extraOptions = ''
129 keep-outputs = true
130 keep-derivations = true
131 allow-unsafe-native-code-during-evaluation = true
132 experimental-features = nix-command flakes
133 #Assumed in NUR
134 allow-import-from-derivation = true
135 '';
136 };
137
138 security.pki.certificateFiles = [
139 (pkgs.fetchurl {
140 url = "http://downloads.e.eriomem.net/eriomemca.pem";
141 sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh";
142 })
143 ];
144
145 # This is equivalent to setting environment.sessionVariables.NIX_PATH
146 nix.nixPath = [
147 "home-manager=${pkgs.sources.home-manager.url}"
148 "nixpkgs=${pkgs.sources.nixpkgs-home-manager.url}"
149 ];
150 nix.binaryCaches = [ "https://hydra.iohk.io" "https://cache.nixos.org" ];
151 nix.binaryCachePublicKeys = [ "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" ];
152
153 myServices.monitoring.enable = true;
154 myServices.certificates.enable = true;
155 security.acme.certs."${name}" = {
156 user = config.services.nginx.user;
157 group = config.services.nginx.group;
158 extraDomains = {
159 "dev.immae.eu" = null;
160 "caldance.immae.eu" = null;
161 };
162 };
163 services.nginx = {
164 enable = true;
165 recommendedOptimisation = true;
166 recommendedGzipSettings = true;
167 recommendedProxySettings = true;
168 upstreams = {
169 caldance.servers."nixops-99a7e1ba-54dc-11ea-a965-10bf487fe63b-caldance:3031" = {};
170 };
171 virtualHosts = {
172 "dev.immae.eu" = {
173 acmeRoot = config.myServices.certificates.webroot;
174 useACMEHost = name;
175 forceSSL = true;
176 root = "/home/immae/www";
177 };
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 };
192 };
193 };
194
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 };
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
223 system.stateVersion = "20.03"; # Did you read the comment?
224 }
225