Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate mkApp in favor of direct definitions #103

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,21 @@ eachSystem allSystems (system: { hello = 42; })
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
packages = rec {
hello = pkgs.hello;
default = hello;
packages = {
default = pkgs.hello;
# `nix run .#find` will work because findutils.meta.mainProgram is set to "find".
find = pkgs.findutils;
};
apps = rec {
hello = flake-utils.lib.mkApp { drv = self.packages.${system}.hello; };
default = hello;
# Use apps to expose packages that have multiple binaries.
apps = {
xargs = flake-utils.lib.mkApp {
drv = pkgs.findutils;
name = "xargs";
};
ls = flake-utils.lib.mkApp {
drv = pkgs.coreutils;
name = "ls";
};
};
}
);
Expand All @@ -119,9 +127,16 @@ Meld merges subflakes using common inputs. Useful when you want to
split up a large flake with many different components into more
manageable parts.

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

A small utility that builds the structure expected by the special `apps` and `defaultApp` prefixes.
> **DEPRECATED**
>
> `mkApp` used to look for `drv.passthru.exePath`, and it's no longer the case.
>
> For derivations that only expose a single binary, set the `meta.mainProgram`
> attribute on the package and expose it in the `packages`.

A small utility that builds the structure expected by the special `apps` prefix.


### `flattenTree :: attrs -> attrs`
Expand Down
20 changes: 14 additions & 6 deletions examples/each-system/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
packages = rec {
hello = pkgs.hello;
default = hello;
packages = {
default = pkgs.hello;
# `nix run .#find` will work because findutils.meta.mainProgram is set to "find".
find = pkgs.findutils;
};
apps = rec {
hello = flake-utils.lib.mkApp { drv = self.packages.${system}.hello; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you think it would be nicer to deprecate drv.passthru.exePath and use nixpkgs.lib.getExe in the helper instead?

This is still a bit simpler to use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, I don't see a lot of value in definining those apps.

Copy link
Author

@soupglasses soupglasses Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. There is a problem where all these apps can be rewritten as packages."<system>"."<name>" since nix3-run runs against meta.mainProgram as well.

Unsure how to show examples without removing apps outright.

default = hello;
# Use apps to expose packages that have multiple binaries.
apps = {
xargs = flake-utils.lib.mkApp {
drv = pkgs.findutils;
name = "xargs";
};
ls = flake-utils.lib.mkApp {
drv = pkgs.coreutils;
name = "ls";
};
};
}
);
Expand Down
16 changes: 14 additions & 2 deletions lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,23 @@ 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}"
, exePath ? "/bin/${name}"
}:
(if (drv.passthru or {}) ? exePath then
warn
"flake-utils.lib.mkApp: ${name} has the deprecated `drv.passthru.exePath` attribute. Please pass the `exePath` directly."
else
lib.id
)
{
type = "app";
program = "${drv}${exePath}";
Expand Down