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

feat: home configurations without hostname #77

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

clo4
Copy link
Contributor

@clo4 clo4 commented Feb 17, 2025

This PR will be marked as draft until there's consensus on what the right design is and a solid implementation for it. This PR only exists since I needed a place to put the to-do list, and since the feature probably be merged in some form eventually :)

This might not be the final form this takes, so I'm not going to describe it in detail in the PR. The commit descriptions will be up to date.

To-do:

  • Improve let-binding naming
  • Verify generic home configs will warn users without a home-manager input
  • Add test cases

See #74 for design considerations

Blueprint now supports defining user configurations in the top-level
'users' directory, and makes this a first-class way to share user
configurations without exposing them in the public interface of the
flake.

Users are created in 'users/<username>/home-configuration.nix' (though
this is easy to change in the future).

Existing home configurations can access all the generic configurations
through the new 'users' argument. For example, a user defined at
'users/baz/home-configuration.nix' could be imported and used as a base
by 'hosts/foobar/users/baz.nix' (`imports = [ users.baz ];`) OR as a
standalone configuration without a hostname.

Editorial: new users should still be encouraged to start creating their
configuration per-machine to reduce the complexity of their config, and
only move to a shared config when they _need_ to share it between
multiple devices.
@clo4
Copy link
Contributor Author

clo4 commented Feb 19, 2025

Reviewers, how do you feel about the design? This PR exposes a users attrset to home modules. Do you think that's necessary or should users keep using homeModules for shared configuration?

My thinking here is that the users folder should be used for shared home configuration that isn't exposed as part of the flake's public interface.

Copy link
Member

@zimbatm zimbatm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for taking ownership of the home-manager part @clo4

in
lib.filterAttrs (_name: value: value != null) users;
in
importDir (src + "/users") mkUsers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if /homes would map more naturally for the end-users. It would also allow users to have multiple home configurations (eg: homes/terminal and homes/desktop).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to this. users is analogous to hosts/*/users so it was an obvious first choice, but it also makes sense because HM will pick the output name based on $USER. @jzbor since you'll be using this yourself, do you have any input?

@@ -128,6 +128,10 @@ let
self = throw "self was renamed to flake";
};

hmSpecialArgs = specialArgs // {
users = homesGeneric;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give an example of how this would be used?

Copy link

@JumpIn-Git JumpIn-Git Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/hosts/foo/users/foo.nix

{users,...}:
{
  imports = [
    users.foo
  ];
  home.packages = [
    pkgs.hello
  ];
}

now the home-config foo@foo is the same as foo but with pkgs.hello installed

Copy link
Contributor Author

@clo4 clo4 Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concretely,
Screenshot 2025-02-20 at 9 29 55 am

(source)

It's just as easy to add "${flake}/users/robert/home-configuration.nix" to my imports, which is what I was doing before, so I don't have any strong feeling on whether this should be kept or not. I may actually lean towards get rid of it.

@JumpIn-Git
Copy link

by the way, i dont know if you have added this, but if users.foo for example gets imported in /hosts/foo/users/bar.nix the home.homeDirectory might be set to /home/foo but it should be /home/bar

@clo4
Copy link
Contributor Author

clo4 commented Feb 19, 2025

@JumpIn-Git HM handles this already based on the home-manager.users attrset :)

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 this pull request may close these issues.

3 participants