diff --git a/home/default.nix b/home/default.nix index fd6d208..1c611fd 100644 --- a/home/default.nix +++ b/home/default.nix @@ -31,6 +31,7 @@ in imports = [ ./packages ./programs + ./impermanence ]; config = { diff --git a/home/impermanence/default.nix b/home/impermanence/default.nix new file mode 100644 index 0000000..62ba5d5 --- /dev/null +++ b/home/impermanence/default.nix @@ -0,0 +1,28 @@ +{ + lib, + osConfig, + inputs, + ... +}: let + inherit (lib) mkIf; + cfg = osConfig.myOptions.system.impermanence.home; +in { + imports = [ inputs.impermanence.nixosModules.home-manager.impermanence ]; + + config = mkIf cfg.enable { + home.persistence."${cfg.persistentMountPoint}" = { + directories = [ + ".cache/nix" + ] ++ cfg.extraDirectories; + + files = [ + + ] ++ cfg.extraFiles; + + # Allow other users (such as root), to access files through the bind + # mounted directories listed in `directories`. Useful for `sudo` operations, + # Docker, etc. Requires NixOS configuration programs.fuse.userAllowOther = true; + allowOther = true; + }; + }; +} diff --git a/hosts/voyager/default.nix b/hosts/voyager/default.nix index 3abc33c..6d51508 100644 --- a/hosts/voyager/default.nix +++ b/hosts/voyager/default.nix @@ -50,10 +50,32 @@ ]; }; + home = { + enable = true; + persistentMountPoint = "/persist/home"; + extraDirectories = [ + "Downloads" + "Personal" + "Media" + "dots" + + ".local/share/gnupg" + ".local/share/wakatime" + ".local/share/nvim" + ".local/state/nvim" + ".local/share/zsh" + ".local/cargo" + ".local/go" + ]; + extraFiles = [ + ".config/git/git-credentials" + ]; + }; + # Configure automatic root subvolume wiping on boot from initrd autoWipeBtrfs = { enable = true; - devices."/dev/disk/by-label/NIXOS-FS".subvolumes = [ "root" ]; + devices."/dev/disk/by-label/NIXOS-FS".subvolumes = [ "root" "home" ]; }; }; }; diff --git a/options/system/impermanence.nix b/options/system/impermanence.nix index 732f5da..ff50350 100644 --- a/options/system/impermanence.nix +++ b/options/system/impermanence.nix @@ -34,6 +34,47 @@ in Path to a persistent directory (usually a mount point to a standalone partition / subvolume), which will hold the persistent system state files. + + This should point to the entire persistent partition, this setup + then expects this directory to contain `passwords` and `system` subdirectories. + ''; + }; + }; + + home = { + enable = mkEnableOption '' + the Impermanence module for persisting important state directories. + + This requires home-manager. + ''; + + extraFiles = mkOption { + default = []; + type = types.listOf types.str; + example = literalExpression ''[".zshrc"]''; + description = '' + Additional files in home to link to persistent storage. + ''; + }; + + extraDirectories = mkOption { + default = []; + type = types.listOf types.str; + example = literalExpression ''["Downloads"]''; + description = '' + Additional directories in home to link to persistent storage. + ''; + }; + + persistentMountPoint = mkOption { + default = "/persist/home"; + description = '' + Path to a persistent directory (usually a mount point to a + standalone partition / subvolume), which will hold the persistent + system state files. + + This does not expect any subdirectories, all of the persistent home files + will be put directly in here. The user should be the owner of this direcotry. ''; }; };