2024-01-23 11:51:13 -06:00
|
|
|
{
|
|
|
|
inputs,
|
|
|
|
nixpkgs,
|
|
|
|
...
|
|
|
|
}: let
|
2024-01-24 14:12:52 -06:00
|
|
|
inherit (builtins) concatLists attrValues mapAttrs elemAt match readDir filter listToAttrs baseNameOf readFile;
|
|
|
|
inherit (nixpkgs.lib) hasSuffix nixosSystem genAttrs;
|
2024-01-23 11:51:13 -06:00
|
|
|
inherit (nixpkgs.lib.filesystem) listFilesRecursive;
|
2024-01-24 14:12:52 -06:00
|
|
|
|
|
|
|
# https://xeiaso.net/blog/nix-flakes-1-2022-02-21/
|
|
|
|
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
|
|
|
|
forAllSystems = genAttrs supportedSystems;
|
|
|
|
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
|
2024-01-23 11:51:13 -06:00
|
|
|
in rec {
|
2024-01-24 14:12:52 -06:00
|
|
|
shToPkg = path:
|
|
|
|
forAllSystems (
|
|
|
|
system: let
|
|
|
|
name = baseNameOf path;
|
|
|
|
pkgs = nixpkgsFor.${system};
|
|
|
|
in {
|
|
|
|
${name} = pkgs.writeScriptBin name (readFile path);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-01-23 12:50:40 -06:00
|
|
|
isNixFile = path: hasSuffix ".nix" path;
|
|
|
|
|
2024-01-23 11:51:13 -06:00
|
|
|
mkSystem = hostname:
|
|
|
|
nixosSystem {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
modules =
|
2024-01-23 19:13:42 -06:00
|
|
|
[../modules/roles/common.nix]
|
2024-01-24 14:12:52 -06:00
|
|
|
++ filter isNixFile (listFilesRecursive (../. + "/hosts/${hostname}"));
|
2024-01-23 11:51:13 -06:00
|
|
|
specialArgs = {inherit inputs;};
|
|
|
|
};
|
|
|
|
|
|
|
|
mapHosts = dir:
|
|
|
|
mapAttrs
|
|
|
|
(name: _: mkSystem name)
|
|
|
|
(readDir dir);
|
|
|
|
|
2024-01-24 14:12:52 -06:00
|
|
|
findModules = modulesPath: listToAttrs (findModulesList modulesPath);
|
2024-01-23 11:51:13 -06:00
|
|
|
# https://github.com/balsoft/nixos-config/blob/73cc2c3a8bb62a9c3980a16ae70b2e97af6e1abd/flake.nix#L109-L120
|
2024-01-24 14:12:52 -06:00
|
|
|
findModulesList = dir:
|
2024-01-23 11:51:13 -06:00
|
|
|
concatLists (attrValues (mapAttrs
|
|
|
|
(name: type:
|
|
|
|
if type == "regular"
|
|
|
|
then [
|
|
|
|
{
|
|
|
|
name = elemAt (match "(.*)\\.nix" name) 0;
|
|
|
|
value = dir + "/${name}";
|
|
|
|
}
|
|
|
|
]
|
|
|
|
else if
|
|
|
|
(readDir (dir + "/${name}"))
|
|
|
|
? "default.nix"
|
|
|
|
then [
|
|
|
|
{
|
|
|
|
inherit name;
|
|
|
|
value = dir + "/${name}";
|
|
|
|
}
|
|
|
|
]
|
2024-01-24 14:12:52 -06:00
|
|
|
else findModulesList (dir + "/${name}")) (readDir dir)));
|
2024-01-23 11:51:13 -06:00
|
|
|
}
|