Centralize the logic for escaping the shell values.

This commit is contained in:
Tom Alexander 2025-08-09 20:54:54 -04:00
parent 6b42a09468
commit 2c3e5483e9
No known key found for this signature in database
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 22 additions and 11 deletions

View File

@ -81,6 +81,7 @@
# me.install.user.file.talexander.".local/nixcfg" = ./README.org;
me.install.user.talexander.file.".local/nixcfg" = {
source = ./flake.lock;
method = "overwrite";
};
nix.settings.experimental-features = [

View File

@ -13,6 +13,12 @@ let
attrNames
;
get_shell_values = target: rec {
source = lib.strings.escapeShellArg "${target.source}";
homedir = config.users.users."${target.username}".home;
destination = lib.strings.escapeShellArg "${homedir}/${target.target}";
mode = lib.strings.escapeShellArg "${target.mode}";
};
install_user_file =
let
constructors = {
@ -26,10 +32,11 @@ let
"install" = (
target:
let
source = lib.strings.escapeShellArg "${target.source}";
homedir = config.users.users."${target.username}".home;
destination = lib.strings.escapeShellArg "${homedir}/${target.target}";
mode = lib.strings.escapeShellArg "${target.mode}";
inherit (get_shell_values target)
source
destination
mode
;
in
''
$DRY_RUN_CMD install $VERBOSE_ARG -D --compare -m ${mode} ${source} ${destination}
@ -38,8 +45,9 @@ let
"uninstall" = (
target:
let
homedir = config.users.users."${target.username}".home;
destination = lib.strings.escapeShellArg "${homedir}/${target.target}";
inherit (get_shell_values target)
destination
;
in
''
$DRY_RUN_CMD echo rm -f ${destination}
@ -51,9 +59,10 @@ let
"install" = (
target:
let
source = lib.strings.escapeShellArg "${target.source}";
homedir = config.users.users."${target.username}".home;
destination = lib.strings.escapeShellArg "${homedir}/${target.target}";
inherit (get_shell_values target)
source
destination
;
in
''
$DRY_RUN_CMD ln $VERBOSE_ARG -s ${source} ${destination}
@ -62,8 +71,9 @@ let
"uninstall" = (
target:
let
homedir = config.users.users."${target.username}".home;
destination = lib.strings.escapeShellArg "${homedir}/${target.target}";
inherit (get_shell_values target)
destination
;
in
''
$DRY_RUN_CMD echo rm -f ${destination}