mirror of
https://github.com/gburd/nix-config.git
synced 2024-11-14 00:26:24 +00:00
40 lines
1.2 KiB
Nix
40 lines
1.2 KiB
Nix
# 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 = [
|
|
"/var/lib/containers"
|
|
"/var/lib/systemd"
|
|
"/var/lib/nixos"
|
|
# "/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);
|
|
}
|