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

Same username, different homeConfigurations #11

Open
esselius opened this issue Jul 19, 2024 · 5 comments · May be fixed by #12
Open

Same username, different homeConfigurations #11

esselius opened this issue Jul 19, 2024 · 5 comments · May be fixed by #12

Comments

@esselius
Copy link
Contributor

I use the same username on my home and work computers, but need to apply different home-manager config based on environment.

Got any tips for how to do this?

@ehllie
Copy link
Owner

ehllie commented Jul 30, 2024

You don't need to have the same home.username as the name of the nix file it's inside of. You can have home-configurations/user-minimal.nix and home-configurations/user-full.nix and have them both have a home.username = "user";. I might need to make changes to make that work if you're using nixos-module version of home-manager

@esselius
Copy link
Contributor Author

esselius commented Aug 4, 2024

I'm using ezConfigs.nixos.hosts.adama.userHomeModules = [ "username" ]; yes :)

@krad246
Copy link

krad246 commented Aug 13, 2024

Is there a resolution to this? I am also interested in the same problem.

@ehllie
Copy link
Owner

ehllie commented Aug 16, 2024

I've created a PR that should be able fix this issue, but when finishing it, I noticed a simpler solution. Or rather a solution that would not require extra maintenance on my part. The value of users.users.<user-config-name>.name need not be the same as users-config-name. If all that you need to do is have the same username, but use different configs, can't you write a nixos module like this:

users.users.my-minimal-config.name = "my-username";

and inside homeConfigurations/my-minimal-config.nix

{ pkgs, osConfig, ... }:
let users = osConfig.users.users;
in
{
  home = rec {
    username =
      if (users ? my-minimal-config) then
        users.my-minimal-config.name else
        "my-username";
    homeDirectory =
      if (users ? my-minimal-config) then
        users.my-minimal-config.home else
        (
          if pkgs.stdenv.isDarwin then
            "/Users/${username}" else
            "/home/${username}"
        );
  };
}

Would that solve your issue, or is the PR I made still necessary? I've always had my users-config-name be the same as the value of the name attribute, but I assume nixos lets you override that for a reason, and uses the value of name for everything that happens at the configuration "runtime".

@reedrw
Copy link

reedrw commented Oct 9, 2024

The PR solves this for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants