nix-config/hosts/common/global/optin-persistence.nix
Greg Burd f3fd89af54
A fork of Misterio77 and his standard template.
Many thangs to the hard work and generous availability of:
git@github.com:Misterio77/nix-config.git
2023-09-15 10:53:38 -04:00

33 lines
1,010 B
Nix

# 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/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);
}