{ config, lib, flake-parts-lib, ... }:
let
inherit (lib)
filterAttrs
mapAttrs
mkOption
optionalAttrs
types
;
inherit (flake-parts-lib)
mkSubmoduleOptions
mkPerSystemOption
;
in
{
options = {
flake = mkSubmoduleOptions {
packages = mkOption {
type = types.lazyAttrsOf (types.lazyAttrsOf types.package);
default = { };
description = ''
Per system an attribute set of packages.
nix build .#<name> will build packages.<system>.<name>.
'';
};
};
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 nix build .#<name>.
nix build .#<name> will build packages.<name>.
'';
};
};
});
};
config = {
flake.packages =
mapAttrs
(k: v: v.packages)
(filterAttrs
(k: v: v.packages != null)
config.allSystems
);
perInput = system: flake:
optionalAttrs (flake?packages.${system}) {
packages = flake.packages.${system};
};
};
}