diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ci.nix | 70 | ||||
| -rw-r--r-- | lib/configs.nix | 90 | ||||
| -rw-r--r-- | lib/default.nix | 15 |
3 files changed, 97 insertions, 78 deletions
diff --git a/lib/ci.nix b/lib/ci.nix new file mode 100644 index 0000000..1911a11 --- /dev/null +++ b/lib/ci.nix @@ -0,0 +1,70 @@ +lib: supportedSystems: let + inherit (builtins) attrNames baseNameOf elem getContext head mapAttrs seq stringLength substring; + inherit (lib) filterAttrs; + check = string: elem string supportedSystems; +in rec { + # filters systems in basic flake output + # ex: + # + # packages = { + # x86_64-linux = {}; + # aarch64-linux = {}; + # x86_64-darwin = {}; + # aarch64-darwin = {}; + # }; + # mkCompatible packages -> { x86_64-linux = {}; aarch64-linux = {}; } + mkCompatible = filterAttrs (system: _: check system); + + # mkCompatible but for apps, since their attribute + # also needs to be editied in order to be picked up + # by some ci systems + mkCompatibleApps = apps: + mkCompatible (mapAttrs ( + _: + mapAttrs (_: v: { + program = let + ctx = getContext v.program; + drvPath = head (attrNames ctx); + basename = baseNameOf drvPath; + hashLength = 33; + l = stringLength basename; + in { + name = substring hashLength (l - hashLength - 4) basename; + type = "derivation"; + inherit drvPath; + }; + }) + ) + apps); + + # mkCompatible but for formatters + mkCompatibleFormatters = filterAttrs (system: fmt: check system && elem system (fmt.meta.platforms or [])); + + # mkComaptible, but maps nixosConfigurations + # to their toplevel build attribute so they can + # be picked up by hydra + mkCompatibleCfg = configs: + filterAttrs (_: config: check config.system) + (mapAttrs (_: v: v.config.system.build.toplevel) configs); + + # mkCompatibleCfg, but the toplevel build attribute + # is only evaluated + mkCompatibleCfg' = configs: + filterAttrs (_: config: check config.system) + (mapAttrs (_: v: + seq + v.config.system.build.toplevel + v._module.args.pkgs.emptyFile) + configs); + + # mkCompatible, but maps homeConfigurations + # to their activationPackage so they can be + # picked up by hydra + mkCompatibleHM = configs: + filterAttrs (system: _: check system) + (mapAttrs (_: mapAttrs (_: deriv: deriv.activationPackage or {})) configs); + + # mkCompatible, but for packages + # meta.platforms is also checked to ensure compatibility + mkCompatiblePkgs = mapAttrs (system: filterAttrs (_: deriv: elem system (deriv.meta.platforms or []))); +} diff --git a/lib/configs.nix b/lib/configs.nix index d7460ac..9b20897 100644 --- a/lib/configs.nix +++ b/lib/configs.nix @@ -1,81 +1,37 @@ -# this is mainly for my host/hm configurations -{ - lib, - inputs, -}: let - inherit (builtins) mapAttrs readDir; - inherit (lib) filterAttrs hasPrefix; -in rec { - mapFilterDir = dir: filter: map: let - dirs = filterAttrs filter (readDir dir); - in - mapAttrs map dirs; - - mapModules = dir: let - check = n: v: v == "directory" && !(hasPrefix "_" n); - in - mapFilterDir dir check; +inputs: { + mkNixOS = { + name, + profile, + modules ? profile.modules, + system ? profile.system, + specialArgs ? profile.specialArgs, + }: + profile.builder { + inherit specialArgs system; + modules = + ["${inputs.self}/hosts/${name}"] + ++ ( + if modules == profile.modules + then modules + else modules ++ profile.modules + ); + }; mkHMUser = { - username, - pkgs, + name, modules ? [], - extraSpecialArgs ? {}, - inputs, - dir, + pkgs ? import inputs.nixpkgs {system = "x86_64-linux";}, + extraSpecialArgs ? inputs, }: inputs.home-manager.lib.homeManagerConfiguration { - inherit pkgs; - extraSpecialArgs = inputs // extraSpecialArgs; + inherit pkgs extraSpecialArgs; modules = [ - "${dir}/${username}/home.nix" - { programs.home-manager.enable = true; } ] + ++ ["${inputs.self}/users/${name}/home.nix"] ++ modules; }; - - mapHMUsers = system: dir: let - users = import dir system inputs; - in - mapModules dir ( - username: _: - mkHMUser ({ - inherit username inputs dir; - inherit (users.${username}) extraSpecialArgs modules pkgs; - } - // users.${username}) - ); - - mkHost = { - name, - modules ? [], - specialArgs ? {}, - system ? "x86_64-linux", - inputs ? {}, - builder, - dir, - }: - builder { - inherit system; - specialArgs = inputs // specialArgs; - modules = - [ - "${dir}/${name}" - ] - ++ modules; - }; - - mapHosts = dir: let - hosts = import "${dir}" inputs; - in - mapModules dir (name: _: - mkHost ({ - inherit name dir inputs; - inherit (hosts.${name}) builder system; - } - // hosts.${name})); } diff --git a/lib/default.nix b/lib/default.nix index 4682b2f..ccdb0bf 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,11 +1,4 @@ -lib: inputs: let - inherit (lib) forEach genAttrs removeSuffix; - files = let - inherit (builtins) attrNames readDir; - inherit (lib) filterAttrs hasSuffix; - check = n: v: n != "default.nix" && hasSuffix ".nix" n && v == "regular"; - dir = readDir ./.; - in - attrNames (filterAttrs check dir); -in - genAttrs (forEach files (removeSuffix ".nix")) (f: (import ./${f + ".nix"} {inherit lib inputs;})) +lib: {inputs, ...}: { + ci = import ./ci.nix lib; + configs = import ./configs.nix inputs; +} |
