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

Merge pull request #209 from hercules-ci/getexe

Getexe
This commit is contained in:
Robert Hensing 2024-01-29 19:03:35 +01:00 committed by GitHub
commit bffc4be17f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 10 deletions

View file

@ -14,11 +14,18 @@ rec {
inherit (f-p-lib) mkFlake;
inherit (f-p.inputs.nixpkgs-lib) lib;
pkg = system: name: derivation {
name = name;
builder = "no-builder";
system = system;
};
pkg = system: name:
derivation
{
name = name;
builder = "no-builder";
system = system;
}
// {
meta = {
mainProgram = name;
};
};
empty = mkFlake
{ inputs.self = { }; }
@ -46,8 +53,9 @@ rec {
{ inputs.self = { }; }
{
systems = [ "a" "b" ];
perSystem = { system, ... }: {
perSystem = { config, system, ... }: {
packages.hello = pkg system "hello";
apps.hello.program = config.packages.hello;
};
};
@ -142,7 +150,20 @@ rec {
};
assert example1 == {
apps = { a = { }; b = { }; };
apps = {
a = {
hello = {
program = "${pkg "a" "hello"}/bin/hello";
type = "app";
};
};
b = {
hello = {
program = "${pkg "b" "hello"}/bin/hello";
type = "app";
};
};
};
checks = { a = { }; b = { }; };
devShells = { a = { }; b = { }; };
formatter = { };

View file

@ -8,15 +8,17 @@ let
mkTransposedPerSystemModule
;
getExe = lib.getExe or (
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"'')}"
);
programType = lib.types.coercedTo derivationType getExe lib.types.str;
derivationType = lib.types.package // {
check = lib.isDerivation;
};
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"'')}";
appType = lib.types.submodule {
options = {
type = mkOption {