From bbbc41918634c2388f1fd39db1c8f162e3ab4b95 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Wed, 22 Apr 2020 09:48:05 +0200 Subject: [PATCH 1/2] srcOnly: fix invocation and document Previously, callPackage would try and fill the arguments such as `name` and `src` which would cause problems if those existed as top-level attributes. This also makes it clearer what part is the function signature. Then document the derivation inline in the code to explain the ellipsis and various use-cases. --- pkgs/build-support/src-only/default.nix | 17 ++++++++++++++++- pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/src-only/default.nix b/pkgs/build-support/src-only/default.nix index a93b3648090..8ca262a998b 100644 --- a/pkgs/build-support/src-only/default.nix +++ b/pkgs/build-support/src-only/default.nix @@ -1,4 +1,19 @@ -{stdenv, name, src, patches ? [], buildInputs ? [], ...}: +{ stdenv }@orig: +# srcOnly is a utility builder that only fetches and unpacks the given `src`, +# maybe pathings it in the process with the optional `patches` and +# `buildInputs` attributes. +# +# It can be invoked directly, or be used to wrap an existing derivation. Eg: +# +# > srcOnly pkgs.hello +# +{ name +, src +, stdenv ? orig.stdenv +, patches ? [] +, buildInputs ? [] +, ... # needed when passing an existing derivation +}: stdenv.mkDerivation { inherit src buildInputs patches name; installPhase = "cp -r . $out"; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index febca841867..7e61b010316 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -450,7 +450,7 @@ in singularity-tools = callPackage ../build-support/singularity-tools { }; - srcOnly = args: callPackage ../build-support/src-only args; + srcOnly = callPackage ../build-support/src-only { }; substituteAll = callPackage ../build-support/substitute/substitute-all.nix { }; From 31ead7d030b235fcbb7b6a6d92600f23702c7505 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Thu, 23 Apr 2020 11:44:55 +0200 Subject: [PATCH 2/2] srcOnly: rename buildInputs to nativeBuildInputs The only reason to pass build inputs is to extend the unpackPhase with custom unpack commands. Eg: add "unrar" to unpack rar sources. And those should really be passed as native build inputs. Why? Because nativeBuildInputs is for dependencies that are used at build time but will not propagate as runtime dependencies. And also, cross-compilation. --- pkgs/build-support/src-only/default.nix | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/src-only/default.nix b/pkgs/build-support/src-only/default.nix index 8ca262a998b..c721fdf40c6 100644 --- a/pkgs/build-support/src-only/default.nix +++ b/pkgs/build-support/src-only/default.nix @@ -11,11 +11,21 @@ , src , stdenv ? orig.stdenv , patches ? [] -, buildInputs ? [] -, ... # needed when passing an existing derivation +, # deprecated, use the nativeBuildInputs + buildInputs ? [] +, # used to pass extra unpackers + nativeBuildInputs ? [] +, # needed when passing an existing derivation + ... }: stdenv.mkDerivation { - inherit src buildInputs patches name; + inherit + buildInputs + name + nativeBuildInputs + patches + src + ; installPhase = "cp -r . $out"; phases = ["unpackPhase" "patchPhase" "installPhase"]; }