diff --git a/flake.nix b/flake.nix index 2c2c8dd..36bb3a1 100644 --- a/flake.nix +++ b/flake.nix @@ -49,6 +49,9 @@ nix-inspect = { url = "github:bluskript/nix-inspect"; }; + + # disko - Declarative disk partitioning and formatting using nix + disko.url = "github:nix-community/disko"; }; outputs = @@ -144,8 +147,10 @@ hostname = "legiondary"; system = "x86_64-linux"; hardwareModules = [ - ./nixos/profiles/hw-legion-15arh05h.nix inputs.nixos-hardware.nixosModules.lenovo-legion-15arh05h + ./nixos/profiles/hw-legion-15arh05h.nix + disko.nixosModules.disko + (import ./nixos/profiles/disko-nixos.nix { disks = [ "/dev/nvme0n1" ]; }) ]; profileModules = [ ./nixos/profiles/role-dev.nix diff --git a/nixos/profiles/disko-nixos.nix b/nixos/profiles/disko-nixos.nix new file mode 100644 index 0000000..b1b662d --- /dev/null +++ b/nixos/profiles/disko-nixos.nix @@ -0,0 +1,71 @@ +{ disks ? [ "/dev/sda" ], ... }: { + disko.devices = { + disk = { + main = { + type = "disk"; + device = builtins.elemAt disks 0; + content = { + type = "gpt"; + partitions = { + ESP = { + size = "1024M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + zfs = { + size = "100%"; + content = { + type = "zfs"; + pool = "zroot"; + }; + }; + }; + }; + }; + zpool = { + zroot = { + type = "zpool"; + mode = ""; + rootFsOptions = { + compression = "zstd"; + "com.sun:auto-snapshot" = "false"; + mountpoint = "none"; + acltype = "posixacl"; + }; + + options = { + ashift = 12; + }; + + postCreateHook = "zfs list -t snapshot -H -o name | grep -E '^zroot@blank$' || zfs snapshot zroot@blank"; + + datasets = { + root = { + type = "zfs_fs"; + mountpoint = "/"; + }; + + nix = { + type = "zfs_fs"; + options.mountpoint = "/nix"; + }; + + var = { + type = "zfs_fs"; + mountpoint = "/var"; + }; + + home = { + type = "zfs_fs"; + mountpoint = "/home"; + options."com.sun:auto-snapshot" = "true" + }; + }; + }; + }; + }; +}