From f1eb2f35a6c06c22d5299eb39ab9ce5b88008605 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 4 Mar 2018 06:28:49 -0500 Subject: lib/tests: Add check-eval.nix to run simple tests. This can be used by evaluation-only tools to validate tests are still working. --- lib/tests/check-eval.nix | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lib/tests/check-eval.nix (limited to 'lib') diff --git a/lib/tests/check-eval.nix b/lib/tests/check-eval.nix new file mode 100644 index 000000000000..8bd7b605a39b --- /dev/null +++ b/lib/tests/check-eval.nix @@ -0,0 +1,7 @@ +# Throws an error if any of our lib tests fail. + +let tests = [ "misc" "systems" ]; + all = builtins.concatLists (map (f: import (./. + "/${f}.nix")) tests); +in if all == [] + then null + else throw (builtins.toJSON all) -- cgit 1.4.1 From 6da6accd303be776bb4e958da52046da86f9cb5c Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 22 May 2018 16:42:02 -0400 Subject: treewide: Remove uses of builtins.toPath. toPath has confusing semantics and is never necessary; it can always either just be omitted or replaced by pre-concatenating `/.`. It has been marked as "!!! obsolete?" for more than 10 years in a C++ comment, hopefully removing it will let us properly deprecate and, eventually, remove it. --- lib/strings.nix | 5 ++--- lib/tests/misc.nix | 4 ++-- nixos/lib/eval-config.nix | 2 +- nixos/modules/services/x11/desktop-managers/enlightenment.nix | 2 +- pkgs/build-support/fetchdocker/default.nix | 4 ++-- pkgs/development/mobile/androidenv/androidndk.nix | 2 +- .../darwin/apple-source-releases/libsecurity_generic/default.nix | 2 +- pkgs/servers/bird/default.nix | 2 +- pkgs/servers/monitoring/telegraf/default.nix | 2 +- pkgs/servers/nosql/influxdb/default.nix | 2 +- pkgs/tools/typesetting/tex/texlive/combine.nix | 2 +- 11 files changed, 14 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/strings.nix b/lib/strings.nix index e09ec42bfea2..2a61b1465cc2 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -492,7 +492,7 @@ rec { isStorePath = x: isCoercibleToString x && builtins.substring 0 1 (toString x) == "/" - && dirOf (builtins.toPath x) == builtins.storeDir; + && dirOf x == builtins.storeDir; /* Convert string to int Obviously, it is a bit hacky to use fromJSON that way. @@ -528,11 +528,10 @@ rec { */ readPathsFromFile = rootPath: file: let - root = toString rootPath; lines = lib.splitString "\n" (builtins.readFile file); removeComments = lib.filter (line: line != "" && !(lib.hasPrefix "#" line)); relativePaths = removeComments lines; - absolutePaths = builtins.map (path: builtins.toPath (root + "/" + path)) relativePaths; + absolutePaths = builtins.map (path: rootPath + "/${path}") relativePaths; in absolutePaths; diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index c683df7d7ca3..c0e1aaa248eb 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -97,7 +97,7 @@ runTests { storePathAppendix = isStorePath "${goodPath}/bin/python"; nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath))); - asPath = isStorePath (builtins.toPath goodPath); + asPath = isStorePath goodPath; otherPath = isStorePath "/something/else"; otherVals = { attrset = isStorePath {}; @@ -318,7 +318,7 @@ runTests { int = 42; bool = true; string = ''fno"rd''; - path = /. + "/foo"; # toPath returns a string + path = /. + "/foo"; null_ = null; function = x: x; functionArgs = { arg ? 4, foo }: arg; diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix index 97c79487df4c..d005fc61dc4e 100644 --- a/nixos/lib/eval-config.nix +++ b/nixos/lib/eval-config.nix @@ -28,7 +28,7 @@ let extraArgs_ = extraArgs; pkgs_ = pkgs; extraModules = let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH"; - in if e == "" then [] else [(import (builtins.toPath e))]; + in if e == "" then [] else [(import e)]; in let diff --git a/nixos/modules/services/x11/desktop-managers/enlightenment.nix b/nixos/modules/services/x11/desktop-managers/enlightenment.nix index da3287aaea6e..5c083a151ff3 100644 --- a/nixos/modules/services/x11/desktop-managers/enlightenment.nix +++ b/nixos/modules/services/x11/desktop-managers/enlightenment.nix @@ -61,7 +61,7 @@ in ''; }]; - security.wrappers = (import (builtins.toPath "${e.enlightenment}/e-wrappers.nix")).security.wrappers; + security.wrappers = (import "${e.enlightenment}/e-wrappers.nix").security.wrappers; environment.etc = singleton { source = xcfg.xkbDir; diff --git a/pkgs/build-support/fetchdocker/default.nix b/pkgs/build-support/fetchdocker/default.nix index ae3ae4185e05..b54e4141afc9 100644 --- a/pkgs/build-support/fetchdocker/default.nix +++ b/pkgs/build-support/fetchdocker/default.nix @@ -22,8 +22,8 @@ assert null == lib.findFirst (c: "/"==c) null (lib.stringToCharacters repository assert null == lib.findFirst (c: "/"==c) null (lib.stringToCharacters imageName); let - # Abuse `builtins.toPath` to collapse possible double slashes - repoTag0 = builtins.toString (builtins.toPath "/${stripScheme registry}/${repository}/${imageName}"); + # Abuse paths to collapse possible double slashes + repoTag0 = builtins.toString (/. + "/${stripScheme registry}/${repository}/${imageName}"); repoTag1 = lib.removePrefix "/" repoTag0; layers = builtins.map stripNixStore imageLayers; diff --git a/pkgs/development/mobile/androidenv/androidndk.nix b/pkgs/development/mobile/androidenv/androidndk.nix index 78e278be2376..1c0f75215e76 100644 --- a/pkgs/development/mobile/androidenv/androidndk.nix +++ b/pkgs/development/mobile/androidenv/androidndk.nix @@ -50,7 +50,7 @@ stdenv.mkDerivation rec { patch -p1 \ --no-backup-if-mismatch \ - -d $out/libexec/${name} < ${ ./. + builtins.toPath ("/make_standalone_toolchain.py_" + "${version}" + ".patch") } + -d $out/libexec/${name} < ${ ./. + "/make_standalone_toolchain.py_${version}.patch" } wrapProgram ${pkg_path}/build/tools/make_standalone_toolchain.py --prefix PATH : "${runtime_paths}" '' } diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/default.nix index 93857ea792c2..2efdc5abeb31 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/default.nix @@ -1,7 +1,7 @@ { appleDerivation_, applePackage, pkgs, stdenv }: name: version: sha256: args: let n = stdenv.lib.removePrefix "lib" name; - makeFile = ../. + builtins.toPath "/${name}/GNUmakefile"; + makeFile = ../. + "/${name}/GNUmakefile"; appleDerivation = appleDerivation_ name version sha256; in applePackage name version sha256 (args // { appleDerivation = a: diff --git a/pkgs/servers/bird/default.nix b/pkgs/servers/bird/default.nix index 94bd92abb4f8..f44ae83ec03a 100644 --- a/pkgs/servers/bird/default.nix +++ b/pkgs/servers/bird/default.nix @@ -17,7 +17,7 @@ let buildInputs = [ readline ]; patches = [ - (./. + (builtins.toPath "/dont-create-sysconfdir-${builtins.substring 0 1 version}.patch")) + (./. + "/dont-create-sysconfdir-${builtins.substring 0 1 version}.patch") ]; configureFlags = [ diff --git a/pkgs/servers/monitoring/telegraf/default.nix b/pkgs/servers/monitoring/telegraf/default.nix index b7879cc763aa..dc219416fcb9 100644 --- a/pkgs/servers/monitoring/telegraf/default.nix +++ b/pkgs/servers/monitoring/telegraf/default.nix @@ -19,7 +19,7 @@ buildGoPackage rec { -X main.version=${version} '' ]; - goDeps = ./. + builtins.toPath "/deps-${version}.nix"; + goDeps = ./. + "/deps-${version}.nix"; meta = with lib; { description = "The plugin-driven server agent for collecting & reporting metrics."; diff --git a/pkgs/servers/nosql/influxdb/default.nix b/pkgs/servers/nosql/influxdb/default.nix index 972bd53d95ee..466bf6a60a06 100644 --- a/pkgs/servers/nosql/influxdb/default.nix +++ b/pkgs/servers/nosql/influxdb/default.nix @@ -20,7 +20,7 @@ buildGoPackage rec { excludedPackages = "test"; # Generated with the nix2go - goDeps = ./. + builtins.toPath "/deps-${version}.nix"; + goDeps = ./. + "/deps-${version}.nix"; meta = with lib; { description = "An open-source distributed time series database"; diff --git a/pkgs/tools/typesetting/tex/texlive/combine.nix b/pkgs/tools/typesetting/tex/texlive/combine.nix index 35fee64ba54f..f1a20552d382 100644 --- a/pkgs/tools/typesetting/tex/texlive/combine.nix +++ b/pkgs/tools/typesetting/tex/texlive/combine.nix @@ -35,7 +35,7 @@ let mkUniquePkgs = pkgs: fastUnique (a: b: a < b) # highlighting hack: > # here we deal with those dummy packages needed for hyphenation filtering - (map (p: if lib.isDerivation p then builtins.toPath p else "") pkgs); + (map (p: if lib.isDerivation p then p.outPath else "") pkgs); in buildEnv { name = "texlive-${extraName}-${bin.texliveYear}"; -- cgit 1.4.1 From 608730af4404f40586ba1e764fbc8576451ec513 Mon Sep 17 00:00:00 2001 From: Vladimír Čunát Date: Mon, 3 Sep 2018 14:10:54 +0200 Subject: lib/trivial.nix: fix missing parens Broken in 62dca7c9a; the tricky thing is that it depends on nix version. Explanation: https://github.com/NixOS/nix/issues/629 --- lib/trivial.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/trivial.nix b/lib/trivial.nix index b75e81eb7352..e702b8cdcc9f 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -36,18 +36,18 @@ rec { /* bitwise “and” */ bitAnd = builtins.bitAnd - or import ./zip-int-bits.nix - (a: b: if a==1 && b==1 then 1 else 0); + or (import ./zip-int-bits.nix + (a: b: if a==1 && b==1 then 1 else 0)); /* bitwise “or” */ bitOr = builtins.bitOr - or import ./zip-int-bits.nix - (a: b: if a==1 || b==1 then 1 else 0); + or (import ./zip-int-bits.nix + (a: b: if a==1 || b==1 then 1 else 0)); /* bitwise “xor” */ bitXor = builtins.bitXor - or import ./zip-int-bits.nix - (a: b: if a!=b then 1 else 0); + or (import ./zip-int-bits.nix + (a: b: if a!=b then 1 else 0)); /* bitwise “not” */ bitNot = builtins.sub (-1); -- cgit 1.4.1 From 7422953eb0619d34a0ad38e76926dfe05c40ff03 Mon Sep 17 00:00:00 2001 From: Markus Kowalewski Date: Mon, 3 Sep 2018 21:52:21 +0200 Subject: lsof: add license + update homepage lib/licenses: add purdue style BSD license --- lib/licenses.nix | 5 +++++ pkgs/development/tools/misc/lsof/default.nix | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/licenses.nix b/lib/licenses.nix index c442d74c857c..6f0e4217c196 100644 --- a/lib/licenses.nix +++ b/lib/licenses.nix @@ -546,6 +546,11 @@ lib.mapAttrs (n: v: v // { shortName = n; }) rec { fullName = "Public Domain"; }; + purdueBsd = { + fullName = " Purdue BSD-Style License"; # also know as lsof license + url = https://enterprise.dejacode.com/licenses/public/purdue-bsd; + }; + qpl = spdx { spdxId = "QPL-1.0"; fullName = "Q Public License 1.0"; diff --git a/pkgs/development/tools/misc/lsof/default.nix b/pkgs/development/tools/misc/lsof/default.nix index 28c2660ac3d7..0a5a3c487810 100644 --- a/pkgs/development/tools/misc/lsof/default.nix +++ b/pkgs/development/tools/misc/lsof/default.nix @@ -51,15 +51,16 @@ stdenv.mkDerivation rec { cp lsof $out/bin ''; - meta = { - homepage = ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/; + meta = with stdenv.lib; { + homepage = https://people.freebsd.org/~abe/; description = "A tool to list open files"; longDescription = '' List open files. Can show what process has opened some file, socket (IPv6/IPv4/UNIX local), or partition (by opening a file from it). ''; - maintainers = [ stdenv.lib.maintainers.dezgeg ]; - platforms = stdenv.lib.platforms.unix; + maintainers = [ maintainers.dezgeg ]; + platforms = platforms.unix; + license = licenses.purdueBsd; }; } -- cgit 1.4.1 From 0e2aa97f3aa1341693885511fd78394b828c6477 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Thu, 26 Jul 2018 20:45:55 +0200 Subject: lib/trivial: add assertMsg --- lib/default.nix | 3 ++- lib/trivial.nix | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/default.nix b/lib/default.nix index dd6fcec75e21..fd3be3c6f4bc 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -59,7 +59,8 @@ let inherit (trivial) id const concat or and bitAnd bitOr bitXor bitNot boolToString mergeAttrs flip mapNullable inNixShell min max importJSON warn info nixpkgsVersion version mod compare - splitByAndCompare functionArgs setFunctionArgs isFunction; + splitByAndCompare functionArgs setFunctionArgs isFunction + assertMsg; inherit (fixedPoints) fix fix' extends composeExtensions makeExtensible makeExtensibleWithCustomName; diff --git a/lib/trivial.nix b/lib/trivial.nix index e702b8cdcc9f..bba284548d98 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -188,6 +188,26 @@ rec { warn = msg: builtins.trace "WARNING: ${msg}"; info = msg: builtins.trace "INFO: ${msg}"; + /* Print a trace message if pred is false. + Intended to be used to augment asserts with helpful error messages. + + Example: + assertMsg false "nope" + => false + stderr> trace: nope + + assert (assertMsg ("foo" == "bar") "foo is not bar, silly"); "" + stderr> trace: foo is not bar, silly + stderr> assert failed at … + + Type: + assertMsg :: Bool -> String -> Bool + */ + assertMsg = pred: msg: + if pred + then true + else builtins.trace msg false; + ## Function annotations -- cgit 1.4.1 From 320cdecd1697020cb367adc1f8408dbf689ca254 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Mon, 6 Aug 2018 01:35:48 +0200 Subject: lib/trivial: add assertOneOf --- lib/default.nix | 2 +- lib/trivial.nix | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/default.nix b/lib/default.nix index fd3be3c6f4bc..358c8ca0b8f9 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -60,7 +60,7 @@ let boolToString mergeAttrs flip mapNullable inNixShell min max importJSON warn info nixpkgsVersion version mod compare splitByAndCompare functionArgs setFunctionArgs isFunction - assertMsg; + assertMsg assertOneOf; inherit (fixedPoints) fix fix' extends composeExtensions makeExtensible makeExtensibleWithCustomName; diff --git a/lib/trivial.nix b/lib/trivial.nix index bba284548d98..f1001ee10ca3 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -203,11 +203,29 @@ rec { Type: assertMsg :: Bool -> String -> Bool */ + # TODO(Profpatsch): add tests that check stderr assertMsg = pred: msg: if pred then true else builtins.trace msg false; + /* Specialized `assertMsg` for checking if val is one of the elements + of a list. Useful for checking enums. + + Example: + let sslLibrary = "libressl" + in assertOneOf "sslLibrary" sslLibrary [ "openssl" "bearssl" ] + => false + stderr> trace: sslLibrary must be one of "openssl", "bearssl", but is: "libressl" + + Type: + assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool + */ + assertOneOf = name: val: xs: assertMsg + (lib.elem val xs) + "${name} must be one of ${ + lib.generators.toPretty {} xs}, but is: ${ + lib.generators.toPretty {} val}"; ## Function annotations -- cgit 1.4.1 From 3e45b61a9920466a8ea06b8ad9350d56ade435bc Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Mon, 6 Aug 2018 01:36:09 +0200 Subject: lib/trivial: add a few examples of usage of assertMsg/assertOneOf --- lib/lists.nix | 7 +++++-- lib/strings.nix | 7 +++++-- lib/types.nix | 8 ++++++-- pkgs/applications/misc/lilyterm/default.nix | 5 ++--- pkgs/applications/science/math/ripser/default.nix | 3 ++- 5 files changed, 20 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/lists.nix b/lib/lists.nix index 288882924fff..9a75f179e964 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -509,7 +509,8 @@ rec { => 3 */ last = list: - assert list != []; elemAt list (length list - 1); + assert assertMsg (list != []) "lists.last: list must not be empty!"; + elemAt list (length list - 1); /* Return all elements but the last @@ -517,7 +518,9 @@ rec { init [ 1 2 3 ] => [ 1 2 ] */ - init = list: assert list != []; take (length list - 1) list; + init = list: + assert assertMsg (list != []) "lists.init: list must not be empty!"; + take (length list - 1) list; /* return the image of the cross product of some lists by a function diff --git a/lib/strings.nix b/lib/strings.nix index 833f69d2fbfe..0c4095bb55cd 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -410,7 +410,7 @@ rec { components = splitString "/" url; filename = lib.last components; name = builtins.head (splitString sep filename); - in assert name != filename; name; + in assert name != filename; name; /* Create an --{enable,disable}- string that can be passed to standard GNU Autoconf scripts. @@ -468,7 +468,10 @@ rec { strw = lib.stringLength str; reqWidth = width - (lib.stringLength filler); in - assert strw <= width; + assert lib.assertMsg (strw <= width) + "fixedWidthString: requested string length (${ + toString width}) must not be shorter than actual length (${ + toString strw})"; if strw == width then str else filler + fixedWidthString reqWidth filler str; /* Format a number adding leading zeroes up to fixed width. diff --git a/lib/types.nix b/lib/types.nix index 4d6ac51c8988..441af98cb9b6 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -119,7 +119,9 @@ rec { let betweenDesc = lowest: highest: "${toString lowest} and ${toString highest} (both inclusive)"; - between = lowest: highest: assert lowest <= highest; + between = lowest: highest: + assert lib.assertMsg (lowest <= highest) + "ints.between: lowest must be smaller than highest"; addCheck int (x: x >= lowest && x <= highest) // { name = "intBetween"; description = "integer between ${betweenDesc lowest highest}"; @@ -439,7 +441,9 @@ rec { # Either value of type `finalType` or `coercedType`, the latter is # converted to `finalType` using `coerceFunc`. coercedTo = coercedType: coerceFunc: finalType: - assert coercedType.getSubModules == null; + assert assertMsg (coercedType.getSubModules == null) + "coercedTo: coercedType must not have submodules (it’s a ${ + coercedType.description})"; mkOptionType rec { name = "coercedTo"; description = "${finalType.description} or ${coercedType.description} convertible to it"; diff --git a/pkgs/applications/misc/lilyterm/default.nix b/pkgs/applications/misc/lilyterm/default.nix index 72cb1e85802a..948ae7b14a11 100644 --- a/pkgs/applications/misc/lilyterm/default.nix +++ b/pkgs/applications/misc/lilyterm/default.nix @@ -1,13 +1,12 @@ -{ stdenv, fetchurl, fetchFromGitHub +{ stdenv, lib, fetchurl, fetchFromGitHub , pkgconfig , autoconf, automake, intltool, gettext , gtk, vte -# "stable" or "git" , flavour ? "stable" }: -assert flavour == "stable" || flavour == "git"; +assert lib.assertOneOf "flavour" flavour [ "stable" "git" ]; let stuff = diff --git a/pkgs/applications/science/math/ripser/default.nix b/pkgs/applications/science/math/ripser/default.nix index 21948a279d07..5e0b7fc300ba 100644 --- a/pkgs/applications/science/math/ripser/default.nix +++ b/pkgs/applications/science/math/ripser/default.nix @@ -8,7 +8,8 @@ with stdenv.lib; -assert elem fileFormat ["lowerTriangularCsv" "upperTriangularCsv" "dipha"]; +assert assertOneOf "fileFormat" fileFormat + ["lowerTriangularCsv" "upperTriangularCsv" "dipha"]; assert useGoogleHashmap -> sparsehash != null; let -- cgit 1.4.1 From efdf618330a22f837f0e5e446028e918a5b4dd8a Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Wed, 8 Aug 2018 19:26:52 +0200 Subject: lib: move assertMsg and assertOneOf to their own library file Since the `assertOneOf` uses `lib.generators`, they are not really trivial anymore and should go into their own library file. --- lib/asserts.nix | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/default.nix | 9 +++++---- lib/lists.nix | 4 ++-- lib/trivial.nix | 40 +--------------------------------------- lib/types.nix | 2 +- 5 files changed, 53 insertions(+), 46 deletions(-) create mode 100644 lib/asserts.nix (limited to 'lib') diff --git a/lib/asserts.nix b/lib/asserts.nix new file mode 100644 index 000000000000..8a5f1fb3feb7 --- /dev/null +++ b/lib/asserts.nix @@ -0,0 +1,44 @@ +{ lib }: + +rec { + + /* Print a trace message if pred is false. + Intended to be used to augment asserts with helpful error messages. + + Example: + assertMsg false "nope" + => false + stderr> trace: nope + + assert (assertMsg ("foo" == "bar") "foo is not bar, silly"); "" + stderr> trace: foo is not bar, silly + stderr> assert failed at … + + Type: + assertMsg :: Bool -> String -> Bool + */ + # TODO(Profpatsch): add tests that check stderr + assertMsg = pred: msg: + if pred + then true + else builtins.trace msg false; + + /* Specialized `assertMsg` for checking if val is one of the elements + of a list. Useful for checking enums. + + Example: + let sslLibrary = "libressl" + in assertOneOf "sslLibrary" sslLibrary [ "openssl" "bearssl" ] + => false + stderr> trace: sslLibrary must be one of "openssl", "bearssl", but is: "libressl" + + Type: + assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool + */ + assertOneOf = name: val: xs: assertMsg + (lib.elem val xs) + "${name} must be one of ${ + lib.generators.toPretty {} xs}, but is: ${ + lib.generators.toPretty {} val}"; + +} diff --git a/lib/default.nix b/lib/default.nix index 358c8ca0b8f9..d7a05fec8338 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -38,10 +38,11 @@ let systems = callLibs ./systems; # misc + asserts = callLibs ./asserts.nix; debug = callLibs ./debug.nix; - generators = callLibs ./generators.nix; misc = callLibs ./deprecated.nix; + # domain-specific fetchers = callLibs ./fetchers.nix; @@ -59,9 +60,7 @@ let inherit (trivial) id const concat or and bitAnd bitOr bitXor bitNot boolToString mergeAttrs flip mapNullable inNixShell min max importJSON warn info nixpkgsVersion version mod compare - splitByAndCompare functionArgs setFunctionArgs isFunction - assertMsg assertOneOf; - + splitByAndCompare functionArgs setFunctionArgs isFunction; inherit (fixedPoints) fix fix' extends composeExtensions makeExtensible makeExtensibleWithCustomName; inherit (attrsets) attrByPath hasAttrByPath setAttrByPath @@ -118,6 +117,8 @@ let unknownModule mkOption; inherit (types) isType setType defaultTypeMerge defaultFunctor isOptionType mkOptionType; + inherit (asserts) + assertMsg assertOneOf; inherit (debug) addErrorContextToAttrs traceIf traceVal traceValFn traceXMLVal traceXMLValMarked traceSeq traceSeqN traceValSeq traceValSeqFn traceValSeqN traceValSeqNFn traceShowVal diff --git a/lib/lists.nix b/lib/lists.nix index 9a75f179e964..9ecd8f220038 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -509,7 +509,7 @@ rec { => 3 */ last = list: - assert assertMsg (list != []) "lists.last: list must not be empty!"; + assert lib.assertMsg (list != []) "lists.last: list must not be empty!"; elemAt list (length list - 1); /* Return all elements but the last @@ -519,7 +519,7 @@ rec { => [ 1 2 ] */ init = list: - assert assertMsg (list != []) "lists.init: list must not be empty!"; + assert lib.assertMsg (list != []) "lists.init: list must not be empty!"; take (length list - 1) list; diff --git a/lib/trivial.nix b/lib/trivial.nix index f1001ee10ca3..b1eea0bf1247 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -171,7 +171,7 @@ rec { builtins.fromJSON (builtins.readFile path); - ## Warnings and asserts + ## Warnings /* See https://github.com/NixOS/nix/issues/749. Eventually we'd like these to expand to Nix builtins that carry metadata so that Nix can filter out @@ -188,44 +188,6 @@ rec { warn = msg: builtins.trace "WARNING: ${msg}"; info = msg: builtins.trace "INFO: ${msg}"; - /* Print a trace message if pred is false. - Intended to be used to augment asserts with helpful error messages. - - Example: - assertMsg false "nope" - => false - stderr> trace: nope - - assert (assertMsg ("foo" == "bar") "foo is not bar, silly"); "" - stderr> trace: foo is not bar, silly - stderr> assert failed at … - - Type: - assertMsg :: Bool -> String -> Bool - */ - # TODO(Profpatsch): add tests that check stderr - assertMsg = pred: msg: - if pred - then true - else builtins.trace msg false; - - /* Specialized `assertMsg` for checking if val is one of the elements - of a list. Useful for checking enums. - - Example: - let sslLibrary = "libressl" - in assertOneOf "sslLibrary" sslLibrary [ "openssl" "bearssl" ] - => false - stderr> trace: sslLibrary must be one of "openssl", "bearssl", but is: "libressl" - - Type: - assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool - */ - assertOneOf = name: val: xs: assertMsg - (lib.elem val xs) - "${name} must be one of ${ - lib.generators.toPretty {} xs}, but is: ${ - lib.generators.toPretty {} val}"; ## Function annotations diff --git a/lib/types.nix b/lib/types.nix index 441af98cb9b6..4e44e7521c4b 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -441,7 +441,7 @@ rec { # Either value of type `finalType` or `coercedType`, the latter is # converted to `finalType` using `coerceFunc`. coercedTo = coercedType: coerceFunc: finalType: - assert assertMsg (coercedType.getSubModules == null) + assert lib.assertMsg (coercedType.getSubModules == null) "coercedTo: coercedType must not have submodules (it’s a ${ coercedType.description})"; mkOptionType rec { -- cgit 1.4.1 From 6d6cbd316d5f5c12c002c86b919d1f923b0d87fe Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Mon, 10 Sep 2018 11:59:51 +0200 Subject: pythonmagick: fix build (#46469) The original build broke with the following linker issue: ``` CXXLD _PythonMagick.la /nix/store/h0lbngpv6ln56hjj59i6l77vxq25flbz-binutils-2.30/bin/ld: cannot find -l-L/nix/store/4gh6ynzsd5ndx37hmkl62xa8z30k43y1-imagemagick-6.9.9-34/lib collect2: error: ld returned 1 exit status ``` This happens since `BOOST_PYTHON_LIB` wasn't set properly, however `_PythonMagick.la` was linked with `-l$(BOOST_PYTHON_LIB) $(MAGICK_LIBS)`. With an empty `BOOST_PYTHON_LIB` the linker got confused. To work around this, the `boost` library directory needs to be specified explicitly. To ensure that the changes take effect, the original `configure` script shipped with `$src` needs to be removed and recreated using the `autoreconfHook`. Additionally the `imagemagick` license (https://spdx.org/licenses/ImageMagick.html) needs to be added to `lib/licenses.nix` to document the proper license of `pythonmagick` in the meta section. --- lib/licenses.nix | 5 +++++ pkgs/applications/graphics/PythonMagick/default.nix | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/licenses.nix b/lib/licenses.nix index 6f0e4217c196..c4db280645a4 100644 --- a/lib/licenses.nix +++ b/lib/licenses.nix @@ -355,6 +355,11 @@ lib.mapAttrs (n: v: v // { shortName = n; }) rec { fullName = "Independent JPEG Group License"; }; + imagemagick = spdx { + fullName = "ImageMagick License"; + spdxId = "imagemagick"; + }; + inria-compcert = { fullName = "INRIA Non-Commercial License Agreement for the CompCert verified compiler"; url = "http://compcert.inria.fr/doc/LICENSE"; diff --git a/pkgs/applications/graphics/PythonMagick/default.nix b/pkgs/applications/graphics/PythonMagick/default.nix index f0b4a991f74a..938df76e2572 100644 --- a/pkgs/applications/graphics/PythonMagick/default.nix +++ b/pkgs/applications/graphics/PythonMagick/default.nix @@ -1,6 +1,6 @@ # This expression provides Python bindings to ImageMagick. Python libraries are supposed to be called via `python-packages.nix`. -{stdenv, fetchurl, python, boost, pkgconfig, imagemagick}: +{ stdenv, fetchurl, python, pkgconfig, imagemagick, autoreconfHook }: stdenv.mkDerivation rec { name = "pythonmagick-${version}"; @@ -11,10 +11,18 @@ stdenv.mkDerivation rec { sha256 = "137278mfb5079lns2mmw73x8dhpzgwha53dyl00mmhj2z25varpn"; }; - nativeBuildInputs = [ pkgconfig ]; - buildInputs = [python boost imagemagick]; + postPatch = '' + rm configure + ''; - meta = { + configureFlags = [ "--with-boost=${python.pkgs.boost}" ]; + + nativeBuildInputs = [ pkgconfig autoreconfHook ]; + buildInputs = [ python python.pkgs.boost imagemagick ]; + + meta = with stdenv.lib; { homepage = http://www.imagemagick.org/script/api.php; + license = licenses.imagemagick; + description = "PythonMagick provides object oriented bindings for the ImageMagick Library."; }; } -- cgit 1.4.1