1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2025-03-06 00:46:50 +00:00
flake-parts/modules/perSystem.nix

54 lines
1.7 KiB
Nix
Raw Normal View History

2022-05-13 10:14:10 +02:00
{ config, lib, flake-modules-core-lib, self, ... }:
2021-10-27 11:05:52 +02:00
let
inherit (lib)
genAttrs
2021-10-27 11:05:52 +02:00
mapAttrs
mkOption
types
;
2022-05-13 10:14:10 +02:00
inherit (flake-modules-core-lib)
mkPerSystemType
;
2021-10-27 11:05:52 +02:00
rootConfig = config;
in
{
options = {
systems = mkOption {
description = "All the system types to enumerate in the flake.";
type = types.listOf types.str;
};
perInput = mkOption {
description = "Function from system to function from flake to <literal>system</literal>-specific attributes.";
2021-10-27 11:05:52 +02:00
type = types.functionTo (types.functionTo (types.lazyAttrsOf types.unspecified));
};
perSystem = mkOption {
2022-05-13 10:14:10 +02:00
description = "A function from system to flake-like attributes omitting the <literal>&lt;system></literal> attribute.";
type = mkPerSystemType ({ config, system, ... }: {
_file = ./perSystem.nix;
config = {
_module.args.inputs' = mapAttrs (k: rootConfig.perInput system) self.inputs;
_module.args.self' = rootConfig.perInput system self;
};
2021-10-27 11:05:52 +02:00
});
};
allSystems = mkOption {
type = types.lazyAttrsOf types.unspecified;
description = "The system-specific config for each of systems.";
internal = true;
};
};
config = {
perSystem = system: { _module.args.system = system; };
allSystems = genAttrs config.systems config.perSystem;
# TODO: Sub-optimal error message. Get Nix to support a memoization primop, or get Nix Flakes to support systems properly or get Nix Flakes to add a name to flakes.
2022-04-06 18:01:26 +02:00
_module.args.getSystem = system: config.allSystems.${system} or (builtins.trace "using non-memoized system ${system}" config.perSystem system);
2021-10-27 11:05:52 +02:00
};
}