summary refs log tree commit diff
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2023-08-13 12:27:41 +0200
committerSefa Eyeoglu <contact@scrumplex.net>2023-08-13 15:45:37 +0200
commit30364657608090625e9c7f861da53f42f8e913f2 (patch)
treead9a37b5b6b57223858a5334478b810b8738edc7
parent9591244e00f3a164a96b60585e687d46c565876f (diff)
downloadnixpkgs-30364657608090625e9c7f861da53f42f8e913f2.tar
nixpkgs-30364657608090625e9c7f861da53f42f8e913f2.tar.gz
nixpkgs-30364657608090625e9c7f861da53f42f8e913f2.tar.bz2
nixpkgs-30364657608090625e9c7f861da53f42f8e913f2.tar.lz
nixpkgs-30364657608090625e9c7f861da53f42f8e913f2.tar.xz
nixpkgs-30364657608090625e9c7f861da53f42f8e913f2.tar.zst
nixpkgs-30364657608090625e9c7f861da53f42f8e913f2.zip
lib/meta.nix: introduce getExe'
getExe' can be used to get a binary other than the mainProgram from a
derivation.

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
-rw-r--r--lib/default.nix2
-rw-r--r--lib/meta.nix25
2 files changed, 21 insertions, 6 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 73b8ad87154..124528c5f50 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -116,7 +116,7 @@ let
     inherit (self.derivations) lazyDerivation;
     inherit (self.meta) addMetaAttrs dontDistribute setName updateName
       appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
-      hiPrioSet getLicenseFromSpdxId getExe;
+      hiPrioSet getLicenseFromSpdxId getExe getExe';
     inherit (self.filesystem) pathType pathIsDirectory pathIsRegularFile;
     inherit (self.sources) cleanSourceFilter
       cleanSource sourceByRegex sourceFilesBySuffices
diff --git a/lib/meta.nix b/lib/meta.nix
index d32a37fe61d..50665c9513d 100644
--- a/lib/meta.nix
+++ b/lib/meta.nix
@@ -144,9 +144,24 @@ rec {
        => "/nix/store/am9ml4f4ywvivxnkiaqwr0hyxka1xjsf-mustache-go-1.3.0/bin/mustache"
   */
   getExe = x:
-    "${lib.getBin x}/bin/${x.meta.mainProgram or (
-      # This could be turned into an error when 23.05 is at end of life
-      lib.warn "getExe: Package ${lib.strings.escapeNixIdentifier x.meta.name or x.pname or x.name} does not have the meta.mainProgram attribute. We'll assume that the main program has the same name for now, but this behavior is deprecated, because it leads to surprising errors when the assumption does not hold. If the package has a main program, please set `meta.mainProgram` in its definition to make this warning go away. Otherwise, if the package does not have a main program, or if you don't control its definition, specify the full path to the program, such as \"\${lib.getBin foo}/bin/bar\"."
-      lib.getName x
-    )}";
+    let
+      y = x.meta.mainProgram or (
+        # This could be turned into an error when 23.05 is at end of life
+        lib.warn "getExe: Package ${lib.strings.escapeNixIdentifier x.meta.name or x.pname or x.name} does not have the meta.mainProgram attribute. We'll assume that the main program has the same name for now, but this behavior is deprecated, because it leads to surprising errors when the assumption does not hold. If the package has a main program, please set `meta.mainProgram` in its definition to make this warning go away. Otherwise, if the package does not have a main program, or if you don't control its definition, specify the full path to the program, such as \"\${lib.getBin foo}/bin/bar\"."
+          lib.getName
+          x
+      );
+    in
+    getExe' x y;
+
+  /* Get the path of a program of a derivation.
+
+     Type: getExe' :: derivation -> string -> string
+     Example:
+       getExe' pkgs.hello "hello"
+       => "/nix/store/g124820p9hlv4lj8qplzxw1c44dxaw1k-hello-2.12/bin/hello"
+       getExe' pkgs.imagemagick "convert"
+       => "/nix/store/5rs48jamq7k6sal98ymj9l4k2bnwq515-imagemagick-7.1.1-15/bin/convert"
+  */
+  getExe' = x: y: "${lib.getBin x}/bin/${y}";
 }