From 2a9b8080b61c3752e701cf6a6905e45e455bc3e3 Mon Sep 17 00:00:00 2001 From: Sofi Date: Sun, 20 Aug 2023 03:24:46 +0200 Subject: [PATCH] deprecate `mkApp` in favor of direct definitions Now that nixpkgs has its own idea of `passthru.exePath` under the name `meta.mainProgram`, deprecate our solution in favor of the new standard. This subsequently removes the value of which `mkApp` brings, and therefore a full deprecation for its removal has begun. --- README.md | 11 ++++++++++- examples/each-system/flake.nix | 5 ++++- lib.nix | 10 +++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f2144de..03df3bb 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,10 @@ eachSystem allSystems (system: { hello = 42; }) default = hello; }; apps = rec { - hello = flake-utils.lib.mkApp { drv = self.packages.${system}.hello; }; + hello = { + type = "app"; + program = "${nixpkgs.lib.getExe self.packages.${system}.hello}"; + }; default = hello; }; } @@ -121,6 +124,12 @@ manageable parts. ### `mkApp { drv, name ? drv.pname or drv.name, exePath ? drv.passthru.exePath or "/bin/${name}"` +> **DEPRECATED** +> +> `mkApp` has been deprecated in favor of direct definitions. +> +> Example: `{ type = "app"; program = "${nixpkgs.lib.getExe drv}"; }` + A small utility that builds the structure expected by the special `apps` and `defaultApp` prefixes. diff --git a/examples/each-system/flake.nix b/examples/each-system/flake.nix index 7eff847..4d47cb8 100644 --- a/examples/each-system/flake.nix +++ b/examples/each-system/flake.nix @@ -12,7 +12,10 @@ default = hello; }; apps = rec { - hello = flake-utils.lib.mkApp { drv = self.packages.${system}.hello; }; + hello = { + type = "app"; + program = "${nixpkgs.lib.getExe self.packages.${system}.hello}"; + }; default = hello; }; } diff --git a/lib.nix b/lib.nix index a774f18..aec9a22 100644 --- a/lib.nix +++ b/lib.nix @@ -202,11 +202,19 @@ let recursiveUpdate output (import subflake inputs)) { }; # Returns the structure used by `nix app` - mkApp = + mkApp = let + # Pulled from nixpkgs.lib + warn = + if builtins.elem (builtins.getEnv "NIX_ABORT_ON_WARN") ["1" "true" "yes"] + then msg: builtins.trace "warning: ${msg}" (abort "NIX_ABORT_ON_WARN=true; warnings are treated as unrecoverable errors.") + else msg: builtins.trace "warning: ${msg}"; + in { drv , name ? drv.pname or drv.name , exePath ? drv.passthru.exePath or "/bin/${name}" }: + warn + "`mkApp` has been deprecated in favor of direct definitions. Replace definitions of `mkApp { drv = ...; }` with `{ type = \"app\"; program = \"\${nixpkgs.lib.getExe drv}\"; }` to remove this warning. Use of `passthru.exePath` inside derivations should be replaced with nixpkgs' `meta.mainProgram` instead." { type = "app"; program = "${drv}${exePath}";