diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-04-06 16:18:51 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-04-06 16:18:51 +0000 |
commit | 9afbeb71219925d54b72b0170b2e3be76bad1e28 (patch) | |
tree | d80c6bf0441de5412475859de320806b0e5a454c /nixpkgs/lib | |
parent | 75eafe97f7df0d653bec67f3962214d7c357831f (diff) | |
parent | ae6bdcc53584aaf20211ce1814bea97ece08a248 (diff) | |
download | nixlib-9afbeb71219925d54b72b0170b2e3be76bad1e28.tar nixlib-9afbeb71219925d54b72b0170b2e3be76bad1e28.tar.gz nixlib-9afbeb71219925d54b72b0170b2e3be76bad1e28.tar.bz2 nixlib-9afbeb71219925d54b72b0170b2e3be76bad1e28.tar.lz nixlib-9afbeb71219925d54b72b0170b2e3be76bad1e28.tar.xz nixlib-9afbeb71219925d54b72b0170b2e3be76bad1e28.tar.zst nixlib-9afbeb71219925d54b72b0170b2e3be76bad1e28.zip |
Merge commit 'ae6bdcc53584aaf20211ce1814bea97ece08a248'
# Conflicts: # nixpkgs/pkgs/build-support/rust/default.nix # nixpkgs/pkgs/development/go-modules/generic/default.nix
Diffstat (limited to 'nixpkgs/lib')
-rw-r--r-- | nixpkgs/lib/generators.nix | 53 | ||||
-rw-r--r-- | nixpkgs/lib/licenses.nix | 7 | ||||
-rw-r--r-- | nixpkgs/lib/modules.nix | 13 | ||||
-rw-r--r-- | nixpkgs/lib/options.nix | 2 | ||||
-rw-r--r-- | nixpkgs/lib/sources.nix | 7 | ||||
-rw-r--r-- | nixpkgs/lib/systems/default.nix | 1 | ||||
-rw-r--r-- | nixpkgs/lib/systems/doubles.nix | 11 | ||||
-rw-r--r-- | nixpkgs/lib/systems/inspect.nix | 1 | ||||
-rw-r--r-- | nixpkgs/lib/systems/parse.nix | 3 | ||||
-rwxr-xr-x | nixpkgs/lib/tests/modules.sh | 13 | ||||
-rw-r--r-- | nixpkgs/lib/tests/modules/declare-enable-nested.nix | 14 | ||||
-rw-r--r-- | nixpkgs/lib/tests/modules/declare-int-positive-value-nested.nix | 9 | ||||
-rw-r--r-- | nixpkgs/lib/tests/modules/define-option-dependently-nested.nix | 16 | ||||
-rw-r--r-- | nixpkgs/lib/tests/modules/define-option-dependently.nix | 16 | ||||
-rw-r--r-- | nixpkgs/lib/tests/systems.nix | 7 |
15 files changed, 158 insertions, 15 deletions
diff --git a/nixpkgs/lib/generators.nix b/nixpkgs/lib/generators.nix index 240a19789b54..efe6ea6031d3 100644 --- a/nixpkgs/lib/generators.nix +++ b/nixpkgs/lib/generators.nix @@ -126,6 +126,59 @@ rec { # map input to ini sections mapAttrsToStringsSep "\n" mkSection attrsOfAttrs; + /* Generate a git-config file from an attrset. + * + * It has two major differences from the regular INI format: + * + * 1. values are indented with tabs + * 2. sections can have sub-sections + * + * generators.toGitINI { + * url."ssh://git@github.com/".insteadOf = "https://github.com"; + * user.name = "edolstra"; + * } + * + *> [url "ssh://git@github.com/"] + *> insteadOf = https://github.com/ + *> + *> [user] + *> name = edolstra + */ + toGitINI = attrs: + with builtins; + let + mkSectionName = name: + let + containsQuote = libStr.hasInfix ''"'' name; + sections = libStr.splitString "." name; + section = head sections; + subsections = tail sections; + subsection = concatStringsSep "." subsections; + in if containsQuote || subsections == [ ] then + name + else + ''${section} "${subsection}"''; + + # generation for multiple ini values + mkKeyValue = k: v: + let mkKeyValue = mkKeyValueDefault { } " = " k; + in concatStringsSep "\n" (map (kv: "\t" + mkKeyValue kv) (lib.toList v)); + + # converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI + gitFlattenAttrs = let + recurse = path: value: + if isAttrs value then + lib.mapAttrsToList (name: value: recurse ([ name ] ++ path) value) value + else if length path > 1 then { + ${concatStringsSep "." (lib.reverseList (tail path))}.${head path} = value; + } else { + ${head path} = value; + }; + in attrs: lib.foldl lib.recursiveUpdate { } (lib.flatten (recurse [ ] attrs)); + + toINI_ = toINI { inherit mkKeyValue mkSectionName; }; + in + toINI_ (gitFlattenAttrs attrs); /* Generates JSON from an arbitrary (non-function) value. * For more information see the documentation of the builtin. diff --git a/nixpkgs/lib/licenses.nix b/nixpkgs/lib/licenses.nix index e2f94e565ce2..e37eb57cff97 100644 --- a/nixpkgs/lib/licenses.nix +++ b/nixpkgs/lib/licenses.nix @@ -649,6 +649,13 @@ lib.mapAttrs (n: v: v // { shortName = n; }) { url = http://metadata.ftp-master.debian.org/changelogs/main/d/debianutils/debianutils_4.8.1_copyright; }; + sspl = { + shortName = "SSPL"; + fullName = "Server Side Public License"; + url = https://www.mongodb.com/licensing/server-side-public-license; + free = false; + }; + tcltk = spdx { spdxId = "TCL"; fullName = "TCL/TK License"; diff --git a/nixpkgs/lib/modules.nix b/nixpkgs/lib/modules.nix index 6cbef5632bd7..c18fec66c705 100644 --- a/nixpkgs/lib/modules.nix +++ b/nixpkgs/lib/modules.nix @@ -93,7 +93,11 @@ rec { res set._definedNames else res; - result = { inherit options config; }; + result = { + inherit options; + config = removeAttrs config [ "_module" ]; + inherit (config) _module; + }; in result; # collectModules :: (modulesPath: String) -> (modules: [ Module ]) -> (args: Attrs) -> [ Module ] @@ -410,10 +414,9 @@ rec { # Type-check the remaining definitions, and merge them. Or throw if no definitions. mergedValue = if isDefined then - foldl' (res: def: - if type.check def.value then res - else throw "The option value `${showOption loc}' in `${def.file}' is not of type `${type.description}'." - ) (type.merge loc defsFinal) defsFinal + if all (def: type.check def.value) defsFinal then type.merge loc defsFinal + else let firstInvalid = findFirst (def: ! type.check def.value) null defsFinal; + in throw "The option value `${showOption loc}' in `${firstInvalid.file}' is not of type `${type.description}'." else # (nixos-option detects this specific error message and gives it special # handling. If changed here, please change it there too.) diff --git a/nixpkgs/lib/options.nix b/nixpkgs/lib/options.nix index e5c0631a5437..71481c9250ab 100644 --- a/nixpkgs/lib/options.nix +++ b/nixpkgs/lib/options.nix @@ -159,7 +159,7 @@ rec { let ss = opt.type.getSubOptions opt.loc; in if ss != {} then optionAttrSetToDocList' opt.loc ss else []; in - [ docOption ] ++ subOptions) (collect isOption options); + [ docOption ] ++ optionals docOption.visible subOptions) (collect isOption options); /* This function recursively removes all derivation attributes from diff --git a/nixpkgs/lib/sources.nix b/nixpkgs/lib/sources.nix index 05519c3e392e..ed9bce485300 100644 --- a/nixpkgs/lib/sources.nix +++ b/nixpkgs/lib/sources.nix @@ -63,17 +63,14 @@ rec { # https://nixos.org/nix/manual/#builtin-filterSource # # name: Optional name to use as part of the store path. - # This defaults `src.name` or otherwise `baseNameOf src`. - # We recommend setting `name` whenever `src` is syntactically `./.`. - # Otherwise, you depend on `./.`'s name in the parent directory, - # which can cause inconsistent names, defeating caching. + # This defaults to `src.name` or otherwise `"source"`. # cleanSourceWith = { filter ? _path: _type: true, src, name ? null }: let isFiltered = src ? _isLibCleanSourceWith; origSrc = if isFiltered then src.origSrc else src; filter' = if isFiltered then name: type: filter name type && src.filter name type else filter; - name' = if name != null then name else if isFiltered then src.name else baseNameOf src; + name' = if name != null then name else if isFiltered then src.name else "source"; in { inherit origSrc; filter = filter'; diff --git a/nixpkgs/lib/systems/default.nix b/nixpkgs/lib/systems/default.nix index 4ca932d17921..210674cc6399 100644 --- a/nixpkgs/lib/systems/default.nix +++ b/nixpkgs/lib/systems/default.nix @@ -65,6 +65,7 @@ rec { freebsd = "FreeBSD"; openbsd = "OpenBSD"; wasi = "Wasi"; + genode = "Genode"; }.${final.parsed.kernel.name} or null; # uname -p diff --git a/nixpkgs/lib/systems/doubles.nix b/nixpkgs/lib/systems/doubles.nix index 96e602d0e167..a839b3d3d573 100644 --- a/nixpkgs/lib/systems/doubles.nix +++ b/nixpkgs/lib/systems/doubles.nix @@ -26,9 +26,17 @@ let "riscv32-linux" "riscv64-linux" - "aarch64-none" "avr-none" "arm-none" "i686-none" "x86_64-none" "powerpc-none" "msp430-none" "riscv64-none" "riscv32-none" "vc4-none" + "arm-none" "armv6l-none" "aarch64-none" + "avr-none" + "i686-none" "x86_64-none" + "powerpc-none" + "msp430-none" + "riscv64-none" "riscv32-none" + "vc4-none" "js-ghcjs" + + "aarch64-genode" "x86_64-genode" ]; allParsed = map parse.mkSystemFromString all; @@ -62,6 +70,7 @@ in { unix = filterDoubles predicates.isUnix; wasi = filterDoubles predicates.isWasi; windows = filterDoubles predicates.isWindows; + genode = filterDoubles predicates.isGenode; embedded = filterDoubles predicates.isNone; diff --git a/nixpkgs/lib/systems/inspect.nix b/nixpkgs/lib/systems/inspect.nix index 01dcf0787dfa..90a1fb6d80c2 100644 --- a/nixpkgs/lib/systems/inspect.nix +++ b/nixpkgs/lib/systems/inspect.nix @@ -47,6 +47,7 @@ rec { isMinGW = { kernel = kernels.windows; abi = abis.gnu; }; isWasi = { kernel = kernels.wasi; }; isGhcjs = { kernel = kernels.ghcjs; }; + isGenode = { kernel = kernels.genode; }; isNone = { kernel = kernels.none; }; isAndroid = [ { abi = abis.android; } { abi = abis.androideabi; } ]; diff --git a/nixpkgs/lib/systems/parse.nix b/nixpkgs/lib/systems/parse.nix index 6a02dbb51528..648e7c270240 100644 --- a/nixpkgs/lib/systems/parse.nix +++ b/nixpkgs/lib/systems/parse.nix @@ -279,6 +279,7 @@ rec { wasi = { execFormat = wasm; families = { }; }; windows = { execFormat = pe; families = { }; }; ghcjs = { execFormat = unknown; families = { }; }; + genode = { execFormat = elf; families = { }; }; } // { # aliases # 'darwin' is the kernel for all of them. We choose macOS by default. darwin = kernels.macos; @@ -395,6 +396,8 @@ rec { then { cpu = elemAt l 0; vendor = "unknown"; kernel = elemAt l 1; abi = elemAt l 2; } else if (elemAt l 2 == "ghcjs") then { cpu = elemAt l 0; vendor = "unknown"; kernel = elemAt l 2; } + else if hasPrefix "genode" (elemAt l 2) + then { cpu = elemAt l 0; vendor = elemAt l 1; kernel = elemAt l 2; } else throw "Target specification with 3 components is ambiguous"; "4" = { cpu = elemAt l 0; vendor = elemAt l 1; kernel = elemAt l 2; abi = elemAt l 3; }; }.${toString (length l)} diff --git a/nixpkgs/lib/tests/modules.sh b/nixpkgs/lib/tests/modules.sh index 8cd632a439cd..e81cf016ee9a 100755 --- a/nixpkgs/lib/tests/modules.sh +++ b/nixpkgs/lib/tests/modules.sh @@ -185,6 +185,14 @@ checkConfigError 'The option .* defined in .* does not exist' config.enable ./di # Check that imports can depend on derivations checkConfigOutput "true" config.enable ./import-from-store.nix +# Check that configs can be conditional on option existence +checkConfigOutput true config.enable ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix +checkConfigOutput 360 config.value ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix +checkConfigOutput 7 config.value ./define-option-dependently.nix ./declare-int-positive-value.nix +checkConfigOutput true config.set.enable ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix +checkConfigOutput 360 config.set.value ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix +checkConfigOutput 7 config.set.value ./define-option-dependently-nested.nix ./declare-int-positive-value-nested.nix + # Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only # attrsOf should work with conditional definitions # In addition, lazyAttrsOf should honor an options emptyValue @@ -194,6 +202,11 @@ checkConfigOutput "true" config.conditionalWorks ./declare-attrsOf.nix ./attrsOf checkConfigOutput "false" config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix checkConfigOutput "empty" config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix + +# Even with multiple assignments, a type error should be thrown if any of them aren't valid +checkConfigError 'The option value .* in .* is not of type .*' \ + config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix + cat <<EOF ====== module tests ====== $pass Pass diff --git a/nixpkgs/lib/tests/modules/declare-enable-nested.nix b/nixpkgs/lib/tests/modules/declare-enable-nested.nix new file mode 100644 index 000000000000..c8da8273cba1 --- /dev/null +++ b/nixpkgs/lib/tests/modules/declare-enable-nested.nix @@ -0,0 +1,14 @@ +{ lib, ... }: + +{ + options.set = { + enable = lib.mkOption { + default = false; + example = true; + type = lib.types.bool; + description = '' + Some descriptive text + ''; + }; + }; +} diff --git a/nixpkgs/lib/tests/modules/declare-int-positive-value-nested.nix b/nixpkgs/lib/tests/modules/declare-int-positive-value-nested.nix new file mode 100644 index 000000000000..72d2fb89fc3b --- /dev/null +++ b/nixpkgs/lib/tests/modules/declare-int-positive-value-nested.nix @@ -0,0 +1,9 @@ +{ lib, ... }: + +{ + options.set = { + value = lib.mkOption { + type = lib.types.ints.positive; + }; + }; +} diff --git a/nixpkgs/lib/tests/modules/define-option-dependently-nested.nix b/nixpkgs/lib/tests/modules/define-option-dependently-nested.nix new file mode 100644 index 000000000000..69ee4255534a --- /dev/null +++ b/nixpkgs/lib/tests/modules/define-option-dependently-nested.nix @@ -0,0 +1,16 @@ +{ lib, options, ... }: + +# Some modules may be distributed separately and need to adapt to other modules +# that are distributed and versioned separately. +{ + + # Always defined, but the value depends on the presence of an option. + config.set = { + value = if options ? set.enable then 360 else 7; + } + # Only define if possible. + // lib.optionalAttrs (options ? set.enable) { + enable = true; + }; + +} diff --git a/nixpkgs/lib/tests/modules/define-option-dependently.nix b/nixpkgs/lib/tests/modules/define-option-dependently.nix new file mode 100644 index 000000000000..6abce29366ae --- /dev/null +++ b/nixpkgs/lib/tests/modules/define-option-dependently.nix @@ -0,0 +1,16 @@ +{ lib, options, ... }: + +# Some modules may be distributed separately and need to adapt to other modules +# that are distributed and versioned separately. +{ + + # Always defined, but the value depends on the presence of an option. + config = { + value = if options ? enable then 360 else 7; + } + # Only define if possible. + // lib.optionalAttrs (options ? enable) { + enable = true; + }; + +} diff --git a/nixpkgs/lib/tests/systems.nix b/nixpkgs/lib/tests/systems.nix index 6f52912994df..ea6e337937f9 100644 --- a/nixpkgs/lib/tests/systems.nix +++ b/nixpkgs/lib/tests/systems.nix @@ -12,16 +12,17 @@ let expected = lib.sort lib.lessThan y; }; in with lib.systems.doubles; lib.runTests { - testall = mseteq all (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ wasi ++ windows ++ embedded ++ js); + testall = mseteq all (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ wasi ++ windows ++ embedded ++ js ++ genode); - testarm = mseteq arm [ "armv5tel-linux" "armv6l-linux" "armv7a-linux" "armv7l-linux" "arm-none" "armv7a-darwin" ]; + testarm = mseteq arm [ "armv5tel-linux" "armv6l-linux" "armv6l-none" "armv7a-linux" "armv7l-linux" "arm-none" "armv7a-darwin" ]; testi686 = mseteq i686 [ "i686-linux" "i686-freebsd" "i686-netbsd" "i686-openbsd" "i686-cygwin" "i686-windows" "i686-none" "i686-darwin" ]; testmips = mseteq mips [ "mipsel-linux" ]; - testx86_64 = mseteq x86_64 [ "x86_64-linux" "x86_64-darwin" "x86_64-freebsd" "x86_64-openbsd" "x86_64-netbsd" "x86_64-cygwin" "x86_64-solaris" "x86_64-windows" "x86_64-none" ]; + testx86_64 = mseteq x86_64 [ "x86_64-linux" "x86_64-darwin" "x86_64-freebsd" "x86_64-genode" "x86_64-openbsd" "x86_64-netbsd" "x86_64-cygwin" "x86_64-solaris" "x86_64-windows" "x86_64-none" ]; testcygwin = mseteq cygwin [ "i686-cygwin" "x86_64-cygwin" ]; testdarwin = mseteq darwin [ "x86_64-darwin" "i686-darwin" "aarch64-darwin" "armv7a-darwin" ]; testfreebsd = mseteq freebsd [ "i686-freebsd" "x86_64-freebsd" ]; + testgenode = mseteq genode [ "aarch64-genode" "x86_64-genode" ]; testgnu = mseteq gnu (linux /* ++ kfreebsd ++ ... */); testillumos = mseteq illumos [ "x86_64-solaris" ]; testlinux = mseteq linux [ "aarch64-linux" "armv5tel-linux" "armv6l-linux" "armv7a-linux" "armv7l-linux" "i686-linux" "mipsel-linux" "riscv32-linux" "riscv64-linux" "x86_64-linux" "powerpc64le-linux" ]; |