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

Profiles imports are brittle, causing failure if imported twice #136

Closed
ymarkus opened this issue Feb 23, 2021 · 5 comments · Fixed by #139
Closed

Profiles imports are brittle, causing failure if imported twice #136

ymarkus opened this issue Feb 23, 2021 · 5 comments · Fixed by #139
Labels
bug Something isn't working

Comments

@ymarkus
Copy link
Contributor

ymarkus commented Feb 23, 2021

Expected Behavior

If I set users.users.<name>.shell in the users/<name>/default.nix file, there should be no conflicts anywhere (happens for any user).

Current Behavior

Building the system configuration errors out with following:
for users.users.<name>.shell = pkgs.zsh:

The unique option `users.users.<name>.shell' is defined multiple times, in:
 - <unknown-file>
 - <unknown-file>.

Possible Solution

Maybe I have to set it somewhere else? Can't find anything in the documentation...

@ymarkus ymarkus added the bug Something isn't working label Feb 23, 2021
@nrdxp
Copy link
Collaborator

nrdxp commented Feb 23, 2021

I can't reproduce this error in either core or community from a fresh checkout. What revision are you on? The only place I set the default shell for users is: https://github.com/divnix/devos/blob/community/profiles/develop/zsh/default.nix#L9

This doesn't conflict with users.users.<name>.shell though, as I tested it explicitly, and this is only set if your using the community branch and develop or zsh profile. You might want to grep around and see if you accidentally set it twice somewhere, or perhaps this was an issue with an older revision but is now resolved. Worst case scenario, you can always force the setting with mkForce.

I'll leave this open for a bit to help you find a solution.

@ymarkus
Copy link
Contributor Author

ymarkus commented Feb 23, 2021

OK, I've found the error. It seems like if you import a profile twice, it does weird things. Here's what happened:

  1. users.<name> get imported in core:
core = [ users.nixos users.root  ];
  1. core gets imported in graphics:
graphics = core ++ [ graphical ];
  1. graphics get imported in pc & gaming:
pc = graphics ++ [ develop networking.samba printing systems.pc virt zfs ];
gaming = graphics ++ [ graphical.games ];
  1. pc & gaming get imported in NixOS.nix:
imports = [...] ++ suites.pc ++ suites.gaming;

So everything in the profiles core & graphical got imported twice. That's why mkForce also didn't work.

Maybe a hint in the manual would be fitting if this is the case?

@nrdxp
Copy link
Collaborator

nrdxp commented Feb 23, 2021

Good catch, we don't want this biting us in the future. Perhaps the profiles attribute set in suites should just contain paths to the profile, instead of importing it outright. The default import logic prevents this sort of error when importing the same path twice, so we might want to just leverage that.

@ymarkus
Copy link
Contributor Author

ymarkus commented Feb 24, 2021

I just found out it can also happen when importing a profile inside suites and then importing it inside another profile like this:

{
  suites = with profiles; rec {
    [...]
    pc = graphics ++ [ develop networking.samba printing systems.pc virt zfs ];

    laptop = pc ++ [ systems.pc.laptop ];
  };
}

and laptop/default.nix:

{
  imports = [
    ../. # this imports pc
  ];
}

@nrdxp nrdxp changed the title Can't set users.users.<name>.shell Profiles imports are brittle, causing failure if imported twice Feb 25, 2021
nrdxp added a commit that referenced this issue Feb 25, 2021
* Leave importing to nixpkgs module implentation. Provide a path
  instead; resolves #136.
* Allow profiles which are not lambdas but simple attribute sets,
  relaxing the constraints a bit.
* Update profile README.md
* defaultImports -> mkProfileAttrs: allow importing subprofiles even
  if parent directory does not contain a default.nix.
@ymarkus
Copy link
Contributor Author

ymarkus commented Mar 3, 2021

Thanks, seems to work now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants