nix-config/nixos/_mixins/optin-persistence.nix

41 lines
1.2 KiB
Nix
Raw Permalink Normal View History

2023-10-16 18:46:06 +00:00
# https://nixos.wiki/wiki/Impermanence
#
# https://nixos.wiki/wiki/Impermanence
# https://grahamc.com/blog/erase-your-darlings/
# https://lantian.pub/en/article/modify-computer/nixos-impermanence.lantian/
#
# 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.
{ lib, inputs, config, ... }: {
imports = [
inputs.impermanence.nixosModules.impermanence
];
environment.persistence = {
"/persist" = {
directories = [
2023-10-16 18:46:06 +00:00
"/var/lib/containers"
"/var/lib/systemd"
"/var/lib/nixos"
2023-10-16 18:46:06 +00:00
# "/var/log"
"/srv"
];
};
};
programs.fuse.userAllowOther = true;
system.activationScripts.persistent-dirs.text =
let
mkHomePersist = user: lib.optionalString user.createHome ''
mkdir -p /persist/${user.home}
chown ${user.name}:${user.group} /persist/${user.home}
chmod ${user.homeMode} /persist/${user.home}
'';
users = lib.attrValues config.users.users;
in
lib.concatLines (map mkHomePersist users);
}