oizys/lib/default.nix

64 lines
1.7 KiB
Nix
Raw Normal View History

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
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
2024-01-23 11:51:13 -06:00
in rec {
2024-01-25 13:59:33 -06:00
forAllSystems = f: genAttrs supportedSystems (system: f nixpkgs.legacyPackages.${system});
2024-01-26 12:00:05 -06:00
buildStyx = _:
2024-01-24 14:12:52 -06:00
forAllSystems (
2024-01-25 10:59:03 -06:00
pkgs: let
2024-01-26 12:00:05 -06:00
name = baseNameOf ../styx;
2024-01-26 13:09:15 -06:00
pkg = pkgs.writeScriptBin name (readFile ../styx/styx.sh);
in {
${name} = pkg;
default = pkg;
}
2024-01-24 14:12:52 -06:00
);
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
}