(untested) config for stinky and diff script.

This commit is contained in:
2025-10-27 12:21:57 +00:00
parent 32a22c783d
commit 762037d17f
22 changed files with 899 additions and 37 deletions

View File

@@ -27,7 +27,7 @@ in
};
};
environment.persistence."/persist".directories = [ "/var/lib/consul" ];
environment.persistence.${config.custom.impermanence.persistPath}.directories = [ "/var/lib/consul" ];
networking.firewall = {
allowedTCPPorts = [

View File

@@ -12,7 +12,7 @@
checkpoint-sync-url = "https://beaconstate.info";
};
};
environment.persistence."/persist".directories = [
environment.persistence.${config.custom.impermanence.persistPath}.directories = [
"/var/lib/private/lighthouse-mainnet"
];
}

View File

@@ -5,6 +5,7 @@
./console.nix
./cpufreq.nix
./flakes.nix
./impermanence-options.nix
./kernel.nix
./locale.nix
./network.nix

View File

@@ -0,0 +1,14 @@
{
lib,
...
}:
{
# Define impermanence options that need to be available to all modules
# The actual impermanence implementation is in common/impermanence.nix or common/impermanence-tmpfs.nix
options.custom.impermanence.persistPath = lib.mkOption {
type = lib.types.str;
default = "/persist";
description = "Path where persistent data is stored (e.g., /persist for btrfs, /nix/persist for tmpfs)";
};
}

View File

@@ -1,4 +1,4 @@
{ lib, ... }:
{ lib, config, ... }:
{
networking = {
useDHCP = true;
@@ -10,7 +10,7 @@
'';
};
environment.persistence."/persist" = {
environment.persistence.${config.custom.impermanence.persistPath} = {
directories = [ "/var/db/dhcpcd" ];
};
}

View File

@@ -22,6 +22,6 @@ in
config = mkIf cfg.enable {
services.tailscaleAutoconnect.enable = true;
services.tailscale.package = pkgs.unstable.tailscale;
environment.persistence."/persist".directories = [ "/var/lib/tailscale" ];
environment.persistence.${config.custom.impermanence.persistPath}.directories = [ "/var/lib/tailscale" ];
};
}

View File

@@ -0,0 +1,30 @@
{
lib,
config,
...
}:
{
# Common impermanence configuration shared by both btrfs and tmpfs variants
# This module should be imported by impermanence.nix or impermanence-tmpfs.nix
# The option custom.impermanence.persistPath is defined in common/global/impermanence-options.nix
environment.persistence.${config.custom.impermanence.persistPath} = {
directories = [
"/var/lib/nixos"
"/home"
];
files = [
"/etc/machine-id"
"/etc/ssh/ssh_host_ed25519_key"
"/etc/ssh/ssh_host_ed25519_key.pub"
"/etc/ssh/ssh_host_rsa_key"
"/etc/ssh/ssh_host_rsa_key.pub"
];
};
users.mutableUsers = false;
security.sudo.extraConfig = ''
Defaults lecture = never
'';
}

View File

@@ -0,0 +1,30 @@
{
lib,
config,
...
}:
{
# Impermanence configuration for tmpfs root filesystem
# Used for systems with tmpfs root (e.g., Raspberry Pi with SD card)
# Root is in-memory and wiped on every boot
# Persistent data is stored in /nix/persist (directory on the /nix partition)
# Import common impermanence configuration
imports = [ ./impermanence-common.nix ];
config = {
# Use /nix/persist for tmpfs-based impermanence
custom.impermanence.persistPath = "/nix/persist";
# tmpfs root filesystem
fileSystems."/" = {
device = "none";
fsType = "tmpfs";
options = [
"defaults"
"size=2G"
"mode=755"
];
};
};
}

View File

@@ -1,6 +1,5 @@
{
pkgs,
inputs,
lib,
config,
...
@@ -9,31 +8,22 @@ let
cfg = config.custom.impermanence;
in
{
# Import common impermanence configuration
imports = [ ./impermanence-common.nix ];
options.custom.impermanence = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Enable impermanent root fs";
description = "Enable impermanent root fs with btrfs subvolume rollback";
};
};
config = lib.mkIf cfg.enable {
environment.persistence = {
"/persist" = {
directories = [
"/var/lib/nixos"
"/home"
];
files = [
"/etc/machine-id"
"/etc/ssh/ssh_host_ed25519_key"
"/etc/ssh/ssh_host_ed25519_key.pub"
"/etc/ssh/ssh_host_rsa_key"
"/etc/ssh/ssh_host_rsa_key.pub"
];
};
};
# Use /persist for btrfs-based impermanence
custom.impermanence.persistPath = "/persist";
# Btrfs-specific filesystem options
fileSystems."/".options = [
"compress=zstd"
"noatime"
@@ -53,17 +43,7 @@ in
];
fileSystems."/var/log".neededForBoot = true;
users.mutableUsers = false;
# rollback results in sudo lectures after each reboot
security.sudo.extraConfig = ''
Defaults lecture = never
'';
# needed for allowOther in the home-manager impermanence config
programs.fuse.userAllowOther = true;
# reset / at each boot
# Btrfs subvolume rollback at each boot
# Note `lib.mkBefore` is used instead of `lib.mkAfter` here.
boot.initrd.postDeviceCommands = pkgs.lib.mkBefore ''
mkdir /mnt

View File

@@ -24,7 +24,7 @@ in
config = lib.mkIf cfg.enable {
# Persist root SSH directory for replication key
environment.persistence."/persist" = {
environment.persistence.${config.custom.impermanence.persistPath} = {
directories = [
"/root/.ssh"
];

View File

@@ -150,7 +150,7 @@ in
plugin.raw_exec.config.enabled = true;
};
environment.persistence."/persist".directories = [
environment.persistence.${config.custom.impermanence.persistPath}.directories = [
"/var/lib/docker"
"/var/lib/nomad"
];