From eb5815048f1be578e72ece4a4fd8d5525e00d467 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 9 Aug 2025 20:27:27 -0400 Subject: [PATCH] Add a check and uninstall phase. --- .../util/install_files/default.nix | 68 ++++++++++++------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/nix/configuration/util/install_files/default.nix b/nix/configuration/util/install_files/default.nix index 486a74a..ecdee39 100644 --- a/nix/configuration/util/install_files/default.nix +++ b/nix/configuration/util/install_files/default.nix @@ -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;