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

NixOS users.users.<user> attribute name and .name can differ #147

Merged

Conversation

KoviRobi
Copy link
Contributor

This is admittedly a niche use case, they are the same most of the time, but on my computer for historical purposes I have users.users.default-user which has a different .name depending on whether Nix is building my work configuration or uni configuration (hence why it's default-user).

@nzbr nzbr added enhancement New feature or request hacktoberfest-accepted This labes is used to supply people with free t-shirts labels Oct 30, 2022
@nzbr
Copy link
Member

nzbr commented Oct 30, 2022

Looks good. Thank you!

@nzbr nzbr merged commit 27679db into nix-community:main Oct 30, 2022
@SuperSandro2000
Copy link
Member

SuperSandro2000 commented Oct 31, 2022

Before always including the wsl module worked but now it errors:

building the system configuration...
error: attribute 'nixos' missing

at /nix/store/pqfb6jic287q3d7s9jvz1w8lgrjnm3bi-source/modules/wsl-distro.nix:40:23:

39|         inherit (cfg) automountPath;
40|         defaultUser = config.users.users.${cfg.defaultUser};
|                       ^
41|       };

I expect that changing the name of the default user no longer works in some situations eg when it is only created by users.users below.

@KoviRobi
Copy link
Contributor Author

I guess you don't have a config.users.users.nixos? But

users.users.${cfg.defaultUser} = {
should get you that. I'll have to dig a bit deeper

@SuperSandro2000
Copy link
Member

Yes, I set wsl.defaultUser = "sandro". I think you cannot use the user done here in the same config section.

@KoviRobi
Copy link
Contributor Author

KoviRobi commented Oct 31, 2022

Hmm I've tried creating a simple test case at https://github.com/KoviRobi/nixos-wsl-test and the following works

nix build github:KoviRobi/nixos-wsl-test\#nixosConfigurations.wsl-test.config.system.build.toplevel

Also

nix-repl> :lf github:KoviRobi/nixos-wsl-test
Added 10 variables.

nix-repl> builtins.attrNames nixosConfigurations.wsl-test.config.users.users
[ "messagebus" "nixbld1" "nixbld10" "nixbld11" "nixbld12" "nixbld13" "nixbld14" "nixbld15" "nixbld16" "nixbld17" "nixbld18" "nixbld19" "nixbld2" "nixbld20" "nixbld21" "nixbld22" "nixbld23" "nixbld24" "nixbld25" "nixbld26" "nixbld27" "nixbld28" "nixbld29" "nixbld3" "nixbld30" "nixbld31" "nixbld32" "nixbld4" "nixbld5" "nixbld6" "nixbld7" "nixbld8" "nixbld9" "nobody" "nscd" "root" "systemd-coredump" "systemd-journal-gateway" "systemd-network" "systemd-oom" "systemd-resolve" "systemd-timesync" "test" ]

has no user nixos only test.

Maybe you can provide a minimal example?

@SuperSandro2000
Copy link
Member

Found the problem. Setting wsl.enable = false is still evaluating some WSL parts which want to access the created user https://github.com/nix-community/NixOS-WSL/blob/main/modules/wsl-distro.nix#L150-L184

@SuperSandro2000
Copy link
Member

#151

psvo added a commit to psvo/NixOS-WSL that referenced this pull request Nov 21, 2022
* upstream/main:
  Fix syschdemd exit code (nix-community#140)
  update remaining references to wsl.automountPath (nix-community#158)
  Update flakes (nix-community#124)
  wsl.conf: proper option types (nix-community#153)
  Fix eval by disabling module completely when wsl.enable = false (nix-community#151)
  NixOS users.users.<user> attribute name and .name can differ (nix-community#147)
  switch nixpkgs.overlays to inline overlay (nix-community#150)
  feat: native systemd support (nix-community#134)
  remove boot.isContainer (nix-community#145)
  Do not import minimal profile by default (nix-community#144)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest-accepted This labes is used to supply people with free t-shirts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants