mirror of
https://github.com/aviallon/nixos-lib.git
synced 2026-04-06 01:38:06 +00:00
[NonPersistence] Parameterize persistence folder
This commit is contained in:
parent
1e2feafd9f
commit
9765bc6321
1 changed files with 23 additions and 6 deletions
|
|
@ -2,15 +2,32 @@
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
cfg = config.aviallon.non-persistence;
|
cfg = config.aviallon.non-persistence;
|
||||||
|
impermanenceSrc = builtins.fetchGit {
|
||||||
|
url = "https://github.com/nix-community/impermanence.git";
|
||||||
|
ref = "master";
|
||||||
|
rev = "ff2240b04ffb9322241b9f6374305cbf6a98a285";
|
||||||
|
};
|
||||||
|
persistFolder = "/persist";
|
||||||
|
impermanence = import "${impermanenceSrc}/nixos.nix";
|
||||||
|
mkLink = dest: src: ''L+ "${dest}" - - - - ${src}'';
|
||||||
|
mkDir = dest: ''d "${dest}" - - - -'';
|
||||||
|
mkPersist = path: concatLists [
|
||||||
|
(optional (dirOf path != path) (mkDir (dirOf path)))
|
||||||
|
[ (mkLink path "${persistFolder}/${path}") ]
|
||||||
|
];
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
imports = [
|
||||||
|
impermanence
|
||||||
|
];
|
||||||
|
|
||||||
options.aviallon.non-persistence = {
|
options.aviallon.non-persistence = {
|
||||||
enable = mkEnableOption "non-persitent root";
|
enable = mkEnableOption "non-persitent root";
|
||||||
};
|
};
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
assertions = [
|
assertions = [
|
||||||
{ assertion = hasAttr "/persist" config.fileSystems;
|
{ assertion = hasAttr persistFolder config.fileSystems;
|
||||||
message = "A /persist partition is needed for non-persistence";
|
message = "A ${persistFolder} partition is needed for non-persistence";
|
||||||
}
|
}
|
||||||
{ assertion = hasAttr "/var/log" config.fileSystems;
|
{ assertion = hasAttr "/var/log" config.fileSystems;
|
||||||
message = "A /var/log separate parition is needed to avoid missing early logs.";
|
message = "A /var/log separate parition is needed to avoid missing early logs.";
|
||||||
|
|
@ -18,9 +35,9 @@ in
|
||||||
];
|
];
|
||||||
|
|
||||||
environment.etc = {
|
environment.etc = {
|
||||||
nixos.source = "/persist/etc/nixos";
|
nixos.source = "${persistFolder}/etc/nixos";
|
||||||
NIXOS.source = "/persist/etc/NIXOS";
|
NIXOS.source = "${persistFolder}/etc/NIXOS";
|
||||||
machine-id.source = "/persist/etc/machine-id";
|
machine-id.source = "${persistFolder}/etc/machine-id";
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.tmpOnTmpfs = true;
|
boot.tmpOnTmpfs = true;
|
||||||
|
|
@ -31,7 +48,7 @@ in
|
||||||
autoFormat = true;
|
autoFormat = true;
|
||||||
label = "nixos-persistent-logs";
|
label = "nixos-persistent-logs";
|
||||||
};
|
};
|
||||||
"/persist" = {
|
"${persistFolder}" = {
|
||||||
neededForBoot = true;
|
neededForBoot = true;
|
||||||
label = "nixos-persistent-data";
|
label = "nixos-persistent-data";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue