Skip to content

Commit

Permalink
lib/meta: add getExe to get the main program of a drv
Browse files Browse the repository at this point in the history
  • Loading branch information
Artturin committed Apr 24, 2022
1 parent daac043 commit 379b9c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions lib/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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)}";
}

0 comments on commit 379b9c8

Please sign in to comment.