1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00

nixos-module: Fix potential recursion between users.users and home-manager.users (#6622)

Pushing users.users.<name>.packages from matching home-manager users leads to a circular dependency when
one attribute set is calculated from the other.
A configuration pull approach replaces the previous one to break up the circular dependency. This new approach
allows more flexibility in configuring both option sets, including calculating from each other.

EXAMPLE;

```nix
{lib, /* custom arg */ flake, config, ...}: {
    home-manager.useUserPackages = true;
    home-manager.users = builtins.intersectAttrs (lib.filterAttrs (_: v: v.isNormalUser) config.users.users) (flake.outputs.homeModules.users);
}
```

EXAMPLE;
```nix
{lib, /* custom arg */ flake, config, ...}: {
    home-manager.useUserPackages = true;
    home-manager.users = { inherit (flake.outputs.homeModules.users) demo-user; };
    users.users = lib.mapAttrs (_: _: { isNormalUser = true; }) (lib.filterAttrs (_: v: v.programs.git.enable) config.home-manager.users);
}
```

fixes #594

* options-manual: Remove `users` option set from documentation

The option declaration `users.users` is owned by the upstream
nixos modules and should not be documented by home-manager.

Home-manager declares an incomplete/partial option definition for
`users.users` that cannot be documented without the full definition from
the nixos modules. This partial definition is removed from the options
set while generating documentation for the home-manager nixos module.
This commit is contained in:
Proesmans Bert 2025-03-31 16:19:52 +02:00 committed by GitHub
parent b6fd653ef8
commit 216690777e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 9 deletions

View file

@ -50,6 +50,13 @@ let
};
in {
options.users.users = mkOption {
type = types.attrsOf (types.submodule ({ name, config, ... }: {
config.packages = mkIf ((config.enable or true) && cfg.useUserPackages
&& lib.hasAttr name cfg.users) [ cfg.users.${name}.home.path ];
}));
};
options.home-manager = {
useUserPackages = mkEnableOption ''
installation of user packages through the
@ -104,10 +111,7 @@ in {
};
config = (lib.mkMerge [
# Fix potential recursion when configuring home-manager users based on values in users.users #594
(mkIf (cfg.useUserPackages && cfg.users != { }) {
users.users = (lib.mapAttrs
(_username: usercfg: { packages = [ usercfg.home.path ]; }) cfg.users);
environment.pathsToLink = [ "/etc/profile.d" ];
})
(mkIf (cfg.users != { }) {