ehllie / ez-configs

A flake-parts module for simple nixos, darwin and home-manager configurations using project directory structure
Mozilla Public License 2.0
59 stars 13 forks source link

Same username, different homeConfigurations #11

Open esselius opened 4 months ago

esselius commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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

krad246 commented 3 months ago

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

ehllie commented 3 months ago

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 commented 1 month ago

The PR solves this for me!