diff --git a/lib/default.nix b/lib/default.nix index d67d80c09f81..a22b05d483b7 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -452,6 +452,7 @@ let getLicenseFromSpdxIdOr getExe getExe' + getDarwinApp getDarwinApp' ; inherit (self.filesystem) diff --git a/lib/meta.nix b/lib/meta.nix index f943302e41f3..c87b2d735489 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -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. diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 8aa6cfafe9ca..643c3b0b8a25 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -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";