diff --git a/flake.lock b/flake.lock index 254c8e3..2ab10ac 100644 --- a/flake.lock +++ b/flake.lock @@ -35,6 +35,26 @@ "type": "github" } }, + "disko": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1751854533, + "narHash": "sha256-U/OQFplExOR1jazZY4KkaQkJqOl59xlh21HP9mI79Vc=", + "owner": "nix-community", + "repo": "disko", + "rev": "16b74a1e304197248a1bc663280f2548dbfcae3c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, "files": { "locked": { "lastModified": 1750263550, @@ -171,6 +191,7 @@ "inputs": { "dedupe_flake-compat": "dedupe_flake-compat", "dedupe_gitignore": "dedupe_gitignore", + "disko": "disko", "files": "files", "flake-parts": "flake-parts", "git-hooks": "git-hooks", diff --git a/flake.nix b/flake.nix index 7434240..e296268 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,11 @@ url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; + # disko provides declarative drive partitioning + disko = { + url = "github:nix-community/disko"; + inputs.nixpkgs.follows = "nixpkgs"; + }; # import-tree imports all nix files in a given directory. import-tree.url = "github:vic/import-tree"; # files lets us write text files and automatically add checks for them diff --git a/nix/manifest.nix b/nix/manifest.nix index f87deed..a06a45e 100644 --- a/nix/manifest.nix +++ b/nix/manifest.nix @@ -2,10 +2,6 @@ let testCfg = { hostName, ... }: { - fileSystems."/" = { - device = "/dev/sda1"; - fsType = "ext4"; - }; boot.loader.systemd-boot.enable = true; networking = { inherit hostName; }; }; diff --git a/nix/modules/machine/root.nix b/nix/modules/machine/root.nix new file mode 100644 index 0000000..45ecac6 --- /dev/null +++ b/nix/modules/machine/root.nix @@ -0,0 +1,75 @@ +{ config, inputs, ... }: +{ + flake.modules.nixos.default = + { hostName, ... }: + { + imports = [ inputs.disko.nixosModules.disko ]; + boot.initrd.kernelModules = [ "dm-snapshot" ]; + # BTRFS - may add more later on + disko.devices.disk.main = { + device = config.flake.manifest.hosts.nixos.${hostName}.machine.root.drive; + type = "disk"; + content.type = "gpt"; + content.partitions = { + boot = { + name = "boot"; + size = "1M"; + type = "EF02"; + }; + esp = { + name = "ESP"; + size = "500M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + swap = { + size = "4G"; + content = { + type = "swap"; + resumeDevice = true; + }; + }; + root = { + name = "root"; + size = "100%"; + content = { + type = "lvm_pv"; + vg = "root_vg"; + }; + }; + }; + }; + + disko.devices.lvm_vg.root_vg = { + type = "lvm_vg"; + lvs.root = { + size = "100%FREE"; + content = { + type = "btrfs"; + extraArgs = [ "-f" ]; + subvolumes = { + "/root".mountpoint = "/"; + "/persist" = { + mountpoint = "/persist"; + mountOptions = [ + "subvol=persist" + "noatime" + ]; + }; + "/nix" = { + mountpoint = "/nix"; + mountOptions = [ + "subvol=nix" + "noatime" + ]; + }; + }; + }; + }; + }; + }; +}