Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assertion that config.nixpkgs cannot be set if useGlobalPkgs is enabled #6172

Merged
merged 1 commit into from
Feb 16, 2025

Conversation

justDeeevin
Copy link
Contributor

Description

When useGlobalPkgs is enabled, setting nixpkgs.config and nixpkgs.overlays in the home config has no effect. There is an assertion in place intended to throw an error if the user tries to set these options in this scenario, but it uses an OR instead of an AND, allowing for one of them to be set. This PR replaces this OR for an AND.

Fixes #6079.

Checklist

  • Change is backwards compatible.

  • Code formatted with ./format.

  • Code tested through nix-shell --pure tests -A run.all or nix develop --ignore-environment .#all using Flakes.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.

Maintainer CC

@thiagokokada

This fixes the assertion that `config.nixpkgs` cannot be set if
`useGlobalPkgs` is enabled
@justDeeevin
Copy link
Contributor Author

Been a minute... what's left to get this merged?

Copy link
Contributor

@Adda0 Adda0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I do not think there is anything left to do. The PR just needs to wait for someone to merge it.

@thiagokokada
Copy link
Contributor

CC @rycee .

@khaneliman khaneliman merged commit eb44c16 into nix-community:master Feb 16, 2025
3 checks passed
ornicar added a commit to ornicar/dotfiles that referenced this pull request Feb 16, 2025
@Zerodya
Copy link

Zerodya commented Feb 16, 2025

I updated my flake.lock this morning only to get this failed assertions error:

error:
       … while calling the 'head' builtin
         at /nix/store/brjzz8wv5k09bq0yrvhc1j4hd8677k21-source/lib/attrsets.nix:1574:11:
         1573|         || pred here (elemAt values 1) (head values) then
         1574|           head values
             |           ^
         1575|         else

       … while evaluating the attribute 'value'
         at /nix/store/brjzz8wv5k09bq0yrvhc1j4hd8677k21-source/lib/modules.nix:853:9:
          852|     in warnDeprecation opt //
          853|       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          854|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error:
       Failed assertions:
       - alpha profile: `nixpkgs` options are disabled when `home-manager.useGlobalPkgs` is enabled.

Now, I haven't found any nixpkgs options in my home config, and we all know how unhelpful nix errors are. So maybe this should've been a warning and not an error, since I can't update my system anymore even though it was not broken before.

Anyway, I set useGlobalPkgs = false; in my flake, but now home-manager can't see the allowUnfreePredicate I have set in my system and complains that it can't install some of my packages. I couldn't find any documentation about how to allow unfree packages in home-manager so maybe someone here could help me with this?

@panchoh
Copy link
Contributor

panchoh commented Feb 16, 2025

@Zerodya, if you use stylix, check this issue.

@Zerodya
Copy link

Zerodya commented Feb 16, 2025

Ah, I do. Thank you for pointing me there, I will follow that issue now.

@gaelj
Copy link

gaelj commented Feb 16, 2025

Same problem here (home manager + stylix + hyprpanel). Hyprpanel is impacted as well.

+1 for it to be a warning rather than a hard error, so that we can continue to update home manager until all concerned upstreams have fixed the bug on their side.

@tuxiqae
Copy link
Contributor

tuxiqae commented Feb 16, 2025

In my case it broke my allowUnfree settings:

nixpkgs.config.allowUnfree = true;
nixpkgs.config.allowUnfreePredicate = _: true;
- <myUser> profile: `nixpkgs` options are disabled when `home-manager.useGlobalPkgs` is enabled.

Not sure why, since it's not like it was broken before I guess.

brckd added a commit to brckd/home-manager that referenced this pull request Feb 16, 2025
Temporarily fixes backwards compatibility as issued in nix-community#6172.
brckd added a commit to brckd/home-manager that referenced this pull request Feb 16, 2025
Temporarily fixes backwards compatibility as issued in nix-community#6172.
tetov pushed a commit to tetov/home-manager that referenced this pull request Feb 16, 2025
This fixes the assertion that `config.nixpkgs` cannot be set if
`useGlobalPkgs` is enabled
khaneliman pushed a commit to brckd/home-manager that referenced this pull request Feb 17, 2025
Temporarily fixes backwards compatibility as issued in nix-community#6172.
khaneliman pushed a commit that referenced this pull request Feb 17, 2025
Temporarily fixes backwards compatibility as issued in #6172.
@brckd
Copy link
Contributor

brckd commented Feb 17, 2025

The error has been temporarily removed as of #6466, so updating Home Manager should fix it, but make sure to adapt your configurations nonetheless.

Silveere added a commit to Silveere/nixfiles that referenced this pull request Feb 17, 2025
This allows for setting overlays at the home level while also inheriting
the global nixpkgs configuration. This should theoretically work exactly
like useGlobalPkgs while still allowing for flexibility at the home
level. See nix-community/home-manager#6172
@Silveere
Copy link

If anybody wants a solution that lets you have the advantages of useGlobalPkgs while still letting you configure Home Manager's instance of nixpkgs, my solution was to write a custom submodule for the home-manager.users option in NixOS which injects the config and overlays from the system nixpkgs instance into each user's home-manager instance. Here is how I implemented it:

https://github.com/Silveere/nixfiles/blob/cab0e3e023c85dd85d6944ca068c4e4d373a781c/flake/system.nix#L172-L219

This is part of a flake-parts module that creates my nixosConfiguration outputs, and it does some other unrelated things as well. The important parts are 199-207 and 216-218. Keep in mind that the config arg used in line 204 comes from NixOS, not Home Manager.

Perhaps a similar implementation could be added to Home Manager, but there might be some unforeseen problems with this approach (e.g., if a user overrides _module.args.pkgs in NixOS, although I'd imagine this would cause much bigger problems and is probably an extreme edge case).

@gaelj
Copy link

gaelj commented Feb 20, 2025

Here is @Silveere 's solution adapted for setups which don't involve flake-parts:

  • set home-manager.useGlobalPkgs = false;
  • in each user's home-manager module, add :
    nixpkgs = {
      config = lib.mapAttrs (n: v: lib.mkDefault v) osConfig.nixpkgs.config;
      # mkOrder 900 is after mkBefore but before default order
      overlays = lib.mkOrder 900 osConfig.nixpkgs.overlays;
    };

It silences the warning, but it really should be fixed in all upstreams projects.

@justDeeevin
Copy link
Contributor Author

I'm very sorry i caused so much of a stirr with this change -- good learning experience to consider the impact of my code, i suppose

@brckd
Copy link
Contributor

brckd commented Feb 20, 2025

I'm very sorry i caused so much of a stirr with this change -- good learning experience to consider the impact of my code, i suppose

Don't worry, this was a learning experience for all of us. You fixed a bug which was clearly not intended and needed to be addressed. Although an intermediate warning would have been nice, this quickly urged configs and libraries to be updated, which was bound to happen sooner or later. Luckily it seems that pretty much only Stylix users were affected by this and it was all resolved within a day or two. But you're right, it really shows what unforeseen consequences a simple change can have!

@RossSmyth
Copy link

RossSmyth commented Feb 24, 2025

Yeah, how are you supposed to modify the nixpkgs config then? It would be good if that was documented somewhere. I got this for the allowUnfree config option which is pretty common to have set I believe.

@brckd
Copy link
Contributor

brckd commented Feb 24, 2025

@RossSmyth You're using useGlobalPkgs, which means that Home Manager will use the Nixpkgs instance NixOS uses. Therefore you have to move nixpkgs.allowUnfree and all your other Nixpkgs configurations into your NixOS module.

347Online pushed a commit to 347Online/home-manager that referenced this pull request Mar 1, 2025
This fixes the assertion that `config.nixpkgs` cannot be set if
`useGlobalPkgs` is enabled
347Online pushed a commit to 347Online/home-manager that referenced this pull request Mar 1, 2025
Temporarily fixes backwards compatibility as issued in nix-community#6172.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet