diff --git a/disko/luks-zfs-impermanence.nix b/disko/luks-zfs-impermanence.nix new file mode 100644 index 0000000..5793f61 --- /dev/null +++ b/disko/luks-zfs-impermanence.nix @@ -0,0 +1,80 @@ +{ + disko.devices = { + disk = { + main = { + device = "/dev/sda"; + type = "disk"; + content = { + type = "gpt"; + partitions = { + ESP = { + name = "boot"; + type = "EF00"; + size = "512M"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ "umask=0077" ]; + }; + }; + swap = { + size = "4G"; + content = { + type = "swap"; + discardPolicy = "both"; + randomEncryption = true; + }; + }; + luks = { + size = "100%"; + content = { + type = "luks"; + name = "crypted"; + settings = { + bypassWorkqueues = true; + allowDiscards = true; + }; + extraFormatArgs = [ "-i 5000" ]; + content = { + type = "zfs"; + pool = "zroot"; + }; + }; + }; + }; + }; + }; + }; + zpool = { + zroot = { + type = "zpool"; + rootFsOptions = { + canmount = "off"; + compression = "zstd"; + }; + datasets = { + nix = { + type = "zfs_fs"; + mountpoint = "/nix"; + options.mountpoint = "legacy"; + }; + persist = { + type = "zfs_fs"; + options = { + mountpoint = "legacy"; + "com.sun:auto-snapshot" = "true"; + }; + mountpoint = "/persist"; + }; + root = { + type = "zfs_fs"; + mountpoint = "/"; + options.mountpoint = "legacy"; + postCreateHook = "zfs snapshot zroot/root@blank"; + }; + }; + }; + }; + }; +} diff --git a/hosts/x86_64-linux/lithium.nix b/hosts/x86_64-linux/lithium.nix index 2d9c293..5369286 100644 --- a/hosts/x86_64-linux/lithium.nix +++ b/hosts/x86_64-linux/lithium.nix @@ -1,5 +1,7 @@ { ... }: { + imports = [ ../../disko/luks-zfs-impermanence.nix ]; + custom = { roles = { desktop.enable = true; @@ -19,31 +21,13 @@ }; }; hardware.intelLaptop.enable = true; - platform.hibernate.enable = true; services = { - syncthing.enable = true; nixCacheClient = { enable = true; remoteBuilds.additional = true; }; }; }; - system.stateVersion = "24.05"; - - boot.kernelParams = [ "resume_offset=39292928" ]; - fileSystems."/" = { - device = "/dev/disk/by-uuid/b43fe465-80e9-48d4-a4be-1113c917330e"; - fsType = "ext4"; - }; - - boot.initrd.luks.devices."nixos".device = "/dev/disk/by-uuid/4dc2fd8c-71da-4b95-91d5-7a118387172b"; - - fileSystems."/boot" = { - device = "/dev/disk/by-uuid/D8BB-B91A"; - fsType = "vfat"; - options = [ - "fmask=0077" - "dmask=0077" - ]; - }; + networking.hostId = "ca94a90c"; + system.stateVersion = "25.05"; } diff --git a/modules/platform/impermanence.nix b/modules/platform/impermanence.nix index 6da3661..989587f 100644 --- a/modules/platform/impermanence.nix +++ b/modules/platform/impermanence.nix @@ -3,10 +3,7 @@ let cfg = config.custom.platform.impermanence; in { - options.custom.platform.impermanence.enable = lib.mkOption { - type = lib.types.bool; - default = false; - }; + options.custom.platform.impermanence.enable = lib.mkEnableOption "custom impermanence setup"; config = lib.mkIf cfg.enable { # Default set of directories we always want to persist diff --git a/modules/roles/personal-machine.nix b/modules/roles/personal-machine.nix index 5ddbe7b..a6d8967 100644 --- a/modules/roles/personal-machine.nix +++ b/modules/roles/personal-machine.nix @@ -7,28 +7,38 @@ let cfg = config.custom.roles.personalMachine; in { - options.custom.roles.personalMachine.enable = lib.mkOption { - type = lib.types.bool; - default = false; - }; + options.custom.roles.personalMachine.enable = + lib.mkEnableOption "role for personal machines (desktop/laptop)"; - config = lib.mkIf cfg.enable { - custom = { - hardware = { - keychron.enable = true; - onlykey.enable = true; - trackball.enable = true; + config = + (lib.mkIf cfg.enable { + custom = { + hardware = { + keychron.enable = true; + onlykey.enable = true; + trackball.enable = true; + }; + programs = { + bitwarden.enable = true; + communication.enable = true; + firefox.enable = true; + i3.enable = true; + moonlight.enable = true; + redshift.enable = true; + usbAutoMount.enable = true; + }; }; - programs = { - bitwarden.enable = true; - communication.enable = true; - firefox.enable = true; - i3.enable = true; - moonlight.enable = true; - redshift.enable = true; - usbAutoMount.enable = true; - }; - }; - system.autoUpgrade.allowReboot = lib.mkForce false; - }; + system.autoUpgrade.allowReboot = lib.mkForce false; + }) + // (lib.mkIf config.custom.platform.impermanence.enable { + # TODO Remove this temporary impermanence setup in favor of a more detailed one + environment.persistence."/persist".directories = [ + { + directory = config.users.users.vili.home; + user = config.users.users.vili.name; + group = config.users.users.vili.group; + mode = "u=rwx,g=,o="; + } + ]; + }); }