diff --git a/modules/impermanence/default.nix b/modules/impermanence/default.nix index 31ccd80..5655d18 100644 --- a/modules/impermanence/default.nix +++ b/modules/impermanence/default.nix @@ -4,6 +4,7 @@ pkgs, ... }: { + imports = [./users.nix]; # to allow all users to access hm managed persistent folders programs.fuse.userAllowOther = true; fileSystems."/state".neededForBoot = true; diff --git a/modules/impermanence/users.nix b/modules/impermanence/users.nix index 4979cba..2b252a8 100644 --- a/modules/impermanence/users.nix +++ b/modules/impermanence/users.nix @@ -1,50 +1,81 @@ -userName: { +{ config, lib, ... -}: { - environment.persistence."/state" = { - users.${userName} = let - hmConfig = config.home-manager.users.${userName}; - in { - files = with lib.lists; - [ - ".ssh/known_hosts" - ] - ++ optionals hmConfig.programs.rofi.enable [ - ".cache/rofi-3.runcache" - ]; - directories = with lib.lists; - [] - ++ - # firefox cannot be a symlink as home manager refuses put files outside your $HOME - optionals hmConfig.programs.firefox.enable [ - ".mozilla" - ] - ++ optionals hmConfig.programs.atuin.enable [ - ".local/share/atuin" - ] - ++ optionals hmConfig.programs.direnv.enable [ - ".local/share/direnv" - ] - ++ optionals hmConfig.programs.neovim.enable [ - ".local/share/nvim" - ".local/state/nvim" - ".cache/nvim" - ] - # root should never use interactive programs - ++ optionals config.services.pipewire.enable [ - # persist sound config - ".local/state/wireplumber" - ] - # Folders for steam - ++ optionals config.programs.steam.enable - [ - ".local/share/Steam" - ".steam" - # Ken follets pillars of earth - ".local/share//Daedalic Entertainment GmbH/" - ]; - }; - }; +}: let + inherit + (lib) + flip + mapAttrs + attrNames + mkOption + types + mkMerge + isAttrs + ; +in { + # Expose a home manager module for each user that allows extending + # environment.persistence.${sourceDir}.users.${userName} simply by + # specifying home.persistence.${sourceDir} in home manager. + home-manager.sharedModules = [ + { + options.home.persistence = mkOption { + description = "Additional persistence config for the given source path"; + default = {}; + type = types.attrsOf (types.submodule { + options = { + files = mkOption { + description = "Additional files to persist via NixOS impermanence."; + type = types.listOf (types.either types.attrs types.str); + default = []; + }; + + directories = mkOption { + description = "Additional directories to persist via NixOS impermanence."; + type = types.listOf (types.either types.attrs types.str); + default = []; + }; + }; + }); + }; + } + ]; + + # For each user that has a home-manager config, merge the locally defined + # persistence options that we defined above. + imports = let + mkUserFiles = map (x: + {parentDirectory.mode = "700";} + // ( + if isAttrs x + then x + else {file = x;} + )); + mkUserDirs = map (x: + {mode = "700";} + // ( + if isAttrs x + then x + else {directory = x;} + )); + in [ + { + environment.persistence = mkMerge ( + flip map + (attrNames config.home-manager.users) + ( + user: let + hmUserCfg = config.home-manager.users.${user}; + in + flip mapAttrs hmUserCfg.home.persistence + (_: sourceCfg: { + users.${user} = { + files = mkUserFiles sourceCfg.files; + directories = mkUserDirs sourceCfg.directories; + }; + }) + ) + ); + } + ]; } diff --git a/users/common/graphical/sway/default.nix b/users/common/graphical/sway/default.nix index cd91675..8f55fad 100644 --- a/users/common/graphical/sway/default.nix +++ b/users/common/graphical/sway/default.nix @@ -25,6 +25,8 @@ repeat_rate = "60"; accel_profile = "flat"; pointer_accel = "0.5"; + }; + "type:touchpad" = { natural_scroll = "enabled"; }; }; diff --git a/users/common/impermanence.nix b/users/common/impermanence.nix new file mode 100644 index 0000000..4701e96 --- /dev/null +++ b/users/common/impermanence.nix @@ -0,0 +1,33 @@ +{ + config, + lib, + ... +}: { + home.persistence."/state" = { + files = with lib.lists; + [ + ".ssh/known_hosts" + ] + ++ optionals config.programs.rofi.enable [ + ".cache/rofi-3.runcache" + ]; + directories = with lib.lists; + [] + ++ + # firefox cannot be a symlink as home manager refuses put files outside your $HOME + optionals config.programs.firefox.enable [ + ".mozilla" + ] + ++ optionals config.programs.atuin.enable [ + ".local/share/atuin" + ] + ++ optionals config.programs.direnv.enable [ + ".local/share/direnv" + ] + ++ optionals config.programs.neovim.enable [ + ".local/share/nvim" + ".local/state/nvim" + ".cache/nvim" + ]; + }; +} diff --git a/users/patrick/default.nix b/users/patrick/default.nix index 4222593..1d9f181 100644 --- a/users/patrick/default.nix +++ b/users/patrick/default.nix @@ -7,7 +7,6 @@ imports = [ ../../modules/graphical/wayland.nix ../../modules/graphical/steam.nix - (import ../../modules/impermanence/users.nix "patrick") (import ../../modules/optional/smb-mounts.nix "patrick") ./impermanence.nix ]; @@ -33,6 +32,7 @@ ./patrick.nix ./ssh.nix ../common + ../common/impermanence.nix ../common/interactive.nix ../common/graphical ]; diff --git a/users/patrick/impermanence.nix b/users/patrick/impermanence.nix index 79a9e57..7c7c893 100644 --- a/users/patrick/impermanence.nix +++ b/users/patrick/impermanence.nix @@ -10,8 +10,15 @@ ".config/Nextcloud" # for electron signal app state - ".config/signal" + ".config/Signal" ".config/discord" + # persist sound config + ".local/state/wireplumber" + # Folders for steam + ".local/share/Steam" + ".steam" + # Ken follets pillars of earth + ".local/share//Daedalic Entertainment GmbH/" ]; }; };