Add a check and uninstall phase.

This commit is contained in:
Tom Alexander 2025-08-09 20:27:27 -04:00
parent 1cb4fa4234
commit eb5815048f
No known key found for this signature in database
GPG Key ID: D3A179C9A53C0EDE

View File

@ -14,6 +14,14 @@ let
;
install_user_file =
let
constructors = {
"overwrite" = install_user_file_overwrite;
"symlink" = install_user_file_symlink;
};
in
stage: target: (constructors."${target.method}"."${stage}" target);
old_install_user_file =
let
constructors = {
"overwrite" = install_user_file_overwrite;
@ -21,27 +29,35 @@ let
};
in
(target: (constructors."${target.method}" target));
install_user_file_overwrite =
target:
let
source = lib.strings.escapeShellArg "${target.source}";
destination = lib.strings.escapeShellArg "${target.target}";
mode = lib.strings.escapeShellArg "${target.mode}";
in
# $DRY_RUN_CMD ${pkgs.toyboy}/bin/install $VERBOSE_ARG -D -m ${mode} ${source} ${destination}
''
$DRY_RUN_CMD install $VERBOSE_ARG -D --compare -m ${mode} ${source} ${destination}
'';
install_user_file_symlink =
target:
let
source = lib.strings.escapeShellArg "${target.source}";
destination = lib.strings.escapeShellArg "${target.target}";
mode = lib.strings.escapeShellArg "${target.mode}";
in
''
$DRY_RUN_CMD ln $VERBOSE_ARG -s ${source} ${destination}
'';
install_user_file_overwrite = {
"check" = (target: "");
"install" = (
target:
let
source = lib.strings.escapeShellArg "${target.source}";
destination = lib.strings.escapeShellArg "${target.target}";
mode = lib.strings.escapeShellArg "${target.mode}";
in
''
$DRY_RUN_CMD install $VERBOSE_ARG -D --compare -m ${mode} ${source} ${destination}
''
);
"uninstall" = (target: "");
};
install_user_file_symlink = {
"check" = (target: "");
"install" = (
target:
let
source = lib.strings.escapeShellArg "${target.source}";
destination = lib.strings.escapeShellArg "${target.target}";
in
''
$DRY_RUN_CMD ln $VERBOSE_ARG -s ${source} ${destination}
''
);
"uninstall" = (target: "");
};
in
{
imports = [ ];
@ -141,7 +157,9 @@ in
builtins.map (user: (builtins.map (path: user.file."${path}") (attrNames user.file))) enabled_users
);
enabled_file_targets = filter (target: target.enable) all_file_targets;
install_commands = builtins.map install_user_file enabled_file_targets;
check_commands = builtins.map (install_user_file "check") enabled_file_targets;
install_commands = builtins.map (install_user_file "install") enabled_file_targets;
uninstall_commands = builtins.map (install_user_file "uninstall") enabled_file_targets;
in
{
systemd.services.me-install-file = {
@ -158,10 +176,8 @@ in
Type = "oneshot";
RemainAfterExit = "yes";
};
script = (lib.strings.concatStringsSep "\n" install_commands);
# preStop = ''
# rm -f /home/talexander/.docker/config.json
# '';
script = (lib.strings.concatStringsSep "\n" (check_commands ++ install_commands));
preStop = (lib.strings.concatStringsSep "\n" uninstall_commands);
};
environment.etc."install_out".text = config.systemd.services.me-install-file.script;