about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorArtturi <Artturin@artturin.com>2022-04-26 21:42:23 +0300
committerGitHub <noreply@github.com>2022-04-26 21:42:23 +0300
commitc95f5e185e06d1938fc86af0f82fcf36597905df (patch)
tree5f08ff3394e88c971ee8c73bfc87ad07c3a4f534 /lib
parent1c99518c6f804c0d23ff82a20904768f18512909 (diff)
parent379b9c8be30ee14eb8703ec00c7ea5da5337c6b6 (diff)
Merge pull request #167247 from Artturin/addgetmainprog
lib/meta: add getExe to get the main program of a drv
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix2
-rw-r--r--lib/meta.nix14
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 1f06283790a8b..ec7f536bbdde4 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -108,7 +108,7 @@ let
       makeScope makeScopeWithSplicing;
     inherit (self.meta) addMetaAttrs dontDistribute setName updateName
       appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
-      hiPrioSet getLicenseFromSpdxId;
+      hiPrioSet getLicenseFromSpdxId getExe;
     inherit (self.sources) pathType pathIsDirectory cleanSourceFilter
       cleanSource sourceByRegex sourceFilesBySuffices
       commitIdFromGitRepo cleanSourceWith pathHasContext
diff --git a/lib/meta.nix b/lib/meta.nix
index 5b1f7ee5ff2d1..74b94211552b6 100644
--- a/lib/meta.nix
+++ b/lib/meta.nix
@@ -126,4 +126,18 @@ rec {
         lib.warn "getLicenseFromSpdxId: No license matches the given SPDX ID: ${licstr}"
         { shortName = licstr; }
       );
+
+  /* Get the path to the main program of a derivation with either
+     meta.mainProgram or pname or name
+
+     Type: getExe :: derivation -> string
+
+     Example:
+       getExe pkgs.hello
+       => "/nix/store/g124820p9hlv4lj8qplzxw1c44dxaw1k-hello-2.12/bin/hello"
+       getExe pkgs.mustache-go
+       => "/nix/store/am9ml4f4ywvivxnkiaqwr0hyxka1xjsf-mustache-go-1.3.0/bin/mustache"
+  */
+  getExe = x:
+    "${lib.getBin x}/bin/${x.meta.mainProgram or (lib.getName x)}";
 }