From: Scott Worley Date: Sun, 2 Aug 2026 01:26:18 +0000 (-0700) Subject: Add the option to use `nix-env --set` for user profiles X-Git-Url: http://git.scottworley.com/auto-upgrade-with-pinch/commitdiff_plain/8baa5ec5de960253e6ecff6f7bcb13bb25609261?ds=inline;hp=6a301e7274267c1c8ac096944b8e7ccb8859340a Add the option to use `nix-env --set` for user profiles --- diff --git a/modules/auto-upgrade.nix b/modules/auto-upgrade.nix index 5f5fe3a..918b4a9 100644 --- a/modules/auto-upgrade.nix +++ b/modules/auto-upgrade.nix @@ -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 '' $remove_arg -iA "$(userenv_query "$user" .package)" + ${pkgs.nix}/bin/nix-env -f '' "$action" -A "$(userenv_query "$user" .package)" sync done < <( config_query '.userEnvironments | keys []' ) ''} diff --git a/upgrade-config.nix b/upgrade-config.nix index 4d69100..abf70aa 100644 --- a/upgrade-config.nix +++ b/upgrade-config.nix @@ -146,6 +146,7 @@ evalModules { otherPackagesAction = mkOption { type = types.enum [ "remove" + "set-remove" "keep" ]; default = "remove"; @@ -158,6 +159,9 @@ evalModules { through your one entire-environment package. This keeps your environment declarative and ensures that all packages receive regular updates. + + "set-remove" is mostly equilavent to "remove", but uses + nix-env --set, resulting in a profile without a manifest.nix. ''; }; };