writers: Set mainProgram

Part of https://github.com/NixOS/nixpkgs/pull/246386
This commit is contained in:
Robert Hensing 2023-07-31 21:50:23 +02:00
parent 34ee0260ec
commit 0ed9e35a22

View file

@ -25,13 +25,21 @@ rec {
name = last (builtins.split "/" nameOrPath); name = last (builtins.split "/" nameOrPath);
in in
pkgs.runCommandLocal name (if (types.str.check content) then { pkgs.runCommandLocal name (
lib.optionalAttrs (nameOrPath == "/bin/${name}") {
meta.mainProgram = name;
}
// (
if (types.str.check content) then {
inherit content interpreter; inherit content interpreter;
passAsFile = [ "content" ]; passAsFile = [ "content" ];
} else { } else {
inherit interpreter; inherit interpreter;
contentPath = content; contentPath = content;
}) '' }
)
)
''
# On darwin a script cannot be used as an interpreter in a shebang but # On darwin a script cannot be used as an interpreter in a shebang but
# there doesn't seem to be a limit to the size of shebang and multiple # there doesn't seem to be a limit to the size of shebang and multiple
# arguments to the interpreter are allowed. # arguments to the interpreter are allowed.
@ -89,6 +97,8 @@ rec {
# https://github.com/NixOS/nixpkgs/issues/154203 # https://github.com/NixOS/nixpkgs/issues/154203
# https://github.com/NixOS/nixpkgs/issues/148189 # https://github.com/NixOS/nixpkgs/issues/148189
nativeBuildInputs = [ stdenv.cc.bintools ]; nativeBuildInputs = [ stdenv.cc.bintools ];
} // lib.optionalAttrs (nameOrPath == "/bin/${name}") {
meta.mainProgram = name;
}) '' }) ''
${compileScript} ${compileScript}
${lib.optionalString strip ${lib.optionalString strip