Compare commits
No commits in common. "89ce47d4da2fa118cf8343512c44910a790ac8d0" and "96f1c6854be0a1bdc6a9f7146225714e54e70214" have entirely different histories.
89ce47d4da
...
96f1c6854b
16
flake.lock
generated
16
flake.lock
generated
@ -551,21 +551,6 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"impermanence": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1737831083,
|
|
||||||
"narHash": "sha256-LJggUHbpyeDvNagTUrdhe/pRVp4pnS6wVKALS782gRI=",
|
|
||||||
"owner": "nix-community",
|
|
||||||
"repo": "impermanence",
|
|
||||||
"rev": "4b3e914cdf97a5b536a889e939fb2fd2b043a170",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-community",
|
|
||||||
"repo": "impermanence",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"libgit2": {
|
"libgit2": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
@ -1156,7 +1141,6 @@
|
|||||||
"flake-parts": "flake-parts_4",
|
"flake-parts": "flake-parts_4",
|
||||||
"flake-registry": "flake-registry",
|
"flake-registry": "flake-registry",
|
||||||
"home-manager": "home-manager",
|
"home-manager": "home-manager",
|
||||||
"impermanence": "impermanence",
|
|
||||||
"lite-config": "lite-config",
|
"lite-config": "lite-config",
|
||||||
"lix-module": "lix-module",
|
"lix-module": "lix-module",
|
||||||
"nixpkgs": "nixpkgs_8",
|
"nixpkgs": "nixpkgs_8",
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
ataraxiasjel-nur.url = "github:AtaraxiaSjel/nur";
|
ataraxiasjel-nur.url = "github:AtaraxiaSjel/nur";
|
||||||
impermanence.url = "github:nix-community/impermanence";
|
|
||||||
lix-module = {
|
lix-module = {
|
||||||
# url = "https://git.lix.systems/lix-project/nixos-module/archive/2.92.0.tar.gz";
|
# url = "https://git.lix.systems/lix-project/nixos-module/archive/2.92.0.tar.gz";
|
||||||
url = "github:ataraxiasjel/lix-nixos-module/2.92.0-1";
|
url = "github:ataraxiasjel/lix-nixos-module/2.92.0-1";
|
||||||
|
@ -27,9 +27,6 @@
|
|||||||
hashedPassword = "$y$j9T$ZC44T3XYOPapB26cyPsA4.$8wlYEbwXFszC9nrg0vafqBZFLMPabXdhnzlT3DhUit6";
|
hashedPassword = "$y$j9T$ZC44T3XYOPapB26cyPsA4.$8wlYEbwXFszC9nrg0vafqBZFLMPabXdhnzlT3DhUit6";
|
||||||
shell = pkgs.bash;
|
shell = pkgs.bash;
|
||||||
};
|
};
|
||||||
users.users.test = {
|
|
||||||
isNormalUser = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
boot.supportedFilesystems = [ "zfs" ];
|
boot.supportedFilesystems = [ "zfs" ];
|
||||||
boot.zfs.forceImportRoot = false;
|
boot.zfs.forceImportRoot = false;
|
||||||
@ -40,35 +37,5 @@
|
|||||||
sing-box
|
sing-box
|
||||||
];
|
];
|
||||||
|
|
||||||
# Test persist module
|
|
||||||
persist.enable = true;
|
|
||||||
persist.cache.clean.enable = true;
|
|
||||||
persist.state.directories = [ "/etc" ];
|
|
||||||
persist.cache.directories = [ "/cache" ];
|
|
||||||
home-manager.users.ataraxia = {
|
|
||||||
home.stateVersion = "24.11";
|
|
||||||
persist.enable = true;
|
|
||||||
persist.cache.clean.enable = false;
|
|
||||||
persist.state.directories = [ "test-home" ];
|
|
||||||
persist.cache.directories = [
|
|
||||||
"test-1"
|
|
||||||
"test-2"
|
|
||||||
];
|
|
||||||
persist.state.files = [ "home" ];
|
|
||||||
};
|
|
||||||
home-manager.users.test = {
|
|
||||||
home.stateVersion = "24.11";
|
|
||||||
persist.enable = true;
|
|
||||||
persist.cache.clean.enable = true;
|
|
||||||
persist.cache.directories = [
|
|
||||||
"test-3"
|
|
||||||
"test-4"
|
|
||||||
];
|
|
||||||
persist.cache.files = [
|
|
||||||
"home"
|
|
||||||
"home3"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
system.stateVersion = "24.11";
|
system.stateVersion = "24.11";
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,4 @@
|
|||||||
{ lib, ... }:
|
{ ... }:
|
||||||
let
|
|
||||||
inherit (lib) filterAttrs;
|
|
||||||
inherit (builtins) attrNames readDir;
|
|
||||||
moduleDirs =
|
|
||||||
dir:
|
|
||||||
map (name: dir + "/${name}") (attrNames (filterAttrs (_: type: type == "directory") (readDir dir)));
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
imports = moduleDirs ./.;
|
|
||||||
}
|
}
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
{
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
inherit (lib) mkOption mkEnableOption;
|
|
||||||
inherit (lib.types) listOf path str;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options =
|
|
||||||
let
|
|
||||||
common = {
|
|
||||||
directories = mkOption {
|
|
||||||
type = listOf str;
|
|
||||||
default = [ ];
|
|
||||||
};
|
|
||||||
files = mkOption {
|
|
||||||
type = listOf str;
|
|
||||||
default = [ ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
persist = {
|
|
||||||
enable = mkEnableOption "A tmpfs root with explicit opt-in state";
|
|
||||||
persistRoot = mkOption {
|
|
||||||
type = path;
|
|
||||||
default = "/persist";
|
|
||||||
};
|
|
||||||
# Stuff that matters
|
|
||||||
# TODO backups
|
|
||||||
state = {
|
|
||||||
# backup = {...};
|
|
||||||
} // common;
|
|
||||||
# Stuff that's just there to speed up the system
|
|
||||||
cache = {
|
|
||||||
clean = {
|
|
||||||
enable = mkEnableOption "cleaning the cache files and directories";
|
|
||||||
dates = mkOption {
|
|
||||||
type = str;
|
|
||||||
default = "weekly";
|
|
||||||
description = "A systemd.time calendar description of when to clean the cache files";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
} // common;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,147 +0,0 @@
|
|||||||
{
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
inputs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
inherit (lib)
|
|
||||||
escapeShellArg
|
|
||||||
filterAttrs
|
|
||||||
mapAttrs
|
|
||||||
mapAttrs'
|
|
||||||
mkEnableOption
|
|
||||||
mkIf
|
|
||||||
mkMerge
|
|
||||||
mkOption
|
|
||||||
nameValuePair
|
|
||||||
;
|
|
||||||
inherit (lib.types) listOf path str;
|
|
||||||
inherit (builtins) concatMap;
|
|
||||||
cfg = config.persist;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
imports = [ inputs.impermanence.nixosModules.impermanence ];
|
|
||||||
|
|
||||||
options =
|
|
||||||
let
|
|
||||||
common = {
|
|
||||||
directories = mkOption {
|
|
||||||
type = listOf str;
|
|
||||||
default = [ ];
|
|
||||||
};
|
|
||||||
files = mkOption {
|
|
||||||
type = listOf str;
|
|
||||||
default = [ ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
persist = {
|
|
||||||
enable = mkEnableOption "A tmpfs root with explicit opt-in state";
|
|
||||||
persistRoot = mkOption {
|
|
||||||
type = path;
|
|
||||||
default = "/persist";
|
|
||||||
};
|
|
||||||
# Stuff that matters
|
|
||||||
# TODO backups
|
|
||||||
state = {
|
|
||||||
# backup = {...};
|
|
||||||
} // common;
|
|
||||||
# Stuff that's just there to speed up the system
|
|
||||||
cache = {
|
|
||||||
clean = {
|
|
||||||
enable = mkEnableOption "cleaning the cache files and directories";
|
|
||||||
dates = mkOption {
|
|
||||||
type = str;
|
|
||||||
default = "weekly";
|
|
||||||
description = "A systemd.time calendar description of when to clean the cache files";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
} // common;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config =
|
|
||||||
let
|
|
||||||
# TODO: fix infinite recursion (can't get user home directory)
|
|
||||||
# userPersists = lib.mapAttrs (name: cfg:
|
|
||||||
# cfg.persist // {
|
|
||||||
# home = config.users.users.${name}.home;
|
|
||||||
# }
|
|
||||||
# ) config.home-manager.users;
|
|
||||||
takeAll = what: concatMap (x: x.${what});
|
|
||||||
persists = with cfg; [
|
|
||||||
state
|
|
||||||
cache
|
|
||||||
];
|
|
||||||
allFiles = takeAll "files" persists;
|
|
||||||
allDirectories = takeAll "directories" persists;
|
|
||||||
|
|
||||||
userPersists = mapAttrs (_: cfg: cfg.persist) config.home-manager.users;
|
|
||||||
usersFlatten = mapAttrs (
|
|
||||||
name: cfg:
|
|
||||||
let
|
|
||||||
persists = with cfg; [
|
|
||||||
state
|
|
||||||
cache
|
|
||||||
];
|
|
||||||
allHomeFiles = takeAll "files" persists;
|
|
||||||
allHomeDirectories = takeAll "directories" persists;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
home = "/home/${name}";
|
|
||||||
directories = allHomeDirectories;
|
|
||||||
files = allHomeFiles;
|
|
||||||
}
|
|
||||||
) userPersists;
|
|
||||||
in
|
|
||||||
mkIf cfg.enable {
|
|
||||||
# Persist users uid by default
|
|
||||||
persist.state.directories = [ "/var/lib/nixos" ];
|
|
||||||
|
|
||||||
environment.persistence.${cfg.persistRoot} = {
|
|
||||||
hideMounts = true;
|
|
||||||
directories = allDirectories;
|
|
||||||
files = allFiles;
|
|
||||||
users = usersFlatten;
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.services =
|
|
||||||
let
|
|
||||||
filtered = filterAttrs (_: cfg: cfg.cache.clean.enable) userPersists;
|
|
||||||
in
|
|
||||||
mkMerge [
|
|
||||||
(mapAttrs' (
|
|
||||||
name: cfg:
|
|
||||||
let
|
|
||||||
absoluteHomePath = map (x: "/home/${name}/${x}");
|
|
||||||
in
|
|
||||||
nameValuePair "persist-cache-cleanup-${name}" {
|
|
||||||
description = "Cleaning up cache files and directories for user ${name}";
|
|
||||||
script = ''
|
|
||||||
${builtins.concatStringsSep "\n" (
|
|
||||||
map (x: "rm ${escapeShellArg x}") (absoluteHomePath cfg.cache.files)
|
|
||||||
)}
|
|
||||||
|
|
||||||
${builtins.concatStringsSep "\n" (
|
|
||||||
map (x: "rm -rf ${escapeShellArg x}") (absoluteHomePath cfg.cache.directories)
|
|
||||||
)}
|
|
||||||
'';
|
|
||||||
startAt = cfg.cache.clean.dates;
|
|
||||||
}
|
|
||||||
) filtered)
|
|
||||||
{
|
|
||||||
persist-cache-cleanup = mkIf cfg.cache.clean.enable {
|
|
||||||
description = "Cleaning up cache files and directories";
|
|
||||||
script = ''
|
|
||||||
${builtins.concatStringsSep "\n" (map (x: "rm ${escapeShellArg x}") cfg.cache.files)}
|
|
||||||
|
|
||||||
${builtins.concatStringsSep "\n" (map (x: "rm -rf ${escapeShellArg x}") cfg.cache.directories)}
|
|
||||||
'';
|
|
||||||
startAt = cfg.cache.clean.dates;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user