diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2019-11-25 00:23:07 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2019-11-25 00:23:07 +0000 |
commit | 6bc456c91c6a556e905852d9a13034ed1932ea3d (patch) | |
tree | 69df19159e5e7df77ae939041f8f6e941c5ef056 /lib | |
parent | ea9a2c5ec21bf088bbdef036238fa67cdc85b073 (diff) | |
parent | 4273a6adcc9327b9dc0e09e9fe205b4861c15679 (diff) |
Merge remote-tracking branch 'upstream/master' into ghcjs-cross-without-cc
Diffstat (limited to 'lib')
-rw-r--r-- | lib/attrsets.nix | 2 | ||||
-rw-r--r-- | lib/customisation.nix | 37 | ||||
-rw-r--r-- | lib/default.nix | 6 | ||||
-rw-r--r-- | lib/licenses.nix | 11 | ||||
-rw-r--r-- | lib/modules.nix | 14 | ||||
-rw-r--r-- | lib/systems/default.nix | 2 | ||||
-rw-r--r-- | lib/systems/doubles.nix | 3 | ||||
-rw-r--r-- | lib/systems/examples.nix | 6 | ||||
-rw-r--r-- | lib/systems/inspect.nix | 1 | ||||
-rw-r--r-- | lib/systems/parse.nix | 3 | ||||
-rw-r--r-- | lib/tests/misc.nix | 40 | ||||
-rw-r--r-- | lib/trivial.nix | 39 | ||||
-rw-r--r-- | lib/versions.nix | 12 |
13 files changed, 145 insertions, 31 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix index d374d229f597..086c3d746fc1 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -354,7 +354,7 @@ rec { => { a = ["x" "y"]; b = ["z"] } */ zipAttrsWith = f: sets: zipAttrsWithNames (concatMap attrNames sets) f sets; - /* Like `zipAttrsWith' with `(name: values: value)' as the function. + /* Like `zipAttrsWith' with `(name: values: values)' as the function. Example: zipAttrs [{a = "x";} {a = "y"; b = "z";}] diff --git a/lib/customisation.nix b/lib/customisation.nix index 3be36fcd719b..ac234e3b8c6f 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -66,22 +66,31 @@ rec { */ makeOverridable = f: origArgs: let - ff = f origArgs; + result = f origArgs; + + # Creates a functor with the same arguments as f + copyArgs = g: lib.setFunctionArgs g (lib.functionArgs f); + # Changes the original arguments with (potentially a function that returns) a set of new attributes overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs); + + # Re-call the function but with different arguments + overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs)); + # Change the result of the function call by applying g to it + overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs; in - if builtins.isAttrs ff then (ff // { - override = newArgs: makeOverridable f (overrideWith newArgs); - overrideDerivation = fdrv: - makeOverridable (args: overrideDerivation (f args) fdrv) origArgs; - ${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv: - makeOverridable (args: (f args).overrideAttrs fdrv) origArgs; - }) - else if lib.isFunction ff then { - override = newArgs: makeOverridable f (overrideWith newArgs); - __functor = self: ff; - overrideDerivation = throw "overrideDerivation not yet supported for functors"; - } - else ff; + if builtins.isAttrs result then + result // { + override = overrideArgs; + overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv); + ${if result ? overrideAttrs then "overrideAttrs" else null} = fdrv: + overrideResult (x: x.overrideAttrs fdrv); + } + else if lib.isFunction result then + # Transform the result into a functor while propagating its arguments + lib.setFunctionArgs result (lib.functionArgs result) // { + override = overrideArgs; + } + else result; /* Call the package function in the file `fn' with the required diff --git a/lib/default.nix b/lib/default.nix index 0e840dd6c9e6..8af531525860 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -57,8 +57,8 @@ let hasAttr head isAttrs isBool isInt isList isString length lessThan listToAttrs pathExists readFile replaceStrings seq stringLength sub substring tail; - inherit (trivial) id const concat or and bitAnd bitOr bitXor bitNot - boolToString mergeAttrs flip mapNullable inNixShell min max + inherit (trivial) id const pipe concat or and bitAnd bitOr bitXor + bitNot boolToString mergeAttrs flip mapNullable inNixShell min max importJSON warn info showWarnings nixpkgsVersion version mod compare splitByAndCompare functionArgs setFunctionArgs isFunction; inherit (fixedPoints) fix fix' converge extends composeExtensions @@ -135,5 +135,7 @@ let mergeAttrsByFuncDefaultsClean mergeAttrBy fakeSha256 fakeSha512 nixType imap; + inherit (versions) + splitVersion; }); in lib diff --git a/lib/licenses.nix b/lib/licenses.nix index 83e1ec7748d5..986b7fa1fdd9 100644 --- a/lib/licenses.nix +++ b/lib/licenses.nix @@ -218,9 +218,9 @@ lib.mapAttrs (n: v: v // { shortName = n; }) { fullName = "Common Public License 1.0"; }; - curl = { - fullName = "MIT/X11 derivate"; - url = "https://curl.haxx.se/docs/copyright.html"; + curl = spdx { + spdxId = "curl"; + fullName = "curl License"; }; doc = spdx { @@ -613,6 +613,11 @@ lib.mapAttrs (n: v: v // { shortName = n; }) { url = https://enterprise.dejacode.com/licenses/public/purdue-bsd; }; + qhull = spdx { + spdxId = "Qhull"; + fullName = "Qhull License"; + }; + qpl = spdx { spdxId = "QPL-1.0"; fullName = "Q Public License 1.0"; diff --git a/lib/modules.nix b/lib/modules.nix index c3c903c1dfa8..44db77b5d1c6 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -326,6 +326,8 @@ rec { # The value with a check that it is defined valueDefined = if res.isDefined then res.mergedValue else + # (nixos-option detects this specific error message and gives it special + # handling. If changed here, please change it there too.) throw "The option `${showOption loc}' is used but not defined."; # Apply the 'apply' function to the merged value. This allows options to @@ -591,12 +593,16 @@ rec { { options, ... }: { options = setAttrByPath optionName (mkOption { visible = false; + apply = x: throw "The option `${showOption optionName}' can no longer be used since it's been removed. ${replacementInstructions}"; }); - config.warnings = - let opt = getAttrFromPath optionName options; in - optional opt.isDefined '' + config.assertions = + let opt = getAttrFromPath optionName options; in [{ + assertion = !opt.isDefined; + message = '' The option definition `${showOption optionName}' in ${showFiles opt.files} no longer has any effect; please remove it. - ${replacementInstructions}''; + ${replacementInstructions} + ''; + }]; }; /* Return a module that causes a warning to be shown if the diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 0c0cdf1f11b1..026117cc34fd 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -37,6 +37,7 @@ rec { else if final.isAndroid then "bionic" else if final.isLinux /* default */ then "glibc" else if final.isMsp430 then "newlib" + else if final.isVc4 then "newlib" else if final.isAvr then "avrlibc" else if final.isNetBSD then "nblibc" # TODO(@Ericson2314) think more about other operating systems @@ -79,6 +80,7 @@ rec { else if final.isAarch64 then "arm64" else if final.isx86_32 then "x86" else if final.isx86_64 then "ia64" + else if final.isMips then "mips" else final.parsed.cpu.name; qemuArch = diff --git a/lib/systems/doubles.nix b/lib/systems/doubles.nix index f07e9da33bcb..59bb095a28f5 100644 --- a/lib/systems/doubles.nix +++ b/lib/systems/doubles.nix @@ -26,7 +26,7 @@ let "riscv32-linux" "riscv64-linux" - "aarch64-none" "avr-none" "arm-none" "i686-none" "x86_64-none" "powerpc-none" "msp430-none" "riscv64-none" "riscv32-none" + "aarch64-none" "avr-none" "arm-none" "i686-none" "x86_64-none" "powerpc-none" "msp430-none" "riscv64-none" "riscv32-none" "vc4-none" "js-ghcjs" ]; @@ -47,6 +47,7 @@ in { x86_64 = filterDoubles predicates.isx86_64; mips = filterDoubles predicates.isMips; riscv = filterDoubles predicates.isRiscV; + vc4 = filterDoubles predicates.isVc4; cygwin = filterDoubles predicates.isCygwin; darwin = filterDoubles predicates.isDarwin; diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 585156c24759..cb8bc3de6c48 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -118,6 +118,12 @@ rec { config = "avr"; }; + vc4 = { + config = "vc4-elf"; + libc = "newlib"; + platform = {}; + }; + arm-embedded = { config = "arm-none-eabi"; libc = "newlib"; diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 8a983b3d3637..d1980c6dff81 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -21,6 +21,7 @@ rec { isSparc = { cpu = { family = "sparc"; }; }; isWasm = { cpu = { family = "wasm"; }; }; isMsp430 = { cpu = { family = "msp430"; }; }; + isVc4 = { cpu = { family = "vc4"; }; }; isAvr = { cpu = { family = "avr"; }; }; isAlpha = { cpu = { family = "alpha"; }; }; isJavaScript = { cpu = cpuTypes.js; }; diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 5a3805cf997a..6a02dbb51528 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -112,6 +112,8 @@ rec { msp430 = { bits = 16; significantByte = littleEndian; family = "msp430"; }; avr = { bits = 8; family = "avr"; }; + vc4 = { bits = 32; significantByte = littleEndian; family = "vc4"; }; + js = { bits = 32; significantByte = littleEndian; family = "js"; }; }; @@ -330,6 +332,7 @@ rec { } ]; }; + gnuabi64 = { abi = "64"; }; musleabi = { float = "soft"; }; musleabihf = { float = "hard"; }; diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index d8f412d3fc49..b064faa1e1ba 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -18,6 +18,31 @@ runTests { expected = 2; }; + testPipe = { + expr = pipe 2 [ + (x: x + 2) # 2 + 2 = 4 + (x: x * 2) # 4 * 2 = 8 + ]; + expected = 8; + }; + + testPipeEmpty = { + expr = pipe 2 []; + expected = 2; + }; + + testPipeStrings = { + expr = pipe [ 3 4 ] [ + (map toString) + (map (s: s + "\n")) + concatStrings + ]; + expected = '' + 3 + 4 + ''; + }; + /* testOr = { expr = or true false; @@ -102,6 +127,21 @@ runTests { expected = [ "2001" "db8" "0" "0042" "" "8a2e" "370" "" ]; }; + testSplitVersionSingle = { + expr = versions.splitVersion "1"; + expected = [ "1" ]; + }; + + testSplitVersionDouble = { + expr = versions.splitVersion "1.2"; + expected = [ "1" "2" ]; + }; + + testSplitVersionTriple = { + expr = versions.splitVersion "1.2.3"; + expected = [ "1" "2" "3" ]; + }; + testIsStorePath = { expr = let goodPath = diff --git a/lib/trivial.nix b/lib/trivial.nix index f2710a6f0338..3a25e31fb052 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -29,6 +29,43 @@ rec { # Value to ignore y: x; + /* Pipes a value through a list of functions, left to right. + + Type: pipe :: a -> [<functions>] -> <return type of last function> + Example: + pipe 2 [ + (x: x + 2) # 2 + 2 = 4 + (x: x * 2) # 4 * 2 = 8 + ] + => 8 + + # ideal to do text transformations + pipe [ "a/b" "a/c" ] [ + + # create the cp command + (map (file: ''cp "${src}/${file}" $out\n'')) + + # concatenate all commands into one string + lib.concatStrings + + # make that string into a nix derivation + (pkgs.runCommand "copy-to-out" {}) + + ] + => <drv which copies all files to $out> + + The output type of each function has to be the input type + of the next function, and the last function returns the + final value. + */ + pipe = val: functions: + let reverseApply = x: f: f x; + in builtins.foldl' reverseApply val functions; + /* note please don’t add a function like `compose = flip pipe`. + This would confuse users, because the order of the functions + in the list is not clear. With pipe, it’s obvious that it + goes first-to-last. With `compose`, not so much. + */ ## Named versions corresponding to some builtin operators. @@ -134,7 +171,7 @@ rec { On each release the first letter is bumped and a new animal is chosen starting with that new letter. */ - codeName = "Loris"; + codeName = "Markhor"; /* Returns the current nixpkgs version suffix as string. */ versionSuffix = diff --git a/lib/versions.nix b/lib/versions.nix index 2c05445b3dd0..0e9d81ac78b1 100644 --- a/lib/versions.nix +++ b/lib/versions.nix @@ -1,13 +1,15 @@ /* Version string functions. */ { lib }: -let +rec { - splitVersion = builtins.splitVersion or (lib.splitString "."); - -in + /* Break a version string into its component parts. -{ + Example: + splitVersion "1.2.3" + => ["1" "2" "3"] + */ + splitVersion = builtins.splitVersion or (lib.splitString "."); /* Get the major version string from a string. |