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:40:22 -07:00
parent e59c5479c0
commit 7246360b7d
3 changed files with 65 additions and 0 deletions

View File

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

View File

@@ -581,6 +581,54 @@ 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 of an darwin app for a derivation.
# Inputs
`x`
: 1\. Function argument
`y`
: 2\. Function argument
# Type
```
getDarwinApp' :: Derivation -> String -> StorePath
```
# Examples
:::{.example}
## `lib.meta.getDarwinApp'` usage example
```nix
getDarwinApp' pkgs.linear "Linear.app"
=> "/nix/store/z4vh6ldb2vpspv307q7mk6wazfmh5dic-linear-1.30.2/Applications/Linear.app"
getDarwinApp' pkgs.vscodium "VSCodium.app"
=> "/nix/store/0y95mgmlrs8cayv2cnj23xjfljwhlib0-vscodium-1.121.03429/Applications/VSCodium.app"
```
:::
*/
getDarwinApp' =
x: y:
assert
isDerivation x
|| throw "lib.meta.getDarwinApp': The first argument is of type ${typeOf x}, but it should be a derivation instead.";
assert
isString y
|| throw "lib.meta.getDarwinApp': The second argument is of type ${typeOf y}, but it should be a string instead.";
assert
lib.hasInfix "/" y == false
|| throw "lib.meta.getDarwinApp': The second argument \"${y}\" is a nested path with a \"/\" character, but it should just be the name of the app instead.";
assert
lib.hasSuffix ".app" y
|| throw "lib.meta.getDarwinApp': The second argument \"${y}\" must end in `.app`";
"${lib.getOutput "out" x}/Applications/${y}";
/**
Generate [CPE parts](#var-meta-identifiers-cpeParts) from inputs. Copies `vendor` and `version` to the output, and sets `update` to `*`.

View File

@@ -61,6 +61,7 @@ let
genList
getExe
getExe'
getDarwinApp'
getLicenseFromSpdxIdOr
groupBy
groupBy'
@@ -4752,6 +4753,21 @@ runTests {
testGetExe'FailureSecondArg = testingThrow (getExe' { type = "derivation"; } "dir/executable");
testGetDarwinApp'Output = {
expr = getDarwinApp' {
type = "derivation";
out = "somelonghash";
bin = "somelonghash";
} "app.app";
expected = "somelonghash/Applications/app.app";
};
testGetDarwinApp'FailureFirstArg = testingThrow (getDarwinApp' "not a derivation" "executable");
testGetDarwinApp'FailureSecondArg = testingThrow (
getDarwinApp' { type = "derivation"; } "dir/executable"
);
testGetLicenseFromSpdxIdOrExamples = {
expr = [
(getLicenseFromSpdxIdOr "MIT" null)