1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2025-03-05 08:27:02 +00:00
flake-parts/modules/packages.nix

58 lines
1.4 KiB
Nix
Raw Normal View History

2022-05-25 16:36:33 +02:00
{ config, lib, flake-parts-lib, ... }:
2021-10-27 11:05:52 +02:00
let
inherit (lib)
filterAttrs
mapAttrs
mkOption
optionalAttrs
types
;
2022-05-25 16:36:33 +02:00
inherit (flake-parts-lib)
2021-11-21 15:47:11 +01:00
mkSubmoduleOptions
2022-05-17 10:10:16 +02:00
mkPerSystemOption
2021-11-21 15:47:11 +01:00
;
2021-10-27 11:05:52 +02:00
in
{
options = {
2021-11-21 15:47:11 +01:00
flake = mkSubmoduleOptions {
2021-10-27 11:05:52 +02:00
packages = mkOption {
type = types.lazyAttrsOf (types.lazyAttrsOf types.package);
default = { };
2021-11-21 14:30:12 +01:00
description = ''
Per system an attribute set of packages.
<literal>nix build .#&lt;name></literal> will build <literal>packages.&lt;system>.&lt;name></literal>.
2021-11-21 14:30:12 +01:00
'';
2021-10-27 11:05:52 +02:00
};
};
2022-05-17 10:10:16 +02:00
perSystem = mkPerSystemOption ({ config, ... }: {
_file = ./packages.nix;
options = {
packages = mkOption {
type = types.lazyAttrsOf types.package;
default = { };
description = ''
An attribute set of packages to be built by <literal>nix build .#&lt;name></literal>.
<literal>nix build .#&lt;name></literal> will build <literal>packages.&lt;name></literal>.
'';
};
};
});
2021-10-27 11:05:52 +02:00
};
config = {
flake.packages =
mapAttrs
(k: v: v.packages)
(filterAttrs
(k: v: v.packages != null)
config.allSystems
2021-10-27 11:05:52 +02:00
);
perInput = system: flake:
optionalAttrs (flake?packages.${system}) {
packages = flake.packages.${system};
};
};
}