1
Fork 0
satellite/hosts/nixos/common/global/persistence.nix

43 lines
1.2 KiB
Nix
Raw Normal View History

2023-12-12 14:32:06 +01:00
# This file defines the "non-hardware dependent" part of opt-in persistence
# It imports impermanence, defines the basic persisted dirs, and ensures each
# users' home persist dir exists and has the right permissions
#
# It works even if / is tmpfs, btrfs snapshot, or even not ephemeral at all.
2024-08-27 13:30:17 +02:00
{
lib,
inputs,
config,
...
}:
{
2023-12-12 14:32:06 +01:00
imports = [ inputs.impermanence.nixosModules.impermanence ];
environment.persistence."/persist/state".directories = [
"/var/lib/systemd"
"/var/lib/nixos"
"/var/log"
];
# Allow non root users to specify the "allowOther" option.
# See [the imperanence readme](https://github.com/nix-community/impermanence#home-manager)
programs.fuse.userAllowOther = true;
# {{{ Create home directories
systemd.tmpfiles.rules =
let
2024-08-27 13:30:17 +02:00
users = lib.filter (v: v != null && v.isNormalUser) (
lib.mapAttrsToList (_: u: u) config.users.users
);
2023-12-12 14:32:06 +01:00
2024-08-27 13:30:17 +02:00
mkHomePersistFor =
location:
lib.forEach users (user: "d ${location}${user.home} ${user.homeMode} ${user.name} ${user.group} -");
2023-12-12 14:32:06 +01:00
in
lib.flatten [
(mkHomePersistFor "/persist/data")
(mkHomePersistFor "/persist/state")
(mkHomePersistFor "/persist/local/cache")
];
# }}}
}