From 704e11319765222175174c091fc61c501808a92e Mon Sep 17 00:00:00 2001 From: Sofi Date: Sun, 20 Aug 2023 03:41:35 +0200 Subject: [PATCH 1/5] 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..80cb001 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}\"; }`, and definitions of `mkApp { drv = ...; name = \"abc\"; }` with `{ type = \"app\"; program = \"\${drv}/bin/abc\"; }` to remove this warning. Use of `passthru.exePath` inside derivations should be replaced with nixpkgs's `meta.mainProgram` instead." { type = "app"; program = "${drv}${exePath}"; From bee7b40d333563128ef19b0226ad18a8a43ce19e Mon Sep 17 00:00:00 2001 From: Jonas Chevalier Date: Sun, 20 Aug 2023 10:19:06 +0200 Subject: [PATCH 2/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 03df3bb..009670d 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ manageable parts. > > `mkApp` has been deprecated in favor of direct definitions. > -> Example: `{ type = "app"; program = "${nixpkgs.lib.getExe drv}"; }` +> Example: `{ type = "app"; program = nixpkgs.lib.getExe drv; }` A small utility that builds the structure expected by the special `apps` and `defaultApp` prefixes. From 015b2db1fffa8ce9e33a6e15e52f6363240c768d Mon Sep 17 00:00:00 2001 From: Jonas Chevalier Date: Sun, 20 Aug 2023 10:19:11 +0200 Subject: [PATCH 3/5] Update examples/each-system/flake.nix --- examples/each-system/flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/each-system/flake.nix b/examples/each-system/flake.nix index 4d47cb8..7ff983a 100644 --- a/examples/each-system/flake.nix +++ b/examples/each-system/flake.nix @@ -14,7 +14,7 @@ apps = rec { hello = { type = "app"; - program = "${nixpkgs.lib.getExe self.packages.${system}.hello}"; + program = nixpkgs.lib.getExe self.packages.${system}.hello; }; default = hello; }; From 94e7512d9789bb6a247a023c6979de44c9b44f31 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Wed, 23 Aug 2023 16:06:15 +0200 Subject: [PATCH 4/5] deprecate drv.passthru.exePath instead --- README.md | 21 +++++++++++++-------- examples/each-system/flake.nix | 21 +++++++++++++-------- lib.nix | 8 ++++++-- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 009670d..c792132 100644 --- a/README.md +++ b/README.md @@ -100,16 +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 = { - type = "app"; - program = "${nixpkgs.lib.getExe self.packages.${system}.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"; }; - default = hello; }; } ); diff --git a/examples/each-system/flake.nix b/examples/each-system/flake.nix index 7ff983a..54f19b9 100644 --- a/examples/each-system/flake.nix +++ b/examples/each-system/flake.nix @@ -7,16 +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 = { - type = "app"; - program = nixpkgs.lib.getExe self.packages.${system}.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"; }; - default = hello; }; } ); diff --git a/lib.nix b/lib.nix index 80cb001..9f1b915 100644 --- a/lib.nix +++ b/lib.nix @@ -211,10 +211,14 @@ let 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 - "`mkApp` has been deprecated in favor of direct definitions. Replace definitions of `mkApp { drv = ...; }` with `{ type = \"app\"; program = \"\${nixpkgs.lib.getExe drv}\"; }`, and definitions of `mkApp { drv = ...; name = \"abc\"; }` with `{ type = \"app\"; program = \"\${drv}/bin/abc\"; }` to remove this warning. Use of `passthru.exePath` inside derivations should be replaced with nixpkgs's `meta.mainProgram` instead." + "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}"; From e54db8d8a372d2a4e4567f7903cdd9801c20d2a7 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Wed, 23 Aug 2023 16:10:05 +0200 Subject: [PATCH 5/5] fix README --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c792132..3fd1484 100644 --- a/README.md +++ b/README.md @@ -127,15 +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}"` > **DEPRECATED** > -> `mkApp` has been deprecated in favor of direct definitions. +> `mkApp` used to look for `drv.passthru.exePath`, and it's no longer the case. > -> Example: `{ type = "app"; program = nixpkgs.lib.getExe drv; }` +> 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` and `defaultApp` prefixes. +A small utility that builds the structure expected by the special `apps` prefix. ### `flattenTree :: attrs -> attrs`