diff options
| author | Seth Flynn <[email protected]> | 2025-02-10 15:58:39 -0500 |
|---|---|---|
| committer | Seth Flynn <[email protected]> | 2025-02-10 20:26:23 -0500 |
| commit | dd618800566a51365411683f9a4c789923cdc874 (patch) | |
| tree | 88aa89284542c265a564a81a3e7bdffc7ac27916 /lib/default.nix | |
| parent | cd21ca8e9894f7d8dbe7628952c6345174c3eb15 (diff) | |
flake: use checks for CI
Diffstat (limited to 'lib/default.nix')
| -rw-r--r-- | lib/default.nix | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..0d36185 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,80 @@ +{ config, lib, ... }: + +let + self = config.flake.lib; +in + +{ + + flake.lib = { + /** + Get the derivation attribute of a configuration if needed + + # Type + + ``` + derivationFrom :: AttrSet -> Derivation + ``` + + # Arguments + + - [set] A system/home configuration or regular derivation + */ + derivationFrom = + deriv: + if lib.isDerivation deriv then + deriv + else + deriv.config.system.build.toplevel or deriv.activationPackage; + + /** + Check if a derivation or configuration is compatible with the current system + + # Type + + ``` + isCompatible :: String -> Derivation -> Bool + ``` + + # Arguments + + - [system] System to check against + - [derivation] Derivation to check + */ + isCompatibleWith = system: deriv: (deriv.pkgs or deriv).stdenv.hostPlatform.system == system; + + /** + Flatten nested derivations from an attribute set + + Mainly for use with making Flake outputs work in `checks` + + # Example + + ```nix + collectNestedDerivations { nixosConfigurations = { my-machine = { }; }; } + => { nixosConfigurations-my-machine = { }; } + + # Type + + ``` + collectNestedDerivations :: String -> AttrSet -> AttrSet + ``` + + # Arguments + + - [system] System to collect derivations for + - [set] Set of (single-level) nested derivations + */ + collectNestedDerivationsFor = + system: + + lib.foldlAttrs ( + acc: attrType: values: + + acc + // lib.mapAttrs' ( + attrName: value: lib.nameValuePair "${attrType}-${attrName}" (self.derivationFrom value) + ) (lib.filterAttrs (lib.const (self.isCompatibleWith system)) values) + ) { }; + }; +} |
