From 51ab89cd98f03c223c1fe7e0f17d063862829c26 Mon Sep 17 00:00:00 2001 From: Jan-Bulthuis Date: Thu, 29 May 2025 14:19:19 +0200 Subject: [PATCH] Better disko setup --- flake.lock | 37 +++++++++++++++++++++++++++++++++++++ modules/nixos/disko.nix | 24 ++++++++++++++++++++++++ profiles/disko/vm.nix | 10 +++++++++- profiles/nixos/vm.nix | 22 +++++++--------------- 4 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 modules/nixos/disko.nix diff --git a/flake.lock b/flake.lock index cd645d1..cab0620 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,25 @@ { "nodes": { + "disko": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1748225455, + "narHash": "sha256-AzlJCKaM4wbEyEpV3I/PUq5mHnib2ryEy32c+qfj6xk=", + "owner": "nix-community", + "repo": "disko", + "rev": "a894f2811e1ee8d10c50560551e50d6ab3c392ba", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -54,6 +74,21 @@ "type": "github" } }, + "impermanence": { + "locked": { + "lastModified": 1737831083, + "narHash": "sha256-LJggUHbpyeDvNagTUrdhe/pRVp4pnS6wVKALS782gRI=", + "owner": "nix-community", + "repo": "impermanence", + "rev": "4b3e914cdf97a5b536a889e939fb2fd2b043a170", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "impermanence", + "type": "github" + } + }, "nix-minecraft": { "inputs": { "flake-compat": "flake-compat", @@ -114,7 +149,9 @@ }, "root": { "inputs": { + "disko": "disko", "home-manager": "home-manager", + "impermanence": "impermanence", "nix-minecraft": "nix-minecraft", "nix-modpack": "nix-modpack", "nixpkgs": "nixpkgs" diff --git a/modules/nixos/disko.nix b/modules/nixos/disko.nix new file mode 100644 index 0000000..dbdbc36 --- /dev/null +++ b/modules/nixos/disko.nix @@ -0,0 +1,24 @@ +{ + lib, + config, + inputs, + ... +}: + +with lib; +let + cfg = config.modules.disko; + profile = import "${inputs.self}/profiles/disko/${cfg.profile}.nix"; +in +{ + options.modules.disko = { + enable = mkEnableOption "Disko module"; + profile = mkOption { + type = types.str; + default = null; + description = "The profile to use for the disko module."; + }; + }; + + config = mkIf cfg.enable { disko.devices = profile.disko.devices; }; +} diff --git a/profiles/disko/vm.nix b/profiles/disko/vm.nix index 58bfe01..9c3446c 100644 --- a/profiles/disko/vm.nix +++ b/profiles/disko/vm.nix @@ -33,7 +33,7 @@ rootFsOptions = { compression = "zstd"; }; - mountpoint = "none"; + mountpoint = null; postCreateHook = "zfs list -t snapshot -H -o name | grep -E '^zroot@blank$' || zfs snapshot zroot@blank"; datasets = { @@ -41,6 +41,14 @@ type = "zfs_fs"; mountpoint = "/"; }; + nix = { + type = "zfs_fs"; + mountpoint = "/nix"; + }; + persist = { + type = "zfs_fs"; + mountpoint = "/persist"; + }; }; }; }; diff --git a/profiles/nixos/vm.nix b/profiles/nixos/vm.nix index 8a52ff6..6314d6d 100644 --- a/profiles/nixos/vm.nix +++ b/profiles/nixos/vm.nix @@ -19,6 +19,10 @@ in # Enabled modules modules = { profiles.base.enable = true; + disko = { + enable = true; + profile = "vm"; + }; ssh.enable = true; }; @@ -36,6 +40,9 @@ in # Machine platform nixpkgs.hostPlatform = "x86_64-linux"; + # Set hostid + networking.hostId = "deadbeef"; + # Hardware configuration hardware.enableRedistributableFirmware = true; boot.initrd.availableKernelModules = [ @@ -51,21 +58,6 @@ in boot.extraModulePackages = [ ]; hardware.cpu.intel.updateMicrocode = true; - # Filesystems - fileSystems."/" = { - device = "/dev/disk/by-partlabel/root"; - fsType = "ext4"; - }; - - fileSystems."/boot" = { - device = "/dev/disk/by-partlabel/EFI"; - fsType = "vfat"; - options = [ - "fmask=0077" - "dmask=0077" - ]; - }; - # Swapfile swapDevices = [ {