Skip to content

Commit

Permalink
deprecate mkApp in favor of direct definitions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
soupglasses committed Aug 20, 2023
1 parent 919d646 commit 2a9b808
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Expand All @@ -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.


Expand Down
5 changes: 4 additions & 1 deletion examples/each-system/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Expand Down
10 changes: 9 additions & 1 deletion lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down

0 comments on commit 2a9b808

Please sign in to comment.