oizys/lib/default.nix

80 lines
2.1 KiB
Nix
Raw Normal View History

2024-01-23 11:51:13 -06:00
{
inputs,
self,
2024-01-23 11:51:13 -06:00
}: let
2024-02-23 15:53:46 -06:00
inherit (inputs) nixpkgs;
2024-01-29 10:46:56 -06:00
inherit (builtins) concatLists attrValues mapAttrs elemAt match readDir filter listToAttrs;
2024-01-24 14:12:52 -06:00
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
2024-02-22 11:57:41 -06:00
#supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
supportedSystems = ["x86_64-linux" ];
2024-01-28 23:19:30 -06:00
runes = import ../modules/runes;
2024-01-23 11:51:13 -06:00
in rec {
2024-02-07 10:49:03 -06:00
forAllSystems = f: genAttrs supportedSystems (system: f nixpkgs.legacyPackages.${system});
2024-01-28 23:31:00 -06:00
mkRune = {
rune,
2024-02-07 10:49:03 -06:00
number ? "6",
2024-01-28 23:31:00 -06:00
runeKind ? "braille",
}:
2024-02-08 12:43:28 -06:00
"[1;3${number}m\n" + runes.${rune}.${runeKind} + "\n";
2024-01-25 13:59:33 -06:00
2024-02-07 10:49:03 -06:00
isNixFile = path: hasSuffix ".nix" path;
2024-01-28 11:00:05 -06:00
buildOizys = _:
2024-01-24 14:12:52 -06:00
forAllSystems (
2024-01-25 10:59:03 -06:00
pkgs: let
2024-01-28 11:00:05 -06:00
pkg = pkgs.callPackage ../oizys {};
2024-01-26 13:09:15 -06:00
in {
2024-01-28 11:00:05 -06:00
oizys = pkg;
2024-01-26 13:09:15 -06:00
default = pkg;
}
2024-01-24 14:12:52 -06:00
);
2024-01-23 11:51:13 -06:00
mkSystem = hostname:
nixosSystem {
system = "x86_64-linux";
2024-02-15 12:01:08 -06:00
modules =
[
2024-02-15 10:57:13 -06:00
../modules/common.nix
2024-02-15 12:01:08 -06:00
../overlays
2024-02-15 10:57:13 -06:00
]
2024-02-15 12:01:08 -06:00
++ filter
isNixFile
(listFilesRecursive (../. + "/hosts/${hostname}"));
2024-02-15 10:57:13 -06:00
specialArgs = {inherit inputs mkRune self;};
2024-01-23 11:51:13 -06:00
};
2024-02-07 10:49:03 -06:00
mapHosts = dir: mapAttrs (name: _: mkSystem name) (readDir dir);
2024-02-06 09:51:21 -06:00
buildHosts = _: mapHosts ../hosts;
2024-02-19 12:24:03 -06:00
findModules = _: listToAttrs (findModulesList ../modules);
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-02-21 14:36:33 -06:00
oizysFlake = _: {
nixosModules = findModules {};
nixosConfigurations = buildHosts {};
packages = buildOizys {};
formatter = forAllSystems (pkgs: pkgs.alejandra);
};
2024-01-23 11:51:13 -06:00
}