summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorseth <[email protected]>2023-05-22 02:35:15 -0400
committerseth <[email protected]>2023-05-23 11:05:28 -0400
commit630934a2631d9429b4e46c1b6ec0f6640f332384 (patch)
treed8bd14cafb0ac382625bc5dca79b84d497e9bab7 /lib
parent2cb6cfab9553184c1e6a10303cb832fe96080d00 (diff)
!hercules-ci -> hydra
Diffstat (limited to 'lib')
-rw-r--r--lib/ci.nix70
-rw-r--r--lib/configs.nix37
-rw-r--r--lib/default.nix18
3 files changed, 125 insertions, 0 deletions
diff --git a/lib/ci.nix b/lib/ci.nix
new file mode 100644
index 0000000..36185f6
--- /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 hydra
+ 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
new file mode 100644
index 0000000..8da37bc
--- /dev/null
+++ b/lib/configs.nix
@@ -0,0 +1,37 @@
+inputs: {
+ mkNixOS = {
+ name,
+ profile,
+ modules ? profile.modules,
+ system ? profile.system,
+ specialArgs ? profile.specialArgs,
+ }:
+ profile.builder {
+ inherit specialArgs system;
+ modules =
+ [../hosts/${name}]
+ ++ (
+ if modules == profile.modules
+ then modules
+ else modules ++ profile.modules
+ );
+ };
+
+ mkHMUser = {
+ name,
+ modules ? [],
+ pkgs ? import inputs.nixpkgs {system = "x86_64-linux";},
+ extraSpecialArgs ? inputs,
+ }:
+ inputs.home-manager.lib.homeManagerConfiguration {
+ inherit pkgs extraSpecialArgs;
+ modules =
+ [
+ {
+ programs.home-manager.enable = true;
+ }
+ ]
+ ++ [../users/${name}/home.nix]
+ ++ modules;
+ };
+}
diff --git a/lib/default.nix b/lib/default.nix
new file mode 100644
index 0000000..67a102e
--- /dev/null
+++ b/lib/default.nix
@@ -0,0 +1,18 @@
+{
+ lib,
+ inputs,
+}: let
+ configs = import ./configs.nix inputs;
+in
+ lib.extend (_: _: {
+ my = {
+ inherit (configs) mkHMUser mkNixOS;
+
+ ci = import ./ci.nix lib;
+
+ mkFlakeFns = systems: nixpkgs: rec {
+ forAllSystems = lib.genAttrs systems;
+ nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
+ };
+ };
+ })