Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@ let
in
lib.optional (builtins.hasAttr hostname homesNested) module;

homesGeneric =
let
getEntryPath =
_username: userEntry:
if builtins.pathExists (userEntry.path + "/home-configuration.nix") then
userEntry.path + "/home-configuration.nix"
else
# If we decide to add users/<username>.nix, it's as simple as
# testing `if userEntry.type == "regular"`
null;

mkUsers =
userEntries:
let
users = lib.mapAttrs getEntryPath userEntries;
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?

Copy link

Choose a reason for hiding this comment

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

Hey!
My 2cents to the _question: /homes/USERNAME seems better suited, as you both wrote (, because HM will pick up the output name).


# Attribute set mapping hostname (defined in hosts/) to a set of home
# configurations (modules) for that host. If a host has no home
# configuration, it will be omitted from the set. Likewise, if the user
Expand Down Expand Up @@ -258,13 +278,17 @@ let
eachSystem (
{ pkgs, ... }:
{
homeConfigurations = lib.mapAttrs (
_name: homeData:
mkHomeConfiguration {
inherit (homeData) modulePath username;
inherit pkgs;
}
) homesFlat;
homeConfigurations =
lib.mapAttrs (
_name: homeData:
mkHomeConfiguration {
inherit (homeData) modulePath username;
inherit pkgs;
}
) homesFlat
// lib.mapAttrs (
username: modulePath: mkHomeConfiguration { inherit pkgs username modulePath; }
) homesGeneric;
}
);

Expand Down Expand Up @@ -468,7 +492,7 @@ let
# nix3 CLI output (`packages` output expects flat attrset)
# FIXME: Find another way to make this work without introducing legacyPackages.
# May involve changing upstream home-manager.
legacyPackages = lib.optionalAttrs (homesNested != { }) standaloneHomeConfigurations;
legacyPackages = standaloneHomeConfigurations;
Copy link
Member

Choose a reason for hiding this comment

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

iiuc, we only introduce this to have nested attributes because the home-manager cli doesn't understand flattened ones? If that's correct I think it'd be preferable to drop this here before it sees too much use and prioritize an upstream fix. What do you think?

(I know it's already in main, i just hadn't seen it before and took the change as there's already this PR touching it ;))


darwinConfigurations = lib.mapAttrs (_: x: x.value) (hostsByCategory.darwinConfigurations or { });
nixosConfigurations = lib.mapAttrs (_: x: x.value) (hostsByCategory.nixosConfigurations or { });
Expand Down