1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2025-03-15 13:07:52 +00:00
flake-parts/modules/apps.nix

87 lines
2.2 KiB
Nix
Raw Normal View History

2022-05-25 16:36:33 +02:00
{ config, lib, flake-parts-lib, ... }:
2022-05-11 22:45:26 +02:00
let
inherit (lib)
filterAttrs
mapAttrs
mkOption
optionalAttrs
types
;
2022-05-25 16:36:33 +02:00
inherit (flake-parts-lib)
2022-05-11 22:45:26 +02:00
mkSubmoduleOptions
2022-05-13 10:15:21 +02:00
mkPerSystemOption
2022-05-11 22:45:26 +02:00
;
programType = lib.types.coercedTo derivationType getExe lib.types.str;
derivationType = lib.types.package // {
check = lib.isDerivation;
};
2022-05-11 22:45:26 +02:00
getExe = x:
"${lib.getBin x}/bin/${x.meta.mainProgram or (throw ''Package ${x.name or ""} does not have meta.mainProgram set, so I don't know how to find the main executable. You can set meta.mainProgram, or pass the full path to executable, e.g. program = "''${pkg}/bin/foo"'')}";
getBin = x:
if !x?outputSpecified || !x.outputSpecified
2022-05-17 09:55:23 +02:00
then x.bin or x.out or x
else x;
2022-05-11 22:45:26 +02:00
appType = lib.types.submodule {
options = {
type = mkOption {
2022-05-17 09:55:23 +02:00
type = lib.types.enum [ "app" ];
2022-05-11 22:45:26 +02:00
default = "app";
description = ''
A type tag for <literal>apps</literal> consumers.
'';
};
program = mkOption {
type = programType;
description = ''
A path to an executable or a derivation with <literal>meta.mainProgram</literal>.
'';
};
};
};
in
{
options = {
flake = mkSubmoduleOptions {
apps = mkOption {
type = types.lazyAttrsOf (types.lazyAttrsOf appType);
default = { };
description = ''
Programs runnable with nix run <literal>.#&lt;name></literal>.
'';
example = lib.literalExpression or lib.literalExample ''
2022-05-11 22:45:26 +02:00
{
x86_64-linux.default.program = "''${config.packages.hello}/bin/hello";
}
'';
};
};
2022-05-17 09:55:23 +02:00
perSystem = mkPerSystemOption
({ config, system, ... }: {
options = {
apps = mkOption {
type = types.lazyAttrsOf appType;
default = { };
description = ''
Programs runnable with nix run <literal>.#&lt;name></literal>.
'';
example = lib.literalExpression or lib.literalExample ''
{
default.program = "''${config.packages.hello}/bin/hello";
}
'';
};
};
});
2022-05-11 22:45:26 +02:00
};
config = {
2022-10-26 13:16:04 +02:00
transposition.apps = { };
2022-05-11 22:45:26 +02:00
};
}