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

bug: nix.package conflict with nix-darwin & NixOS modules #5870

Open
2 tasks done
sellout opened this issue Sep 19, 2024 · 0 comments
Open
2 tasks done

bug: nix.package conflict with nix-darwin & NixOS modules #5870

sellout opened this issue Sep 19, 2024 · 0 comments
Assignees
Labels
bug triage Issues or feature request that have not been triaged yet

Comments

@sellout
Copy link

sellout commented Sep 19, 2024

Are you following the right branch?

  • My Nixpkgs and Home Manager versions are in sync

Is there an existing issue for this?

  • I have searched the existing issues

Issue description

The nix module requires that nix.package is set (it would be helpful if the description explained why it doesn’t have a default), but the Home Manager modules for nix-darwin and NixOS set nix.package unconditionally.

I share most of my Home Manager configuration between multiple accounts and multiple machines. I had been always using home-manager explicitly, but decided to switch to the nix-darwin and NixOS modules for systems that I administer. So my configuration is loaded all three ways – home-manager, darwin-rebuild, and nixos-rebuild.

Since I have nix.packages = pkgs.nix in my shared config, this now errors when I use Home Manager as a module:

error: The option `home-manager.users.greg.nix.package' is defined multiple times while it's expected to be unique.

Definition values:
- In `<unknown-file>': <derivation nix-2.18.5>
- In `/nix/store/hxhym8c5xz6dxkl3d9yppiwlnzk3khn7-source/nixos/common.nix': <derivation nix-2.18.5>
Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.

The error makes sense, but I think the fix should be in Home Manager somewhere. There are a few options, in my order of preference:

  1. make pkgs.nix the default value in modules/misc/nix.nix, which makes it less likely that a user will override it, and if they do, they can decide how they want to manage this issue;
  2. have nixos/common.nix use lib.mkDefault, allowing the user’s setting to take precedence over the system module; or
  3. have nixos/common.nix use lib.mkForce, ensuring that the system modue’s version always takes precedence.

Number 1 seems like the best option to me, but considering the default is explicitly set to null, I figure there’s some reason it’s not already done that way. Number 3 seems a bit ill-behaved, in that it will override what a user explicitly put in their config, so I don’t really like that. But again, the documentation doesn’t make it clear why this situation exists.

My workaround is to change nix.package = pkgs.nix to nix.package = lib.mkDefault pkgs.nix, and if that is the correct solution, it would be helpful if the docs were more descriptive.

(BTW, the channels listed by nix-info below make no sense to me. I do everything with flakes, and when I run nix-channel --list, there are no channels listed.)

Maintainer CC

I see no explicit mantainers on either modules/misc/nix.nix or nixos/common.nix, but @rycee (unsurprisingly) touched both recently.

System information

 - system: `"aarch64-darwin"`
 - host os: `Darwin 23.6.0, macOS 14.6.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.18.5`
 - channels(root): `"darwin, home-manager-20.09.tar.gz, nixpkgs-21.11-darwin, unstable"`
 - channels(greg): `"darwin, home-manager-22.05.tar.gz, nixpkgs-22.05-darwin, unstable"`
 - nixpkgs: `/nix/store/4a7cgzcnwyr0s82r3mk6gz0fngkdyvrx-source`
@sellout sellout added bug triage Issues or feature request that have not been triaged yet labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Issues or feature request that have not been triaged yet
Projects
None yet
Development

No branches or pull requests

4 participants