Skip to content

Commit 015166e

Browse files
committed
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. Closes: #65
1 parent 919d646 commit 015166e

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ eachSystem allSystems (system: { hello = 42; })
105105
default = hello;
106106
};
107107
apps = rec {
108-
hello = flake-utils.lib.mkApp { drv = self.packages.${system}.hello; };
108+
hello = {
109+
type = "app";
110+
program = "${nixpkgs.lib.getExe self.packages.${system}.hello}";
111+
};
109112
default = hello;
110113
};
111114
}
@@ -121,6 +124,12 @@ manageable parts.
121124

122125
### `mkApp { drv, name ? drv.pname or drv.name, exePath ? drv.passthru.exePath or "/bin/${name}"`
123126

127+
> **DEPRECATED**
128+
>
129+
> `mkApp` has been deprecated in favor of direct definitions.
130+
>
131+
> Example: `{ type = "app"; program = "${nixpkgs.lib.getExe drv}"; }`
132+
124133
A small utility that builds the structure expected by the special `apps` and `defaultApp` prefixes.
125134

126135

examples/each-system/flake.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
default = hello;
1313
};
1414
apps = rec {
15-
hello = flake-utils.lib.mkApp { drv = self.packages.${system}.hello; };
15+
hello = {
16+
type = "app";
17+
program = "${nixpkgs.lib.getExe self.packages.${system}.hello}";
18+
};
1619
default = hello;
1720
};
1821
}

lib.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,19 @@ let
202202
recursiveUpdate output (import subflake inputs)) { };
203203

204204
# Returns the structure used by `nix app`
205-
mkApp =
205+
mkApp = let
206+
# Pulled from nixpkgs.lib
207+
warn =
208+
if builtins.elem (builtins.getEnv "NIX_ABORT_ON_WARN") ["1" "true" "yes"]
209+
then msg: builtins.trace "warning: ${msg}" (abort "NIX_ABORT_ON_WARN=true; warnings are treated as unrecoverable errors.")
210+
else msg: builtins.trace "warning: ${msg}";
211+
in
206212
{ drv
207213
, name ? drv.pname or drv.name
208214
, exePath ? drv.passthru.exePath or "/bin/${name}"
209215
}:
216+
warn
217+
"`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."
210218
{
211219
type = "app";
212220
program = "${drv}${exePath}";

0 commit comments

Comments
 (0)