From 34abd6afa44c620a56416bd423a2438a09bd1ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 4 Sep 2020 02:40:24 +0200 Subject: Migrate to morph as a replacement to nixops The deployment tasks are now independent of any state --- modules/private/system/backup-2.nix | 20 ++++---- modules/private/system/dilion.nix | 91 ++++++++++++++++++++------------- modules/private/system/eldiron.nix | 85 ++++++++++++++++++------------ modules/private/system/monitoring-1.nix | 19 +++---- 4 files changed, 124 insertions(+), 91 deletions(-) (limited to 'modules/private/system') diff --git a/modules/private/system/backup-2.nix b/modules/private/system/backup-2.nix index a49c374..d1064c7 100644 --- a/modules/private/system/backup-2.nix +++ b/modules/private/system/backup-2.nix @@ -1,26 +1,22 @@ { privateFiles }: { config, pkgs, resources, name, ... }: { + deployment = { + targetUser = "root"; + targetHost = config.hostEnv.ips.main.ip4; + substituteOnDestination = true; + }; boot.kernelPackages = pkgs.linuxPackages_latest; myEnv = import "${privateFiles}/environment.nix" // { inherit privateFiles; }; - imports = builtins.attrValues (import ../..); - - deployment = { - targetEnv = "hetznerCloud"; - hetznerCloud = { - authToken = config.myEnv.hetznerCloud.authToken; - datacenter = "hel1-dc2"; - location ="hel1"; - serverType = "cx11"; - }; - }; + imports = [ ] ++ builtins.attrValues (import ../..); fileSystems = { "/backup2" = { fsType = "ext4"; device = "UUID=b9425333-f567-435d-94d8-b26c22d93426"; }; + "/" = { device = "/dev/sda1"; fsType = "ext4"; }; }; networking = { @@ -34,6 +30,8 @@ defaultGateway6 = { address = "fe80::1"; interface = "ens3"; }; }; + boot.loader.grub.device = "nodev"; + myServices.certificates.enable = true; security.acme.certs."${name}" = { user = config.services.nginx.user; diff --git a/modules/private/system/dilion.nix b/modules/private/system/dilion.nix index 5c24656..5abaac0 100644 --- a/modules/private/system/dilion.nix +++ b/modules/private/system/dilion.nix @@ -1,59 +1,81 @@ { privateFiles }: { config, pkgs, name, lib, ... }: { - boot.supportedFilesystems = [ "zfs" ]; - boot.kernelPackages = pkgs.linuxPackages_latest; + deployment = { + targetUser = "root"; + targetHost = config.hostEnv.ips.main.ip4; + substituteOnDestination = true; + }; + nixpkgs.system = lib.mkOverride 900 "x86_64-linux"; + boot = { + loader = { + grub = { + version = 2; + devices = [ "/dev/sda" "/dev/sdb" "/dev/sdc" "/dev/sdd" ]; + }; + timeout = 1; + }; + blacklistedKernelModules = [ "nvidiafb" ]; + supportedFilesystems = [ "zfs" ]; + kernelPackages = pkgs.linuxPackages_latest; + kernelModules = [ "kvm-intel" ]; + initrd.availableKernelModules = [ "ahci" "sd_mod" ]; + initrd.secrets = { + "/boot/pass.key" = "/boot/pass.key"; + }; + kernel.sysctl."vm.nr_hugepages" = 256; # for xmr-stak + }; + nix.maxJobs = 8; + powerManagement.cpuFreqGovernor = "powersave"; + hardware.enableRedistributableFirmware = true; + myEnv = import "${privateFiles}/environment.nix" // { inherit privateFiles; }; + swapDevices = [ { label = "swap"; } ]; fileSystems = { - "/" = lib.mkForce { fsType = "zfs"; device = "zpool/root"; }; + "/" = { fsType = "zfs"; device = "zpool/root"; }; "/boot" = { fsType = "ext4"; device = "/dev/disk/by-uuid/fd1c511e-2bc0-49d5-b8bb-95e7e8c8c816"; }; "/etc" = { fsType = "zfs"; device = "zpool/root/etc"; }; "/home" = { fsType = "zfs"; device = "zpool/root/home"; }; "/home/immae" = { fsType = "zfs"; device = "zpool/root/home/immae"; }; "/tmp" = { fsType = "zfs"; device = "zpool/root/tmp"; }; "/var" = { fsType = "zfs"; device = "zpool/root/var"; }; + "/data" = { fsType = "ext4"; label = "data"; }; + "/nix" = { fsType = "ext4"; label = "nix"; }; }; - boot.initrd.secrets = { - "/boot/pass.key" = "/boot/pass.key"; - }; + + services.udev.extraRules = '' + ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="10:bf:48:7f:e6:3b", NAME="eth0" + ''; networking = { hostId = "27c3048d"; # generated with head -c4 /dev/urandom | od -A none -t x4 firewall.enable = false; - interfaces."eth0".ipv4.addresses = pkgs.lib.attrsets.mapAttrsToList - (n: ips: { address = ips.ip4; prefixLength = 32; }) - (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips); - interfaces."eth0".ipv6.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList - (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or [])) - config.hostEnv.ips); + interfaces."eth0".ipv4.addresses = + [ { address = config.hostEnv.ips.main.ip4; prefixLength = 27; } ] + ++ pkgs.lib.attrsets.mapAttrsToList + (n: ips: { address = ips.ip4; prefixLength = 32; }) + (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips); + interfaces."eth0".ipv6.addresses = + [ { address = "2a01:4f8:141:53e7::"; prefixLength = 64; } ] + ++ pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList + (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or [])) + config.hostEnv.ips); + defaultGateway = { address = "176.9.10.225"; interface = "eth0"; }; + defaultGateway6 = { address = "fe80::1"; interface = "eth0"; }; + nameservers = [ + "213.133.98.98" + "213.133.99.99" + "213.133.100.100" + "2a01:4f8:0:a0a1::add:1010" + "2a01:4f8:0:a102::add:9999" + "2a01:4f8:0:a111::add:9898" + ]; }; myServices.ssh.modules = [ config.myServices.ssh.predefinedModules.regular ]; imports = builtins.attrValues (import ../..); - deployment = { - targetEnv = "hetzner"; - hetzner = { - robotUser = config.myEnv.hetzner.user; - robotPass = config.myEnv.hetzner.pass; - mainIPv4 = config.hostEnv.ips.main.ip4; - partitions = '' - clearpart --all --initlabel --drives=sda,sdb,sdc,sdd - - part swap --recommended --label=swap --fstype=swap --ondisk=sda - - part raid.1 --grow --ondisk=sdc - part raid.2 --grow --ondisk=sdd - - raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2 - - part /nix --grow --label=nix --ondisk=sda - part /data --grow --label=data --ondisk=sdb - ''; - }; - }; - system.nssModules = [ pkgs.libvirt ]; system.nssDatabases.hosts = lib.mkForce [ "files" "libvirt_guest" "mymachines" "dns" "myhostname" ]; programs.zsh.enable = true; @@ -78,7 +100,6 @@ } ]; - boot.kernel.sysctl."vm.nr_hugepages" = 256; # for xmr-stak system.activationScripts.libvirtd_exports = '' install -m 0755 -o root -g root -d /var/lib/caldance ''; diff --git a/modules/private/system/eldiron.nix b/modules/private/system/eldiron.nix index 83e52b8..bb8bbfc 100644 --- a/modules/private/system/eldiron.nix +++ b/modules/private/system/eldiron.nix @@ -1,22 +1,45 @@ { privateFiles }: { config, pkgs, lib, ... }: { - boot.supportedFilesystems = [ "zfs" ]; - boot.kernelParams = ["zfs.zfs_arc_max=6442450944"]; - boot.kernelPackages = pkgs.linuxPackages_latest; + deployment = { + targetUser = "root"; + targetHost = config.hostEnv.ips.main.ip4; + substituteOnDestination = true; + }; + boot = { + kernelModules = [ "kvm-intel" ]; + blacklistedKernelModules = [ "nvidiafb" ]; + loader.timeout = 1; + loader.grub.devices = [ "/dev/sda" "/dev/sdb" ]; + kernel.sysctl = { + # https://github.com/Netflix/security-bulletins/blob/master/advisories/third-party/2019-001.md + "net.ipv4.tcp_sack" = 0; + }; + supportedFilesystems = [ "zfs" ]; + kernelParams = ["zfs.zfs_arc_max=6442450944"]; + kernelPackages = pkgs.linuxPackages_latest; + initrd.availableKernelModules = [ "ahci" "sd_mod" ]; + initrd.secrets = { + "/boot/pass.key" = "/boot/pass.key"; + }; + }; + services.udev.extraRules = '' + ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="c8:60:00:56:a0:88", NAME="eth0" + ''; + nix.maxJobs = 8; + powerManagement.cpuFreqGovernor = "powersave"; myEnv = import "${privateFiles}/environment.nix" // { inherit privateFiles; }; fileSystems = { - "/" = lib.mkForce { fsType = "zfs"; device = "zpool/root"; }; + "/" = { fsType = "zfs"; device = "zpool/root"; }; "/boot" = { fsType = "ext4"; device = "/dev/disk/by-uuid/e6bb18fb-ff56-4b5f-ae9f-e60d40dc0622"; }; "/etc" = { fsType = "zfs"; device = "zpool/root/etc"; }; "/nix" = { fsType = "zfs"; device = "zpool/root/nix"; }; "/tmp" = { fsType = "zfs"; device = "zpool/root/tmp"; }; "/var" = { fsType = "zfs"; device = "zpool/root/var"; }; }; - boot.initrd.secrets = { - "/boot/pass.key" = "/boot/pass.key"; - }; + swapDevices = [ { label = "swap1"; } { label = "swap2"; } ]; + hardware.enableRedistributableFirmware = true; services.zfs = { autoScrub = { @@ -27,20 +50,34 @@ hostId = "8262ca33"; # generated with head -c4 /dev/urandom | od -A none -t x4 firewall.enable = true; # 176.9.151.89 declared in nixops -> infra / tools - interfaces."eth0".ipv4.addresses = pkgs.lib.attrsets.mapAttrsToList - (n: ips: { address = ips.ip4; prefixLength = 32; }) - (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips); + interfaces."eth0".ipv4.addresses = + pkgs.lib.attrsets.mapAttrsToList + (n: ips: { address = ips.ip4; prefixLength = 32; }) + (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips) + ++ [ { address = config.hostEnv.ips.main.ip4; prefixLength = 27; } ]; interfaces."eth0".ipv6.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or [])) config.hostEnv.ips); + defaultGateway = "176.9.151.65"; + localCommands = '' + # FIXME: Those commands were added by nixops and may not be + # actually needed + ip -6 addr add '2a01:4f8:160:3445::/64' dev 'eth0' || true + ip -4 route change '176.9.151.64/27' via '176.9.151.65' dev 'eth0' || true + ip -6 route add default via 'fe80::1' dev eth0 || true + ''; + nameservers = [ + "213.133.98.98" + "213.133.99.99" + "213.133.100.100" + "2a01:4f8:0:a0a1::add:1010" + "2a01:4f8:0:a102::add:9999" + "2a01:4f8:0:a111::add:9898" + ]; }; imports = builtins.attrValues (import ../..); - boot.kernel.sysctl = { - # https://github.com/Netflix/security-bulletins/blob/master/advisories/third-party/2019-001.md - "net.ipv4.tcp_sack" = 0; - }; myServices.buildbot.enable = true; myServices.databases.enable = true; myServices.gitolite.enable = true; @@ -76,26 +113,6 @@ "${profile.host_key_type} ${profile.host_key}"; }; - deployment = { - targetEnv = "hetzner"; - hetzner = { - robotUser = config.myEnv.hetzner.user; - robotPass = config.myEnv.hetzner.pass; - mainIPv4 = config.hostEnv.ips.main.ip4; - partitions = '' - clearpart --all --initlabel --drives=sda,sdb - - part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda - part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb - - part raid.1 --grow --ondisk=sda - part raid.2 --grow --ondisk=sdb - - raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2 - ''; - }; - }; - services.cron = { enable = true; mailto = "cron@immae.eu"; diff --git a/modules/private/system/monitoring-1.nix b/modules/private/system/monitoring-1.nix index c87c784..2241b2b 100644 --- a/modules/private/system/monitoring-1.nix +++ b/modules/private/system/monitoring-1.nix @@ -1,20 +1,15 @@ { privateFiles }: { config, pkgs, resources, ... }: { + deployment = { + targetUser = "root"; + targetHost = config.hostEnv.ips.main.ip4; + substituteOnDestination = true; + }; boot.kernelPackages = pkgs.linuxPackages_latest; myEnv = import "${privateFiles}/environment.nix" // { inherit privateFiles; }; - imports = builtins.attrValues (import ../..); - - deployment = { - targetEnv = "hetznerCloud"; - hetznerCloud = { - authToken = config.myEnv.hetznerCloud.authToken; - datacenter = "hel1-dc2"; - location ="hel1"; - serverType = "cx11"; - }; - }; + imports = [ ] ++ builtins.attrValues (import ../..); myServices.monitoring.enable = true; myServices.monitoring.master = true; @@ -29,6 +24,8 @@ config.hostEnv.ips); defaultGateway6 = { address = "fe80::1"; interface = "ens3"; }; }; + boot.loader.grub.device = "nodev"; + fileSystems."/" = { device = "/dev/sda1"; fsType = "ext4"; }; myServices.mailRelay.enable = true; security.pki.certificateFiles = [ -- cgit v1.2.3