feat: better impermanence

This commit is contained in:
Patrick 2023-09-05 17:50:55 +02:00
parent 35cb9101b5
commit 87178a11e9
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F
6 changed files with 122 additions and 48 deletions

View file

@ -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;

View file

@ -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;
};
})
)
);
}
];
}

View file

@ -25,6 +25,8 @@
repeat_rate = "60";
accel_profile = "flat";
pointer_accel = "0.5";
};
"type:touchpad" = {
natural_scroll = "enabled";
};
};

View file

@ -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"
];
};
}

View file

@ -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
];

View file

@ -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/"
];
};
};