From 0ed9e35a220b9de5b9462deba3900605e174809d Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 31 Jul 2023 21:50:23 +0200 Subject: [PATCH] writers: Set mainProgram Part of https://github.com/NixOS/nixpkgs/pull/246386 --- pkgs/build-support/writers/scripts.nix | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/writers/scripts.nix b/pkgs/build-support/writers/scripts.nix index 7fc47fbcdf94..c43f10f0a2ec 100644 --- a/pkgs/build-support/writers/scripts.nix +++ b/pkgs/build-support/writers/scripts.nix @@ -25,13 +25,21 @@ rec { name = last (builtins.split "/" nameOrPath); in - pkgs.runCommandLocal name (if (types.str.check content) then { - inherit content interpreter; - passAsFile = [ "content" ]; - } else { - inherit interpreter; - contentPath = content; - }) '' + pkgs.runCommandLocal name ( + lib.optionalAttrs (nameOrPath == "/bin/${name}") { + meta.mainProgram = name; + } + // ( + if (types.str.check content) then { + inherit content interpreter; + passAsFile = [ "content" ]; + } else { + inherit interpreter; + contentPath = content; + } + ) + ) + '' # 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 # arguments to the interpreter are allowed. @@ -89,6 +97,8 @@ rec { # https://github.com/NixOS/nixpkgs/issues/154203 # https://github.com/NixOS/nixpkgs/issues/148189 nativeBuildInputs = [ stdenv.cc.bintools ]; + } // lib.optionalAttrs (nameOrPath == "/bin/${name}") { + meta.mainProgram = name; }) '' ${compileScript} ${lib.optionalString strip