diff options
| author | Kleidi Bujari <mail@4kb.net> | 2025-07-05 20:40:45 -0400 |
|---|---|---|
| committer | Kleidi Bujari <mail@4kb.net> | 2025-07-05 20:40:45 -0400 |
| commit | 08668f1e0e48a400cb577ff8228e0f3b2d20e56f (patch) | |
| tree | 31ed3f816d8289cb3fb17c371f0b66388ded2d5c /modules | |
| parent | 49b0f37534a9239946bdbd2b2d30cdffc826de09 (diff) | |
| download | depot-08668f1e0e48a400cb577ff8228e0f3b2d20e56f.tar.gz depot-08668f1e0e48a400cb577ff8228e0f3b2d20e56f.tar.bz2 depot-08668f1e0e48a400cb577ff8228e0f3b2d20e56f.zip | |
flatten dataset structure and persist more
Modified options used in disk creation so that consumers of this
module will actually pass disko virtual machine tests.
The flat dataset structure is changed from the xnet disk module,
mainly since I never really made use of the nesting properly. The only
place nesting matters is really in the persist dataset, and that one
is managed by hand anyway.
Although the changes pass tests and seem fine, they have not been
tested on actual hardware yet since the dataset layout changes are
destructive to any running machines, and cannot be simply reverted,
since they alter the disk.
/var, /root, and extras are now persisted since they do not expect to
be wiped on reboot. I never really had problems with this but would
rather minimize messing with SystemD's expectations regarding /var especially.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/disk.nix | 120 |
1 files changed, 80 insertions, 40 deletions
diff --git a/modules/disk.nix b/modules/disk.nix index 8635888..e7f85ab 100644 --- a/modules/disk.nix +++ b/modules/disk.nix @@ -1,8 +1,19 @@ -{ config, pkgs, lib, modulesPath, inputs, ... }: +{ + config, + pkgs, + lib, + modulesPath, + inputs, + ... +}: let cfg = config.depot.disk; - inherit (lib) mkOption mkDefault mkIf types; + inherit (lib) + mkIf + mkDefault + types + ; in { imports = [ @@ -11,21 +22,16 @@ in ]; options.depot.disk = { - enable = mkOption { - type = types.bool; - default = false; - description = "Apply depot-standard ZFS disk layout."; - }; - - device = mkOption { + enable = lib.mkEnableOption "Apply depot-standard ZFS disk layout."; + persistHome = lib.mkEnableOption "Persist home directories."; + device = lib.mkOption { type = types.str; - description = "Device used for zroot ZFS pool."; + description = "Name of device to install to."; }; }; config = mkIf cfg.enable { - networking.hostId = builtins.substring 0 8 - (builtins.hashString "md5" config.networking.hostName); + networking.hostId = builtins.substring 0 8 (builtins.hashString "md5" config.networking.hostName); services = { zfs.autoScrub.enable = true; @@ -51,8 +57,14 @@ in zramSwap.enable = mkDefault true; boot = { - kernelParams = [ "nohibernate" "elevator=none" ]; - supportedFilesystems = [ "vfat" "zfs" ]; + kernelParams = [ + "nohibernate" + "elevator=none" + ]; + supportedFilesystems = [ + "vfat" + "zfs" + ]; zfs.devNodes = mkDefault "/dev/disk/by-partuuid"; loader.efi.canTouchEfiVariables = true; loader.systemd-boot = { @@ -79,13 +91,17 @@ in disko.devices.nodev."/" = { fsType = "tmpfs"; - mountOptions = [ "defaults" "size=2G" "mode=755" ]; + mountOptions = [ + "defaults" + "size=2G" + "mode=755" + ]; }; disko.devices.disk.main = { - type = "disk"; + imageSize = "32G"; device = cfg.device; - imageSize = "15G"; + type = "disk"; content = { type = "gpt"; partitions.ESP = { @@ -95,6 +111,7 @@ in type = "filesystem"; format = "vfat"; mountpoint = "/boot"; + mountOptions = [ "umask=0077" ]; }; }; partitions.ZFS = { @@ -107,46 +124,69 @@ in disko.devices.zpool.zroot = { type = "zpool"; + options = { ashift = "12"; autotrim = "on"; }; rootFsOptions = { - "com.sun:auto-snapshot" = "false"; acltype = "posixacl"; atime = "off"; compression = "on"; + mountpoint = "none"; normalization = "formD"; relatime = "off"; xattr = "sa"; }; - datasets.nix = { - type = "zfs_fs"; - mountpoint = "/nix"; - options.mountpoint = "legacy"; - }; + datasets = + let + inherit (lib) + genAttrs + ; - # datasets.reserved = { - # type = "zfs_fs"; - # options = { - # refreservation = "10G"; - # mountpoint = "none"; - # }; - # }; + mounts = [ + # Any machine importing this configuration will require a + # nix store, so it needs to survive reboots. + "nix" - datasets.home = { - type = "zfs_fs"; - mountpoint = "/home"; - options.mountpoint = "legacy"; - }; + # Although it goes against the idea of putting root on a + # tmpfs, SystemD stores useful state for timers, services, + # logs, etc. in var. + "var" + + # Most machines using this module do not define additional + # users, so /root should persist as the only "home" on the + # system. + "root" + + # General storage that should outlive a reboot. Paths + # mentioned in Nix configs should generally use this + # directory rather than /var or other directories that + # happen to also be saved. + "persist" + ] ++ lib.optional cfg.persistHome "home"; - # datasets.persist = { - # type = "zfs_fs"; - # mountpoint = "/persist"; - # options.mountpoint = "legacy"; - # }; + makeDataset = name: { + type = "zfs_fs"; + mountpoint = "/${name}"; + options.mountpoint = "legacy"; + }; + in + genAttrs mounts makeDataset + // { + # ZFS should not use all available space on a device. This + # reserves some space at pool creation time that is never mounted + # to ensure it never happens. + reserved = { + type = "zfs_fs"; + options = { + refreservation = "10G"; + mountpoint = "none"; + }; + }; + }; }; }; } |
