mirror of
https://github.com/nix-community/impermanence
synced 2024-11-10 05:44:17 +00:00
Format with nixpkgs-fmt
This commit is contained in:
parent
bdec862a14
commit
27a984a236
2 changed files with 40 additions and 34 deletions
|
@ -13,8 +13,8 @@ in
|
|||
|
||||
home.persistence = mkOption {
|
||||
default = { };
|
||||
type = with types; attrsOf (submodule
|
||||
{
|
||||
type = with types; attrsOf (
|
||||
submodule {
|
||||
options =
|
||||
{
|
||||
directories = mkOption {
|
||||
|
@ -48,20 +48,21 @@ in
|
|||
"ln -s '${file}' $out";
|
||||
|
||||
mkLinkNameValuePair = persistentStoragePath: fileOrDir: {
|
||||
name = if cfg.${persistentStoragePath}.removePrefixDirectory then
|
||||
dirListToPath (tail (splitPath [ fileOrDir ]))
|
||||
else
|
||||
fileOrDir;
|
||||
name =
|
||||
if cfg.${persistentStoragePath}.removePrefixDirectory then
|
||||
dirListToPath (tail (splitPath [ fileOrDir ]))
|
||||
else
|
||||
fileOrDir;
|
||||
value = { source = link (concatPaths [ persistentStoragePath fileOrDir ]); };
|
||||
};
|
||||
|
||||
mkLinksToPersistentStorage = persistentStoragePath:
|
||||
listToAttrs
|
||||
(map
|
||||
(mkLinkNameValuePair persistentStoragePath)
|
||||
(cfg.${persistentStoragePath}.files ++ cfg.${persistentStoragePath}.directories));
|
||||
listToAttrs (map
|
||||
(mkLinkNameValuePair persistentStoragePath)
|
||||
(cfg.${persistentStoragePath}.files ++ cfg.${persistentStoragePath}.directories)
|
||||
);
|
||||
in
|
||||
foldl' recursiveUpdate { } (map mkLinksToPersistentStorage persistentStoragePaths);
|
||||
foldl' recursiveUpdate { } (map mkLinksToPersistentStorage persistentStoragePaths);
|
||||
|
||||
home.activation =
|
||||
let
|
||||
|
@ -70,7 +71,8 @@ in
|
|||
mkDirCreationSnippet = persistentStoragePath: dir:
|
||||
let
|
||||
targetDir = concatPaths [ persistentStoragePath dir ];
|
||||
in ''
|
||||
in
|
||||
''
|
||||
if [[ ! -e "${targetDir}" ]]; then
|
||||
mkdir -p "${targetDir}"
|
||||
fi
|
||||
|
@ -83,10 +85,11 @@ in
|
|||
[ "writeBoundary" ]
|
||||
(concatMapStrings
|
||||
(mkDirCreationSnippet persistentStoragePath)
|
||||
cfg.${persistentStoragePath}.directories);
|
||||
cfg.${persistentStoragePath}.directories
|
||||
);
|
||||
};
|
||||
in
|
||||
listToAttrs (map mkDirCreationScriptForPath persistentStoragePaths);
|
||||
listToAttrs (map mkDirCreationScriptForPath persistentStoragePaths);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
43
nixos.nix
43
nixos.nix
|
@ -12,8 +12,8 @@ in
|
|||
|
||||
environment.persistence = mkOption {
|
||||
default = { };
|
||||
type = with types; attrsOf (submodule
|
||||
{
|
||||
type = with types; attrsOf (
|
||||
submodule {
|
||||
options =
|
||||
{
|
||||
files = mkOption {
|
||||
|
@ -53,12 +53,12 @@ in
|
|||
};
|
||||
|
||||
mkLinksToPersistentStorage = persistentStoragePath:
|
||||
listToAttrs
|
||||
(map
|
||||
(mkLinkNameValuePair persistentStoragePath)
|
||||
cfg.${persistentStoragePath}.files);
|
||||
listToAttrs (map
|
||||
(mkLinkNameValuePair persistentStoragePath)
|
||||
cfg.${persistentStoragePath}.files
|
||||
);
|
||||
in
|
||||
foldl' recursiveUpdate { } (map mkLinksToPersistentStorage persistentStoragePaths);
|
||||
foldl' recursiveUpdate { } (map mkLinksToPersistentStorage persistentStoragePaths);
|
||||
|
||||
fileSystems =
|
||||
let
|
||||
|
@ -72,19 +72,20 @@ in
|
|||
};
|
||||
|
||||
mkBindMountsFromPath = persistentStoragePath:
|
||||
listToAttrs
|
||||
(map
|
||||
(mkBindMountNameValuePair persistentStoragePath)
|
||||
cfg.${persistentStoragePath}.directories);
|
||||
listToAttrs (map
|
||||
(mkBindMountNameValuePair persistentStoragePath)
|
||||
cfg.${persistentStoragePath}.directories
|
||||
);
|
||||
in
|
||||
foldl' recursiveUpdate { } (map mkBindMountsFromPath persistentStoragePaths);
|
||||
foldl' recursiveUpdate { } (map mkBindMountsFromPath persistentStoragePaths);
|
||||
|
||||
system.activationScripts =
|
||||
let
|
||||
mkDirCreationSnippet = persistentStoragePath: dir:
|
||||
let
|
||||
targetDir = concatPaths [ persistentStoragePath dir ];
|
||||
in ''
|
||||
in
|
||||
''
|
||||
if [[ ! -e "${targetDir}" ]]; then
|
||||
mkdir -p "${targetDir}"
|
||||
fi
|
||||
|
@ -93,23 +94,25 @@ in
|
|||
mkDirCreationScriptForPath = persistentStoragePath:
|
||||
nameValuePair
|
||||
"createDirsIn-${replaceStrings [ "/" "." ] [ "-" "" ] persistentStoragePath}"
|
||||
(noDepEntry
|
||||
(concatMapStrings
|
||||
(mkDirCreationSnippet persistentStoragePath)
|
||||
cfg.${persistentStoragePath}.directories));
|
||||
(noDepEntry (concatMapStrings
|
||||
(mkDirCreationSnippet persistentStoragePath)
|
||||
cfg.${persistentStoragePath}.directories
|
||||
));
|
||||
in
|
||||
listToAttrs (map mkDirCreationScriptForPath persistentStoragePaths);
|
||||
listToAttrs (map mkDirCreationScriptForPath persistentStoragePaths);
|
||||
|
||||
assertions =
|
||||
let
|
||||
files = concatMap (p: p.files or [ ]) (attrValues cfg);
|
||||
in [
|
||||
in
|
||||
[
|
||||
{
|
||||
assertion = all (hasPrefix "/etc") files;
|
||||
message =
|
||||
let
|
||||
offenders = filter (file: !(hasPrefix "/etc" file)) files;
|
||||
in ''
|
||||
in
|
||||
''
|
||||
environment.persistence.files:
|
||||
Currently, only files in /etc are supported.
|
||||
Please fix / remove the following paths:
|
||||
|
|
Loading…
Reference in a new issue