-
Notifications
You must be signed in to change notification settings - Fork 51
feat: add support for home-manager #468
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # Home Manager | ||
|
|
||
| This example demonstrates how to manage per-user dotfiles and packages with | ||
| [Home Manager](https://github.com/nix-community/home-manager) alongside a | ||
| System Manager configuration. | ||
| Declare both in the same flake and a single `system-manager switch` will | ||
| activate the system-level configuration and run Home Manager for each | ||
| configured user. | ||
| See the [Home Manager manual](https://nix-community.github.io/home-manager/) | ||
| for the full catalogue of options and programs Home Manager can manage. | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### flake.nix | ||
|
|
||
| ```nix | ||
| { | ||
| description = "System Manager with Home Manager"; | ||
|
|
||
| inputs = { | ||
| nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; | ||
| system-manager = { | ||
| url = "github:numtide/system-manager"; | ||
| inputs.nixpkgs.follows = "nixpkgs"; | ||
| }; | ||
| home-manager = { | ||
| url = "github:nix-community/home-manager"; | ||
| inputs.nixpkgs.follows = "nixpkgs"; | ||
| }; | ||
| }; | ||
|
|
||
| outputs = | ||
| { | ||
| self, | ||
| nixpkgs, | ||
| system-manager, | ||
| home-manager, | ||
| ... | ||
| }: | ||
| { | ||
| systemConfigs.default = system-manager.lib.makeSystemConfig { | ||
| modules = [ | ||
| home-manager.nixosModules.home-manager | ||
| ( | ||
| { pkgs, ... }: | ||
| { | ||
| nixpkgs.hostPlatform = "x86_64-linux"; | ||
|
|
||
| # Userborn creates the user on activation. | ||
| services.userborn.enable = true; | ||
|
|
||
| # Required so home-manager can invoke nix-store/nix-build | ||
| # during activation. | ||
| nix.enable = true; | ||
|
|
||
| users.groups.alice.gid = 5000; | ||
| users.users.alice = { | ||
| isNormalUser = true; | ||
| uid = 5000; | ||
| group = "alice"; | ||
| home = "/home/alice"; | ||
| createHome = true; | ||
| }; | ||
|
|
||
| home-manager = { | ||
| # Share the system's pkgs (and nixpkgs config) with Home Manager. | ||
| useGlobalPkgs = true; | ||
| # Install per-user packages into /etc/profiles/per-user/<name>. | ||
| useUserPackages = true; | ||
| # Back up any pre-existing dotfiles home-manager would overwrite. | ||
| backupFileExtension = "bak"; | ||
|
|
||
| users.alice = | ||
| { pkgs, ... }: | ||
| { | ||
| home.stateVersion = "24.05"; | ||
|
|
||
| home.packages = [ pkgs.ripgrep ]; | ||
|
|
||
| home.file.".config/example/hello.txt".text = '' | ||
| Hello from home-manager! | ||
| ''; | ||
|
|
||
| programs.git = { | ||
| enable = true; | ||
| userName = "Alice"; | ||
| userEmail = "alice@example.com"; | ||
| }; | ||
| }; | ||
| }; | ||
| } | ||
| ) | ||
| ]; | ||
| }; | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| # Activate system-manager; home-manager runs per user during activation. | ||
| nix run 'github:numtide/system-manager' -- switch --flake /path/to/this/example --sudo | ||
| ``` | ||
|
|
||
| The per-user systemd unit `home-manager-<username>.service` runs once per | ||
| activation. | ||
| Check its status with: | ||
|
|
||
| ```bash | ||
| systemctl status home-manager-alice.service | ||
| ``` | ||
|
|
||
| The activated dotfiles and generation symlinks live under | ||
| `/home/alice/.config/` and `/home/alice/.local/state/nix/profiles/`. | ||
|
|
||
| ## Notes | ||
|
|
||
| - Users referenced in `home-manager.users.<name>` must also exist in | ||
| `users.users.<name>`; Home Manager reads `home` and the resolved username | ||
| from the system's user database. | ||
| - `useGlobalPkgs = true` disables Home Manager's own `nixpkgs.*` options and | ||
| reuses the instance from System Manager. | ||
| - `useUserPackages = true` makes `home.packages` available on the user's | ||
| login shell via `/etc/profiles/per-user/<username>/bin`. | ||
| - Home Manager activation requires a working Nix setup on the host | ||
| (`nix.enable = true` or an equivalent multi-user Nix install). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Test integration of the home-manager NixOS module with system-manager. | ||
| { | ||
| forEachDistro, | ||
| home-manager, | ||
| ... | ||
| }: | ||
|
|
||
| forEachDistro "home-manager" { | ||
| modules = [ | ||
| home-manager.nixosModules.home-manager | ||
| ( | ||
| { pkgs, ... }: | ||
| { | ||
| nix.enable = true; | ||
| services.userborn.enable = true; | ||
|
|
||
| users.groups.hmuser.gid = 5000; | ||
|
|
||
| users.users.hmuser = { | ||
| isNormalUser = true; | ||
| uid = 5000; | ||
| group = "hmuser"; | ||
| home = "/home/hmuser"; | ||
| createHome = true; | ||
| initialPassword = "hmuser"; | ||
| }; | ||
|
|
||
| home-manager = { | ||
| useGlobalPkgs = true; | ||
| useUserPackages = true; | ||
| backupFileExtension = "bak"; | ||
| users.hmuser = | ||
| { pkgs, ... }: | ||
| { | ||
| home.stateVersion = "24.05"; | ||
| home.file.".config/system-manager-test/hello.txt".text = "hello from home-manager"; | ||
| home.packages = [ pkgs.hello ]; | ||
| }; | ||
| }; | ||
| } | ||
| ) | ||
| ]; | ||
| testScriptFunction = | ||
| { toplevel, ... }: | ||
| '' | ||
| start_all() | ||
|
|
||
| machine.wait_for_unit("multi-user.target") | ||
|
|
||
| activation_logs = machine.activate() | ||
| for line in activation_logs.split("\n"): | ||
| assert not "ERROR" in line, line | ||
| machine.wait_for_unit("system-manager.target") | ||
|
|
||
| with subtest("home-manager per-user service is present"): | ||
| machine.wait_for_unit("home-manager-hmuser.service") | ||
| status = machine.succeed("systemctl is-active home-manager-hmuser.service").strip() | ||
| assert status == "active", f"Expected home-manager-hmuser.service active, got {status!r}" | ||
|
|
||
| with subtest("home-manager activated the managed file"): | ||
| content = machine.succeed("cat /home/hmuser/.config/system-manager-test/hello.txt").strip() | ||
| assert content == "hello from home-manager", f"Unexpected file content: {content!r}" | ||
|
|
||
| with subtest("home-manager user package is on the user's PATH"): | ||
| resolved = machine.succeed( | ||
| "runuser -u hmuser -- bash -lc 'command -v hello'" | ||
| ).strip() | ||
| assert "/etc/profiles/per-user/hmuser/bin/hello" == resolved, ( | ||
| f"Expected hello from per-user profile, got: {resolved!r}" | ||
| ) | ||
| ''; | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.