]> git.scottworley.com Git - auto-upgrade-with-pinch/blobdiff - modules/auto-upgrade.nix
Add the option to use `nix-env --set` for user profiles
[auto-upgrade-with-pinch] / modules / auto-upgrade.nix
index 5f5fe3ad6dbc5918509c9762dd0368fb7e3329d2..918b4a96c4f0a0d79d5c04049fd19f0bcb5d6883 100644 (file)
@@ -200,12 +200,16 @@ let
       hydrate ${config.system.build.nixos-rebuild}/bin/nixos-rebuild ${cfg.operation}
       sync
       while read user;do
-        remove_arg=-r
-        if [[ "$(userenv_query "$user" .otherPackagesAction)" == keep ]];then
-          remove_arg=
-        fi
+        configured_action=$(userenv_query "$user" .otherPackagesAction)
+        action=
+        case "$configured_action" in
+          keep)       action=-i;;
+          remove)     action=-ir;;
+          set-remove) action=--set;;
+          *)          die "Unexpected otherPackagesAction $configured_action for user $user"
+        esac
         hydrate /run/wrappers/bin/sudo -u "$user" \
-          ${pkgs.nix}/bin/nix-env -f '<nixpkgs>' $remove_arg -iA "$(userenv_query "$user" .package)"
+          ${pkgs.nix}/bin/nix-env -f '<nixpkgs>' "$action" -A "$(userenv_query "$user" .package)"
         sync
       done < <( config_query '.userEnvironments | keys []' )
     ''}