1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2024-12-14 11:47:31 +00:00
flake-parts/modules/apps.nix

59 lines
1.5 KiB
Nix
Raw Permalink Normal View History

2022-05-25 14:36:33 +00:00
{ config, lib, flake-parts-lib, ... }:
2022-05-11 20:45:26 +00:00
let
inherit (lib)
mkOption
types
;
2022-05-25 14:36:33 +00:00
inherit (flake-parts-lib)
2022-10-30 10:53:32 +00:00
mkTransposedPerSystemModule
2022-05-11 20:45:26 +00:00
;
programType = lib.types.coercedTo derivationType getExe lib.types.str;
derivationType = lib.types.package // {
check = lib.isDerivation;
};
2022-05-11 20:45:26 +00: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 07:55:23 +00:00
then x.bin or x.out or x
else x;
2022-05-11 20:45:26 +00:00
appType = lib.types.submodule {
options = {
type = mkOption {
2022-05-17 07:55:23 +00:00
type = lib.types.enum [ "app" ];
2022-05-11 20:45:26 +00:00
default = "app";
2022-11-11 06:39:25 +00:00
description = ''
2022-11-11 05:40:37 +00:00
A type tag for `apps` consumers.
2022-05-11 20:45:26 +00:00
'';
};
program = mkOption {
type = programType;
2022-11-11 06:39:25 +00:00
description = ''
2022-11-11 05:40:37 +00:00
A path to an executable or a derivation with `meta.mainProgram`.
2022-05-11 20:45:26 +00:00
'';
};
};
};
in
2022-10-30 10:53:32 +00:00
mkTransposedPerSystemModule {
name = "apps";
option = mkOption {
type = types.lazyAttrsOf appType;
default = { };
description = ''
2022-11-11 05:40:37 +00:00
Programs runnable with nix run `<name>`.
2022-10-30 10:53:32 +00:00
'';
example = lib.literalExpression or lib.literalExample ''
{
default.program = "''${config.packages.hello}/bin/hello";
}
'';
2022-05-11 20:45:26 +00:00
};
2022-10-30 10:53:32 +00:00
file = ./apps.nix;
2022-05-11 20:45:26 +00:00
}