lib.meta.getDarwinApp: init, add tests

This is useful for nix-darwin system.defaults.dock.persistent-apps

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
This commit is contained in:
Ethan Carter Edwards
2026-08-08 19:44:37 -07:00
parent 7246360b7d
commit 2c2686cbbe
3 changed files with 48 additions and 0 deletions

View File

@@ -452,6 +452,7 @@ let
getLicenseFromSpdxIdOr
getExe
getExe'
getDarwinApp
getDarwinApp'
;
inherit (self.filesystem)

View File

@@ -581,6 +581,42 @@ rec {
|| throw "lib.meta.getExe': The second argument \"${y}\" is a nested path with a \"/\" character, but it should just be the name of the executable instead.";
"${getBin x}/bin/${y}";
/**
Get the path to the main darwin app of a package based on `meta.mainDarwinApp`
# Inputs
`x`
: 1\. Function argument
# Type
```
getDarwinApp :: Derivation -> StorePath
```
# Examples
:::{.example}
## `lib.meta.getDarwinApp` usage example
```nix
getDarwinApp pkgs.vscodium
=> "/nix/store/0y95mgmlrs8cayv2cnj23xjfljwhlib0-vscodium-1.121.03429/Applications/VSCodium.app"
getDarwinApp pkgs.slack
=> "/nix/store/g52cl8dblki8dr5bkr0vajpkralkmhi0-slack-4.49.89/Applications/Slack.app"
```
:::
*/
getDarwinApp =
x:
getDarwinApp' x (
x.meta.mainDarwinApp or (builtins.throw "getDarwinApp: Package ${
lib.strings.escapeNixIdentifier x.meta.name or x.pname or x.name
} does not have the meta.mainDarwinApp attribute. If the package has a main darwin app, please set `meta.mainDarwinApp` in its definition to make this error go away. Otherwise, if the package does not have a main darwin app, or if you don't control its definition, use getDarwinApp' to specify the name to the program, such as lib.getDarwinApp' vscodium \"VSCodium.app\".")
);
/**
Get the path of an darwin app for a derivation.

View File

@@ -61,6 +61,7 @@ let
genList
getExe
getExe'
getDarwinApp
getDarwinApp'
getLicenseFromSpdxIdOr
groupBy
@@ -4753,6 +4754,16 @@ runTests {
testGetExe'FailureSecondArg = testingThrow (getExe' { type = "derivation"; } "dir/executable");
testGetDarwinAppOutput = {
expr = getDarwinApp {
type = "derivation";
out = "somelonghash";
bin = "somelonghash";
meta.mainDarwinApp = "mainDarwinApp.app";
};
expected = "somelonghash/Applications/mainDarwinApp.app";
};
testGetDarwinApp'Output = {
expr = getDarwinApp' {
type = "derivation";