diff --git a/README.md b/README.md index f2144de..3fd1484 100644 --- a/README.md +++ b/README.md @@ -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"; + }; }; } ); @@ -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` diff --git a/examples/each-system/flake.nix b/examples/each-system/flake.nix index 7eff847..54f19b9 100644 --- a/examples/each-system/flake.nix +++ b/examples/each-system/flake.nix @@ -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; }; - 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"; + }; }; } ); diff --git a/lib.nix b/lib.nix index a774f18..9f1b915 100644 --- a/lib.nix +++ b/lib.nix @@ -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}";