From 02b736cc0c2b048ee3a9f6959e76952e80d76fe5 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 13:53:42 +0000 Subject: [PATCH 01/12] add cloudnix config --- flake.nix | 11 +++++ hosts/cloudnix/default.nix | 57 +++++++++++++++++++++++ hosts/cloudnix/hardware-configuration.nix | 41 ++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 hosts/cloudnix/default.nix create mode 100644 hosts/cloudnix/hardware-configuration.nix diff --git a/flake.nix b/flake.nix index 7d0b500..0e697b8 100644 --- a/flake.nix +++ b/flake.nix @@ -130,6 +130,17 @@ modules = [ ./hosts/citadel + home-manager.nixosModules.home-manager + { + home-manager.extraSpecialArgs = specialArgs; + } + ]; + }; + cloudnix = nixpkgs.lib.nixosSystem { + inherit specialArgs; + modules = [ + ./hosts/cloudnix + home-manager.nixosModules.home-manager { home-manager.extraSpecialArgs = specialArgs; diff --git a/hosts/cloudnix/default.nix b/hosts/cloudnix/default.nix new file mode 100644 index 0000000..0100eae --- /dev/null +++ b/hosts/cloudnix/default.nix @@ -0,0 +1,57 @@ +{ + configVars, + outputs, + ... +}: let + user = "admin"; + merlinIp = configVars.networking.addresses.merlin.ip; +in { + imports = [ + # Create users for this host + ../common/users/${user} + + # Import core options + ./hardware-configuration.nix + ../common/core + + # Import optional options + ../common/optional/persistence.nix + ../common/optional/openssh.nix + + ../common/optional/distributed-builds/local-machine.nix + + outputs.nixosModules.nixosAutoUpgrade + ]; + + boot = { + loader = { + grub.enable = true; + }; + }; + + services = { + earlyoom = { + enable = true; + freeMemThreshold = 5; # <%5 free + }; + }; + + system.services.nixosAutoUpgrade = { + enable = true; + persistent = true; + remote = "remotebuild@${merlinIp}"; + reboot = false; + pushUpdates = false; + configDir = "/etc/nixos"; + onCalendar = "*-*-* 06:00:00"; + user = "sam"; + }; + + networking = { + hostName = "cloudnix"; + nameservers = ["8.8.8.8"]; + firewall.enable = true; + }; + + services.libinput.enable = true; +} diff --git a/hosts/cloudnix/hardware-configuration.nix b/hosts/cloudnix/hardware-configuration.nix new file mode 100644 index 0000000..ab544bc --- /dev/null +++ b/hosts/cloudnix/hardware-configuration.nix @@ -0,0 +1,41 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/profiles/qemu-guest.nix") + ]; + + boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "virtio_pci" "virtio_scsi" "sd_mod" "sr_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/e12d0dfd-9753-44d4-b65f-dc5549db3edf"; + fsType = "ext4"; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/c29f698d-eb89-4618-be8b-046b4907aed8"; + fsType = "ext4"; + }; + + swapDevices = [ + { + device = "/.swapfile"; + size = 2 * 1024; + } + ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.enp1s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} From 312ecfbecabe28743af6f2c313b033b81ad00176 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 14:05:42 +0000 Subject: [PATCH 02/12] add cloudnix config --- home/cloudnix.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 home/cloudnix.nix diff --git a/home/cloudnix.nix b/home/cloudnix.nix new file mode 100644 index 0000000..7aab28f --- /dev/null +++ b/home/cloudnix.nix @@ -0,0 +1,11 @@ +{ + ... +}: { + imports = [ + ./users/admin + ./common/core + ./common/optional/git.nix + ./common/optional/sops.nix + ]; + +} From a5846c8cfc55f3924fb63b17580c70478f10d8ae Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 14:07:10 +0000 Subject: [PATCH 03/12] add boot loader device --- hosts/cloudnix/default.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hosts/cloudnix/default.nix b/hosts/cloudnix/default.nix index 0100eae..282f435 100644 --- a/hosts/cloudnix/default.nix +++ b/hosts/cloudnix/default.nix @@ -25,7 +25,10 @@ in { boot = { loader = { - grub.enable = true; + grub = { + enable = true; + devices = ["/dev/sda1"]; + }; }; }; From 3e38fadb9f95346a39e5d3e9c224e61017bc7121 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 14:20:17 +0000 Subject: [PATCH 04/12] remove persistence from cloudnix --- hosts/cloudnix/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/hosts/cloudnix/default.nix b/hosts/cloudnix/default.nix index 282f435..13af959 100644 --- a/hosts/cloudnix/default.nix +++ b/hosts/cloudnix/default.nix @@ -15,7 +15,6 @@ in { ../common/core # Import optional options - ../common/optional/persistence.nix ../common/optional/openssh.nix ../common/optional/distributed-builds/local-machine.nix From dd66a73f24acbc84b61407e33030a19fa868e63e Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 14:21:41 +0000 Subject: [PATCH 05/12] update flake secrets --- flake.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index c2b0dd8..267706f 100644 --- a/flake.lock +++ b/flake.lock @@ -539,11 +539,11 @@ }, "nix-secrets": { "locked": { - "lastModified": 1737745804, - "narHash": "sha256-ix/gu0HJmJISlZM2PjCssg+4fhD1g0CrrpLaKb84dRo=", + "lastModified": 1737813653, + "narHash": "sha256-2ZZAuL6fZiwh2Nh1vx4EgFuNueJ3LCBKomsgByOV1k4=", "ref": "refs/heads/master", - "rev": "3a049490d4853b61e9cf778347ff8fa175488ede", - "revCount": 251, + "rev": "8d063046441c3c408197a7226e43b4e7ccdf68f1", + "revCount": 254, "type": "git", "url": "ssh://git@git.bitlab21.com/sam/nix-secrets.git" }, From 620db0fb22bbaf07b9110638e42fd364bbe5db48 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 17:55:52 +0000 Subject: [PATCH 06/12] add legacy disk config and add persistence back to cloudnix --- hosts/cloudnix/default.nix | 1 + hosts/common/disks/btrfs/legacy.nix | 59 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 hosts/common/disks/btrfs/legacy.nix diff --git a/hosts/cloudnix/default.nix b/hosts/cloudnix/default.nix index 13af959..282f435 100644 --- a/hosts/cloudnix/default.nix +++ b/hosts/cloudnix/default.nix @@ -15,6 +15,7 @@ in { ../common/core # Import optional options + ../common/optional/persistence.nix ../common/optional/openssh.nix ../common/optional/distributed-builds/local-machine.nix diff --git a/hosts/common/disks/btrfs/legacy.nix b/hosts/common/disks/btrfs/legacy.nix new file mode 100644 index 0000000..6de397a --- /dev/null +++ b/hosts/common/disks/btrfs/legacy.nix @@ -0,0 +1,59 @@ +{ + disko.devices = { + disk = { + main = { + device = "/dev/sda"; + type = "disk"; + content = { + type = "table"; + format = "gpt"; + partitions = [ + { + name = "ESP"; + start = "1M"; + end = "512M"; + bootable = true; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = ["umask=0077"]; + }; + } + { + name = "root"; + start = "513M"; + end = "100%"; + part-type = "primary"; + bootable = true; + content = { + type = "btrfs"; + extraArgs = ["-f"]; + subvolumes = { + "/root" = { + mountpoint = "/"; + }; + + "/persist" = { + mountOptions = ["subvol=persist"]; + mountpoint = "/persist"; + }; + + "/nix" = { + mountOptions = ["subvol=nix" "noatime"]; + mountpoint = "/nix"; + }; + + "/swap" = { + mountOptions = ["noatime"]; + mountpoint = "/.swapvol"; + }; + }; + }; + } + ]; + }; + }; + }; + }; +} From 45d3c6cc26ebc6e7d644742bfe98f779f8769997 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 17:58:11 +0000 Subject: [PATCH 07/12] add impermenence to cloudnix --- hosts/cloudnix/default.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hosts/cloudnix/default.nix b/hosts/cloudnix/default.nix index 282f435..b396bdd 100644 --- a/hosts/cloudnix/default.nix +++ b/hosts/cloudnix/default.nix @@ -1,10 +1,13 @@ { configVars, outputs, + lib, + ... }: let user = "admin"; merlinIp = configVars.networking.addresses.merlin.ip; + btrfsMountDevice = "/dev/sda2"; in { imports = [ # Create users for this host @@ -14,6 +17,13 @@ in { ./hardware-configuration.nix ../common/core + # Impermanence + ../common/optional/persistence.nix + (import ../common/disks/btrfs/impermanence.nix { + btrfsMountDevice = btrfsMountDevice; + lib = lib; + }) + # Import optional options ../common/optional/persistence.nix ../common/optional/openssh.nix From 8ec54b44b948e06e7219ff0c5523940dc797fcd2 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 18:02:27 +0000 Subject: [PATCH 08/12] add hardware config for cloudnix --- hosts/cloudnix/hardware-configuration.nix | 35 ++++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/hosts/cloudnix/hardware-configuration.nix b/hosts/cloudnix/hardware-configuration.nix index ab544bc..cd814a8 100644 --- a/hosts/cloudnix/hardware-configuration.nix +++ b/hosts/cloudnix/hardware-configuration.nix @@ -14,21 +14,36 @@ boot.extraModulePackages = [ ]; fileSystems."/" = - { device = "/dev/disk/by-uuid/e12d0dfd-9753-44d4-b65f-dc5549db3edf"; - fsType = "ext4"; + { device = "/dev/disk/by-uuid/540bb762-8085-47f0-8c99-90a22382362e"; + fsType = "btrfs"; + options = [ "subvol=root" ]; + }; + + fileSystems."/.swapvol" = + { device = "/dev/disk/by-uuid/540bb762-8085-47f0-8c99-90a22382362e"; + fsType = "btrfs"; + options = [ "subvol=swap" ]; }; fileSystems."/boot" = - { device = "/dev/disk/by-uuid/c29f698d-eb89-4618-be8b-046b4907aed8"; - fsType = "ext4"; + { device = "/dev/disk/by-uuid/FB93-E33C"; + fsType = "vfat"; + options = [ "fmask=0077" "dmask=0077" ]; }; - swapDevices = [ - { - device = "/.swapfile"; - size = 2 * 1024; - } - ]; + fileSystems."/nix" = + { device = "/dev/disk/by-uuid/540bb762-8085-47f0-8c99-90a22382362e"; + fsType = "btrfs"; + options = [ "subvol=nix" ]; + }; + + fileSystems."/persist" = + { device = "/dev/disk/by-uuid/540bb762-8085-47f0-8c99-90a22382362e"; + fsType = "btrfs"; + options = [ "subvol=persist" ]; + }; + + swapDevices = [ ]; # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's From ac3c056e03c761037df9fa097adade7715f095cf Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 18:57:48 +0000 Subject: [PATCH 09/12] various cloudnix modifications --- flake.lock | 8 +++---- hosts/cloudnix/default.nix | 17 +++++++++++++-- hosts/common/disks/btrfs/legacy.nix | 34 ++++++++++++++--------------- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/flake.lock b/flake.lock index 267706f..8bf7750 100644 --- a/flake.lock +++ b/flake.lock @@ -539,11 +539,11 @@ }, "nix-secrets": { "locked": { - "lastModified": 1737813653, - "narHash": "sha256-2ZZAuL6fZiwh2Nh1vx4EgFuNueJ3LCBKomsgByOV1k4=", + "lastModified": 1737831370, + "narHash": "sha256-SknkmBjTklrzrXaVALsIIOtu1r8TP35NEfhST6zJyH4=", "ref": "refs/heads/master", - "rev": "8d063046441c3c408197a7226e43b4e7ccdf68f1", - "revCount": 254, + "rev": "148154f0b8bdaf085ea16562822f55c810b55bac", + "revCount": 255, "type": "git", "url": "ssh://git@git.bitlab21.com/sam/nix-secrets.git" }, diff --git a/hosts/cloudnix/default.nix b/hosts/cloudnix/default.nix index b396bdd..1fe6c4e 100644 --- a/hosts/cloudnix/default.nix +++ b/hosts/cloudnix/default.nix @@ -7,6 +7,7 @@ }: let user = "admin"; merlinIp = configVars.networking.addresses.merlin.ip; + cloudnixIp = configVars.networking.addresses.cloudnix.ip; btrfsMountDevice = "/dev/sda2"; in { imports = [ @@ -35,9 +36,10 @@ in { boot = { loader = { + efi.canTouchEfiVariables = false; grub = { enable = true; - devices = ["/dev/sda1"]; + devices = ["/dev/sda"]; }; }; }; @@ -57,7 +59,7 @@ in { pushUpdates = false; configDir = "/etc/nixos"; onCalendar = "*-*-* 06:00:00"; - user = "sam"; + user = "admin"; }; networking = { @@ -66,5 +68,16 @@ in { firewall.enable = true; }; + systemd.network.networks."10-wan" = { + networkConfig.DHCP = "no"; + address = [ + "${cloudnixIp}/32" + ]; + routes = [ + { routeConfig = { Destination = "172.31.1.1"; }; } + { routeConfig = { Gateway = "172.31.1.1"; GatewayOnLink = true; }; } + ]; + }; + services.libinput.enable = true; } diff --git a/hosts/common/disks/btrfs/legacy.nix b/hosts/common/disks/btrfs/legacy.nix index 6de397a..5155479 100644 --- a/hosts/common/disks/btrfs/legacy.nix +++ b/hosts/common/disks/btrfs/legacy.nix @@ -2,30 +2,28 @@ disko.devices = { disk = { main = { - device = "/dev/sda"; type = "disk"; + device = "/dev/sda"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "ESP"; - start = "1M"; - end = "512M"; - bootable = true; + type = "gpt"; + partitions = { + BOOT = { + size = "1M"; + type = "EF02"; + priority = 1; + }; + ESP = { + size = "512M"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; mountOptions = ["umask=0077"]; }; - } - { - name = "root"; - start = "513M"; - end = "100%"; - part-type = "primary"; - bootable = true; + }; + root = { + size = "100%"; content = { type = "btrfs"; extraArgs = ["-f"]; @@ -50,8 +48,8 @@ }; }; }; - } - ]; + }; + }; }; }; }; From a3455a0b31f9ca0479fce424a93924cd44fb7083 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 19:02:42 +0000 Subject: [PATCH 10/12] add cloudnix hardware --- hosts/cloudnix/hardware-configuration.nix | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hosts/cloudnix/hardware-configuration.nix b/hosts/cloudnix/hardware-configuration.nix index cd814a8..db241d3 100644 --- a/hosts/cloudnix/hardware-configuration.nix +++ b/hosts/cloudnix/hardware-configuration.nix @@ -14,36 +14,41 @@ boot.extraModulePackages = [ ]; fileSystems."/" = - { device = "/dev/disk/by-uuid/540bb762-8085-47f0-8c99-90a22382362e"; + { device = "/dev/disk/by-uuid/2aec8052-68fc-4bac-9b8d-c10b9b659ad8"; fsType = "btrfs"; options = [ "subvol=root" ]; }; fileSystems."/.swapvol" = - { device = "/dev/disk/by-uuid/540bb762-8085-47f0-8c99-90a22382362e"; + { device = "/dev/disk/by-uuid/2aec8052-68fc-4bac-9b8d-c10b9b659ad8"; fsType = "btrfs"; options = [ "subvol=swap" ]; }; fileSystems."/boot" = - { device = "/dev/disk/by-uuid/FB93-E33C"; + { device = "/dev/disk/by-uuid/1DE3-CACA"; fsType = "vfat"; options = [ "fmask=0077" "dmask=0077" ]; }; fileSystems."/nix" = - { device = "/dev/disk/by-uuid/540bb762-8085-47f0-8c99-90a22382362e"; + { device = "/dev/disk/by-uuid/2aec8052-68fc-4bac-9b8d-c10b9b659ad8"; fsType = "btrfs"; options = [ "subvol=nix" ]; }; fileSystems."/persist" = - { device = "/dev/disk/by-uuid/540bb762-8085-47f0-8c99-90a22382362e"; + { device = "/dev/disk/by-uuid/2aec8052-68fc-4bac-9b8d-c10b9b659ad8"; fsType = "btrfs"; options = [ "subvol=persist" ]; }; - swapDevices = [ ]; + swapDevices = [ + { + device = "/.swapvol/swapfile"; + size = 2 * 1024; + } + ]; # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's From c3004ad56f3b252c85edfdfe49906604206f1f16 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 20:22:42 +0000 Subject: [PATCH 11/12] change cloudnix dev ids --- hosts/cloudnix/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hosts/cloudnix/default.nix b/hosts/cloudnix/default.nix index 1fe6c4e..a88b912 100644 --- a/hosts/cloudnix/default.nix +++ b/hosts/cloudnix/default.nix @@ -8,7 +8,7 @@ user = "admin"; merlinIp = configVars.networking.addresses.merlin.ip; cloudnixIp = configVars.networking.addresses.cloudnix.ip; - btrfsMountDevice = "/dev/sda2"; + btrfsMountDevice = "/dev/by-uuid/2aec8052-68fc-4bac-9b8d-c10b9b659ad8"; in { imports = [ # Create users for this host @@ -39,7 +39,7 @@ in { efi.canTouchEfiVariables = false; grub = { enable = true; - devices = ["/dev/sda"]; + devices = ["/dev/by-id/scsi-0QEMU_QEMU_HARDDISK_57492184"]; }; }; }; From 2fede917609477e181803b8c6028f1755f0e4c77 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Jan 2025 20:25:40 +0000 Subject: [PATCH 12/12] fix disk wrong path --- hosts/cloudnix/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hosts/cloudnix/default.nix b/hosts/cloudnix/default.nix index a88b912..bddaabd 100644 --- a/hosts/cloudnix/default.nix +++ b/hosts/cloudnix/default.nix @@ -8,7 +8,7 @@ user = "admin"; merlinIp = configVars.networking.addresses.merlin.ip; cloudnixIp = configVars.networking.addresses.cloudnix.ip; - btrfsMountDevice = "/dev/by-uuid/2aec8052-68fc-4bac-9b8d-c10b9b659ad8"; + btrfsMountDevice = "/dev/disk/by-uuid/2aec8052-68fc-4bac-9b8d-c10b9b659ad8"; in { imports = [ # Create users for this host @@ -39,7 +39,7 @@ in { efi.canTouchEfiVariables = false; grub = { enable = true; - devices = ["/dev/by-id/scsi-0QEMU_QEMU_HARDDISK_57492184"]; + devices = ["/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_57492184"]; }; }; };