mirror of
https://github.com/nix-community/impermanence
synced 2024-11-13 23:27:15 +00:00
nixos: Write the directories creation script into store
When user writes a long list of directories, the original code generates a very long activation script, which can cause an "Argument list too long" error. This try to fix the issue by writing the directories creation script into nix store as an executable instead of repeating it multiple times.
This commit is contained in:
parent
16bc81cd32
commit
b9342b5e44
1 changed files with 10 additions and 7 deletions
17
nixos.nix
17
nixos.nix
|
@ -87,11 +87,11 @@ in
|
|||
|
||||
system.activationScripts =
|
||||
let
|
||||
# Create a directory in persistent storage, so we can bind
|
||||
# Script to create a directory in persistent storage, so we can bind
|
||||
# mount it. The directory structure's mode and ownership mirror those of
|
||||
# persistentStoragePath/dir;
|
||||
# TODO: Move this script to it's own file, add CI with shfmt/shellcheck.
|
||||
mkDirWithPerms = persistentStoragePath: dir:
|
||||
createDirectories = pkgs.writeShellScript "impermanence-create-directories"
|
||||
''
|
||||
# Given a source directory, /source, and a target directory,
|
||||
# /target/foo/bar/bazz, we want to "clone" the target structure
|
||||
|
@ -108,10 +108,10 @@ in
|
|||
# 1. Ensure both /source/qualifiedPath and qualifiedPath exist
|
||||
# 2. Copy the ownership of the source path into the target path
|
||||
# 3. Copy the mode of the source path into the target path
|
||||
(
|
||||
# capture the nix vars into bash to avoid escape hell
|
||||
sourceBase="${persistentStoragePath}"
|
||||
target="${dir}"
|
||||
|
||||
# Get inputs from command line arguments
|
||||
sourceBase="$1"
|
||||
target="$2"
|
||||
|
||||
# trim trailing slashes the root of all evil
|
||||
sourceBase="''${sourceBase%/}"
|
||||
|
@ -147,9 +147,12 @@ in
|
|||
# lastly we update the previousPath to continue down the tree
|
||||
previousPath="$currentTargetPath"
|
||||
done
|
||||
)
|
||||
'';
|
||||
|
||||
mkDirWithPerms = persistentStoragePath: dir: ''
|
||||
${createDirectories} "${persistentStoragePath}" "${dir}"
|
||||
'';
|
||||
|
||||
# Build an activation script which creates all persistent
|
||||
# storage directories we want to bind mount.
|
||||
mkDirCreationScriptForPath = persistentStoragePath:
|
||||
|
|
Loading…
Reference in a new issue