From 7246360b7d587d439df8d42d6847488f076e161e Mon Sep 17 00:00:00 2001 From: Ethan Carter Edwards Date: Sat, 8 Aug 2026 19:40:22 -0700 Subject: [PATCH] lib.meta.getDarwinApp': init, add tests This is useful for nix-darwin system.defaults.dock.persistent-apps Signed-off-by: Ethan Carter Edwards --- lib/default.nix | 1 + lib/meta.nix | 48 ++++++++++++++++++++++++++++++++++++++++++++++ lib/tests/misc.nix | 16 ++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/lib/default.nix b/lib/default.nix index 56baba8708c5..d67d80c09f81 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -452,6 +452,7 @@ let getLicenseFromSpdxIdOr getExe getExe' + getDarwinApp' ; inherit (self.filesystem) pathType diff --git a/lib/meta.nix b/lib/meta.nix index 1defd305abc0..f943302e41f3 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -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 `*`. diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index cfbf0d93b2e4..8aa6cfafe9ca 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -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)