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
|
./nixosModules
|
||||||
] ++ extraModules;
|
] ++ extraModules;
|
||||||
};
|
};
|
||||||
hostFilter = { name, ...}: name == "host.nix";
|
hosts = let
|
||||||
hostPaths = fs.toList (fs.fileFilter hostFilter ./hosts);
|
hostFilter = { name, ...}: name == "host.nix";
|
||||||
|
hostPaths = fs.toList (fs.fileFilter hostFilter ./hosts);
|
||||||
hosts = builtins.listToAttrs (map (path: {
|
# Assumes dir structure is start_of_path/hosts/hostname/host.nix
|
||||||
value = hostConfig [ path ];
|
extractHostName = path: builtins.unsafeDiscardStringContext (
|
||||||
name = builtins.unsafeDiscardStringContext (st.removeSuffix "/host.nix" (
|
st.removeSuffix "/host.nix" (
|
||||||
builtins.elemAt (st.splitString "/hosts/" path) 1
|
builtins.elemAt (st.splitString "/hosts/" path) 1
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
in builtins.listToAttrs (map (path: {
|
||||||
|
value = path;
|
||||||
|
name = extractHostName path;
|
||||||
}) hostPaths);
|
}) hostPaths);
|
||||||
|
|
||||||
userConfig = extraModules: home-manager.lib.homeManagerConfiguration {
|
userConfig = extraModules: home-manager.lib.homeManagerConfiguration {
|
||||||
|
|
@ -42,11 +46,24 @@
|
||||||
./hmModules
|
./hmModules
|
||||||
] ++ extraModules;
|
] ++ 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 {
|
in {
|
||||||
nixosConfigurations = hosts;
|
nixosConfigurations = builtins.mapAttrs (name: path: hostConfig [ path ]) hosts;
|
||||||
|
homeConfigurations = builtins.mapAttrs (name: path: userConfig [ path ]) users;
|
||||||
homeConfigurations."pan@onizuka" = userConfig [ ./hosts/onizuka/users/pan ];
|
|
||||||
homeConfigurations."pan@jibril" = userConfig [ ./hosts/jibril/users/pan ];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue