From 8b2f209838668ead093dec603bdfdb0347a69a07 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 6 Mar 2015 16:42:06 +0100 Subject: mkDerivation: Use function arguments --- pkgs/stdenv/generic/default.nix | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'pkgs/stdenv/generic') diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 751366e38d23..a53ccc3b60a4 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -83,7 +83,15 @@ let # Add a utility function to produce derivations that use this # stdenv and its shell. - mkDerivation = attrs: + mkDerivation = + { buildInputs ? [] + , nativeBuildInputs ? [] + , propagatedBuildInputs ? [] + , propagatedNativeBuildInputs ? [] + , crossConfig ? null + , meta ? {} + , passthru ? {} + , ... } @ attrs: let pos = if attrs.meta.description or null != null then @@ -122,13 +130,7 @@ let lib.addPassthru (derivation ( (removeAttrs attrs ["meta" "passthru" "crossAttrs"]) - // (let - buildInputs = attrs.buildInputs or []; - nativeBuildInputs = attrs.nativeBuildInputs or []; - propagatedBuildInputs = attrs.propagatedBuildInputs or []; - propagatedNativeBuildInputs = attrs.propagatedNativeBuildInputs or []; - crossConfig = attrs.crossConfig or null; - in + // { builder = attrs.realBuilder or shell; args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; @@ -144,7 +146,7 @@ let nativeBuildInputs = nativeBuildInputs ++ (if crossConfig == null then buildInputs else []); propagatedNativeBuildInputs = propagatedNativeBuildInputs ++ (if crossConfig == null then propagatedBuildInputs else []); - }))) ( + })) ( { # The meta attribute is passed in the resulting attribute set, # but it's not part of the actual derivation, i.e., it's not @@ -152,15 +154,15 @@ let # include it in the result, it *is* available to nix-env for # queries. We also a meta.position attribute here to # identify the source location of the package. - meta = attrs.meta or {} // (if pos != null then { - position = pos.file + ":" + (toString pos.line); + meta = meta // (if pos != null then { + position = pos.file + ":" + toString pos.line; } else {}); - passthru = attrs.passthru or {}; + inherit passthru; } // # Pass through extra attributes that are not inputs, but # should be made available to Nix expressions using the # derivation (e.g., in assertions). - (attrs.passthru or {})); + passthru); # The stdenv that we are producing. result = -- cgit 1.4.1 From 5c0eb64d4312737f34b9f766f1836a6e75878251 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 27 Mar 2015 16:11:18 +0100 Subject: Set more precise meta.position for Haskell packages --- .../haskell-modules/generic-builder.nix | 4 +++- pkgs/stdenv/generic/default.nix | 23 +++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'pkgs/stdenv/generic') diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 4b0ddaf991c7..3e9f82db359f 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -43,7 +43,7 @@ , preFixup ? "", postFixup ? "" , coreSetup ? false # Use only core packages to build Setup.hs. , useCpphs ? false -}: +} @ args: assert pkgconfigDepends != [] -> pkgconfig != null; assert editedCabalFile != null -> revision != null; @@ -112,6 +112,8 @@ in stdenv.mkDerivation ({ name = "${optionalString hasActiveLibrary "haskell-"}${pname}-${version}"; + pos = builtins.unsafeGetAttrPos "pname" args; + prePhases = ["setupCompilerEnvironmentPhase"]; preConfigurePhases = ["compileBuildDriverPhase"]; preInstallPhases = ["haddockPhase"]; diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index a53ccc3b60a4..6960c84ba5e3 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -69,8 +69,6 @@ let isUnfree (lib.lists.toList attrs.meta.license) && !allowUnfreePredicate attrs; - unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null); - defaultNativeBuildInputs = extraBuildInputs ++ [ ../../build-support/setup-hooks/move-docs.sh ../../build-support/setup-hooks/compress-man-pages.sh @@ -91,19 +89,22 @@ let , crossConfig ? null , meta ? {} , passthru ? {} + , pos ? null # position used in error messages and for meta.position , ... } @ attrs: let - pos = - if attrs.meta.description or null != null then - unsafeGetAttrPos "description" attrs.meta + pos' = + if pos != null then + pos + else if attrs.meta.description or null != null then + builtins.unsafeGetAttrPos "description" attrs.meta else - unsafeGetAttrPos "name" attrs; - pos' = if pos != null then "‘" + pos.file + ":" + toString pos.line + "’" else "«unknown-file»"; + builtins.unsafeGetAttrPos "name" attrs; + pos'' = if pos' != null then "‘" + pos'.file + ":" + toString pos'.line + "’" else "«unknown-file»"; throwEvalHelp = unfreeOrBroken: whatIsWrong: assert builtins.elem unfreeOrBroken ["Unfree" "Broken" "blacklisted"]; - throw ("Package ‘${attrs.name or "«name-missing»"}’ in ${pos'} ${whatIsWrong}, refusing to evaluate." + throw ("Package ‘${attrs.name or "«name-missing»"}’ in ${pos''} ${whatIsWrong}, refusing to evaluate." + (lib.strings.optionalString (unfreeOrBroken != "blacklisted") '' For `nixos-rebuild` you can set @@ -129,7 +130,7 @@ let assert licenseAllowed attrs; lib.addPassthru (derivation ( - (removeAttrs attrs ["meta" "passthru" "crossAttrs"]) + (removeAttrs attrs ["meta" "passthru" "crossAttrs" "pos"]) // { builder = attrs.realBuilder or shell; @@ -154,8 +155,8 @@ let # include it in the result, it *is* available to nix-env for # queries. We also a meta.position attribute here to # identify the source location of the package. - meta = meta // (if pos != null then { - position = pos.file + ":" + toString pos.line; + meta = meta // (if pos' != null then { + position = pos'.file + ":" + toString pos'.line; } else {}); inherit passthru; } // -- cgit 1.4.1