home-manager: Create missing target directories for files

Create missing parent directories for nonexistent files in persistent
storage.

Reported in #53.
This commit is contained in:
talyz 2021-11-14 18:55:09 +01:00
parent 00df1e57bb
commit 6b474b097a
No known key found for this signature in database
GPG key ID: 2DED2151F4671A2B

View file

@ -293,35 +293,50 @@ in
cfg.${persistentStoragePath}.directories;
in
mkIf (any (path: cfg.${path}.directories != [ ]) persistentStoragePaths) {
createAndMountPersistentStoragePaths =
dag.entryBefore
[ "writeBoundary" ]
''
declare -A mountedPaths
${(concatMapStrings mkBindMountsForPath persistentStoragePaths)}
'';
mkMerge [
(mkIf (any (path: cfg.${path}.directories != [ ]) persistentStoragePaths) {
createAndMountPersistentStoragePaths =
dag.entryBefore
[ "writeBoundary" ]
''
declare -A mountedPaths
${(concatMapStrings mkBindMountsForPath persistentStoragePaths)}
'';
unmountPersistentStoragePaths =
dag.entryBefore
[ "createAndMountPersistentStoragePaths" ]
''
unmountBindMounts() {
${concatMapStrings mkUnmountsForPath persistentStoragePaths}
}
unmountPersistentStoragePaths =
dag.entryBefore
[ "createAndMountPersistentStoragePaths" ]
''
unmountBindMounts() {
${concatMapStrings mkUnmountsForPath persistentStoragePaths}
}
# Run the unmount function on error to clean up stray
# bind mounts
trap "unmountBindMounts" ERR
'';
# Run the unmount function on error to clean up stray
# bind mounts
trap "unmountBindMounts" ERR
'';
runUnmountPersistentStoragePaths =
dag.entryBefore
[ reloadSystemd ]
''
unmountBindMounts
'';
};
runUnmountPersistentStoragePaths =
dag.entryBefore
[ reloadSystemd ]
''
unmountBindMounts
'';
})
(mkIf (any (path: cfg.${path}.files != [ ]) persistentStoragePaths) {
createTargetFileDirectories =
dag.entryBefore
[ "writeBoundary" ]
(concatMapStrings
(persistentStoragePath:
concatMapStrings
(targetFilePath: ''
mkdir -p ${concatPaths [ persistentStoragePath (dirOf targetFilePath) ]}
'')
cfg.${persistentStoragePath}.files)
persistentStoragePaths);
})
];
};
}