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: standalone Home Manager configurations per host #54

Merged
merged 2 commits into from
Jan 22, 2025

Conversation

clo4
Copy link
Contributor

@clo4 clo4 commented Jan 12, 2025

Adds support for Home Manager configurations to Blueprint, both standalone and as a system configuration module.

Related to #36
Closes #35, closes #45

The idea is that Home Manager configurations are defined per-host, as opposed to per-user. This gives users the most flexibility: instead of being tied to a single configuration per username, users can choose to either define a totally unique configuration for a particular host, or use a module to define most of the common configuration and apply light changes on top of it.

The following import paths are supported:

  • hosts/{hostname}/users/{username}.nix
  • hosts/{hostname}/users/{username}/home-configuration.nix

NixOS or nix-darwin hosts

For hosts containing a system configuration, the Home Manager module and any users defined for that host will be automatically imported, along with setting useGlobalPkgs and useUserPkgs to true (default, can be overridden). This means, outside of very specific use cases, users will not need to change any home-manager options.

Standalone configurations

To support the home-manager CLI, the homeConfigurations attribute is defined per-system under legacyPackages. The packages attribute is intended to be a flat set of derivations, and the top-level homeConfigurations cannot be used since pkgs must already be instantiated (which requires a system) to be used as an argument to home-manager.lib.homeManagerConfiguration. This can be changed in the future if the home-manager CLI becomes deprecated or supports a different output name.

The home.homeDirectory and home.username options will be set automatically, as the username is defined in the path to the file and the homeDirectory can be inferred by the target system. Home Manager set these automatically prior to version 20.09, but this was removed to make evaluation pure.

This PR also allows hosts to not define a system configuration if the directory contains a users subdirectory.

@clo4 clo4 changed the title feat: add support for standalone Home Manager configurations feat: standalone Home Manager configurations per host Jan 12, 2025
@clo4 clo4 force-pushed the standalone-home-manager branch from 7c1216b to 27e7783 Compare January 12, 2025 08:56
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 the contrib, it seems to be going in the right direction overall

lib/default.nix Outdated Show resolved Hide resolved
lib/default.nix Outdated Show resolved Hide resolved
lib/default.nix Outdated Show resolved Hide resolved
@clo4 clo4 force-pushed the standalone-home-manager branch from 27e7783 to ea53670 Compare January 13, 2025 12:30
@clo4
Copy link
Contributor Author

clo4 commented Jan 13, 2025

Changed some stuff.

  • Users are now defined under the users subdirectory of a host.
    • TODO: don't fail if a home-configuration.nix doesn't exist, since people may be using this directory already as it's fairly logical
  • home-manager is automatically imported for a given host if it's an input and the host has any number of users defined
  • Standalone HM configurations automatically set the username
  • Commit has a description

@clo4 clo4 force-pushed the standalone-home-manager branch 4 times, most recently from 037b583 to af59222 Compare January 15, 2025 08:31
@clo4 clo4 marked this pull request as ready for review January 15, 2025 08:32
@clo4
Copy link
Contributor Author

clo4 commented Jan 15, 2025

Ready for review.

  • Automatically configuring home.homeDirectory was moved to its own commit because I wasn't certain about it, but it in practice feels good to not configure it since we already know the operating system and the username.
  • I put the docs in what I think is the most logical place, but please let me know if you'd rather shuffle it around somewhere else.
  • I'm extremely open to nitpicks! :p

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, this is great.

Last round of small feedback and then this is ready to be merged.

docs/folder-structure.md Show resolved Hide resolved
lib/default.nix Outdated Show resolved Hide resolved
@clo4 clo4 force-pushed the standalone-home-manager branch from af59222 to 9e83a90 Compare January 22, 2025 06:17
@clo4
Copy link
Contributor Author

clo4 commented Jan 22, 2025

Finally got power back! Had an outage that lasted a few days, then had quite a backlog of stuff to do outside of work. Ready for review round 2

PR description has also been fully updated with the current overview.

@clo4 clo4 force-pushed the standalone-home-manager branch 2 times, most recently from 6a65eae to 3ebea60 Compare January 22, 2025 14:46
clo4 added 2 commits January 23, 2025 01:53
This commit adds support for standalone Home Manager configurations
defined in a 'users' subdirectory of any host.

Defining Home Manager configurations per-host gives users the
flexibility to either write a fully custom config or delegate to a
shared module using the established 'modules/home' directory.

Configuration definitions can take two possible forms:
1. hosts/<hostname>/users/<username>.nix
2. hosts/<hostname>/users/<username>/home-configuration.nix

If the host defines a NixOS or nix-darwin configuration, and the input
'home-manager' exists, then the Home Manager module for that host will
be imported and all defined users will be added automatically.
Additionally, the extraSpecialArgs is modified to include 'flake',
'inputs', and 'perSystem'. An error is thrown if the 'home-manager'
input does not exist.

Standalone configurations also have the 'home.username' and
'home.homeDirectories' options set using 'lib.mkDefault'. This allows it
to be overridden by a user.

If a 'users' directory exists for a given host, that host directory no
longer needs to contain a host configuration file.
@clo4 clo4 force-pushed the standalone-home-manager branch from 3ebea60 to f251867 Compare January 22, 2025 14:53
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.

ok this looks good-enough to be merged.

Tests are missing, but we don't have any tests so it's unfair to ask for some.

In the future we might also want to address a top-level users/ folder that includes UID mapping. But that can be added later and will benefit from the practical experience of having that merged in.

@zimbatm zimbatm merged commit c1fd23c into numtide:main Jan 22, 2025
11 checks passed
@zimbatm
Copy link
Member

zimbatm commented Jan 22, 2025

thanks @clo4 !

@clo4
Copy link
Contributor Author

clo4 commented Jan 22, 2025

I did create some files to test these changes locally and I've been using it for my own configuration throughout the process, so I'm fully confident that it works as expected. I've never dealt with writing proper tests in Nix, so depending on how much time and energy I have over the coming days I might toy around with that. If anything good comes out of it I'll PR it too :)

@zimbatm
Copy link
Member

zimbatm commented Jan 23, 2025

Looking forward to it, testing is one of my main weakspots as a software engineer 😅

Maybe we could just have an ./examples folder with a bunch of sub-flakes in there. It could double as an integration test and a way to demonstrate the various ways to use blueprint.

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