]> git.scottworley.com Git - auto-upgrade-with-pinch/commitdiff
Add the option to use `nix-env --set` for user profiles master
authorScott Worley <scottworley@scottworley.com>
Sun, 2 Aug 2026 01:26:18 +0000 (18:26 -0700)
committerScott Worley <scottworley@scottworley.com>
Sun, 2 Aug 2026 01:26:18 +0000 (18:26 -0700)
modules/auto-upgrade.nix
upgrade-config.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 []' )
     ''}
index 4d69100e3b944782ae42180758365628d92ade02..abf70aad2da6998c7de0b5b822c63be20a1db000 100644 (file)
@@ -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 <literal>package</literal>.
                     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.
                   '';
                 };
               };