2024-03-05 22:57:41 +01:00
|
|
|
{impermanence, ...}: {
|
2023-08-25 00:57:42 +02:00
|
|
|
# Impermanence in NixOS is where the root directory isn't permanent, but gets
|
|
|
|
# wiped every reboot (such as by mounting it as tmpfs). Such a setup is
|
|
|
|
# possible because NixOS only needs /boot and /nix in order to boot, all
|
|
|
|
# other system files are simply links to files in /nix.
|
|
|
|
|
|
|
|
# The impermanence module bind-mounts persistent files and directories,
|
|
|
|
# stored in /nix/persist, into the tmpfs root partition on startup. For
|
|
|
|
# example: /nix/persist/etc/machine-id is mounted to /etc/machine-id.
|
2023-08-01 15:35:09 +02:00
|
|
|
# https://github.com/nix-community/impermanence
|
|
|
|
# https://nixos.wiki/wiki/Impermanence
|
2023-08-25 00:57:42 +02:00
|
|
|
# https://elis.nu/blog/2020/05/nixos-tmpfs-as-root/
|
2023-08-01 15:35:09 +02:00
|
|
|
|
|
|
|
imports = [
|
|
|
|
impermanence.nixosModules.impermanence
|
|
|
|
];
|
|
|
|
|
2023-08-25 00:57:42 +02:00
|
|
|
# Each module will configure the paths they need persisted. Here we define
|
|
|
|
# some general system paths that don't really fit anywhere else.
|
2023-08-01 15:35:09 +02:00
|
|
|
environment.persistence."/nix/persist" = {
|
|
|
|
hideMounts = true;
|
|
|
|
directories = [
|
2024-03-30 23:28:54 +01:00
|
|
|
# The uid and gid maps for entities without a static id is saved in
|
|
|
|
# /var/lib/nixos. Persist to ensure they aren't changed between reboots.
|
|
|
|
{
|
|
|
|
directory = "/var/lib/nixos";
|
|
|
|
user = "root";
|
|
|
|
group = "root";
|
|
|
|
mode = "0755";
|
|
|
|
}
|
2024-03-05 22:17:26 +01:00
|
|
|
# Save the last run time of persistent timers so systemd knows if they were missed
|
2024-03-05 22:57:41 +01:00
|
|
|
{
|
|
|
|
directory = "/var/lib/systemd/timers";
|
|
|
|
user = "root";
|
|
|
|
group = "root";
|
|
|
|
mode = "0755";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
directory = "/var/log";
|
|
|
|
user = "root";
|
|
|
|
group = "root";
|
|
|
|
mode = "0755";
|
|
|
|
}
|
2024-04-03 00:23:45 +02:00
|
|
|
# /var/tmp is meant for temporary files that are preserved across
|
|
|
|
# reboots. Some programs might store files too big for in-memory /tmp
|
|
|
|
# there. Files older than 10 days are cleaned by systemd.
|
|
|
|
{
|
|
|
|
directory = "/var/tmp";
|
|
|
|
user = "root";
|
|
|
|
group = "root";
|
|
|
|
mode = "1777";
|
|
|
|
}
|
2023-08-01 15:35:09 +02:00
|
|
|
];
|
|
|
|
files = [
|
2023-08-01 16:55:53 +02:00
|
|
|
"/etc/machine-id" # needed for /var/log
|
2023-08-01 15:35:09 +02:00
|
|
|
];
|
|
|
|
users.caspervk = {
|
|
|
|
directories = [
|
2024-03-05 22:17:26 +01:00
|
|
|
"/" # entire home directory (TODO?)
|
2023-08-01 15:35:09 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|