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