Users, use directory-driven users in flake.nix
This converts from the old manually defined users in flake.nix to a
dynamically defined users based on the directory structure. This is the
same as ba5fd48 but for users instead of hosts.
This commit is contained in:
parent
ba5fd48569
commit
0e5c6ab2c2
3 changed files with 30 additions and 13 deletions
43
flake.nix
43
flake.nix
|
|
@ -25,14 +25,18 @@
|
|||
./nixosModules
|
||||
] ++ extraModules;
|
||||
};
|
||||
hostFilter = { name, ...}: name == "host.nix";
|
||||
hostPaths = fs.toList (fs.fileFilter hostFilter ./hosts);
|
||||
|
||||
hosts = builtins.listToAttrs (map (path: {
|
||||
value = hostConfig [ path ];
|
||||
name = builtins.unsafeDiscardStringContext (st.removeSuffix "/host.nix" (
|
||||
builtins.elemAt (st.splitString "/hosts/" path) 1
|
||||
));
|
||||
hosts = let
|
||||
hostFilter = { name, ...}: name == "host.nix";
|
||||
hostPaths = fs.toList (fs.fileFilter hostFilter ./hosts);
|
||||
# Assumes dir structure is start_of_path/hosts/hostname/host.nix
|
||||
extractHostName = path: builtins.unsafeDiscardStringContext (
|
||||
st.removeSuffix "/host.nix" (
|
||||
builtins.elemAt (st.splitString "/hosts/" path) 1
|
||||
)
|
||||
);
|
||||
in builtins.listToAttrs (map (path: {
|
||||
value = path;
|
||||
name = extractHostName path;
|
||||
}) hostPaths);
|
||||
|
||||
userConfig = extraModules: home-manager.lib.homeManagerConfiguration {
|
||||
|
|
@ -42,11 +46,24 @@
|
|||
./hmModules
|
||||
] ++ extraModules;
|
||||
};
|
||||
|
||||
users = let
|
||||
userFilter = { name, ...}: name == "user.nix";
|
||||
userPaths = fs.toList (fs.fileFilter userFilter ./hosts);
|
||||
in builtins.listToAttrs (map (path: let
|
||||
dirsAndFiles = st.splitString "/" path;
|
||||
dAFLength = builtins.length dirsAndFiles;
|
||||
# Assumes dir structure is start_of_path/hosts/hostname/users/username/user.nix
|
||||
hostname = builtins.unsafeDiscardStringContext (
|
||||
builtins.elemAt dirsAndFiles (dAFLength - 4));
|
||||
username = builtins.unsafeDiscardStringContext (
|
||||
builtins.elemAt dirsAndFiles (dAFLength - 2));
|
||||
in {
|
||||
name = username + "@" + hostname;
|
||||
value = path;
|
||||
}
|
||||
) userPaths);
|
||||
in {
|
||||
nixosConfigurations = hosts;
|
||||
|
||||
homeConfigurations."pan@onizuka" = userConfig [ ./hosts/onizuka/users/pan ];
|
||||
homeConfigurations."pan@jibril" = userConfig [ ./hosts/jibril/users/pan ];
|
||||
nixosConfigurations = builtins.mapAttrs (name: path: hostConfig [ path ]) hosts;
|
||||
homeConfigurations = builtins.mapAttrs (name: path: userConfig [ path ]) users;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue