diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/attrsets.nix | 2 | ||||
-rw-r--r-- | lib/customisation.nix | 6 | ||||
-rw-r--r-- | lib/debug.nix | 7 | ||||
-rw-r--r-- | lib/default.nix | 2 | ||||
-rw-r--r-- | lib/filesystem.nix | 4 | ||||
-rw-r--r-- | lib/licenses.nix | 53 | ||||
-rw-r--r-- | lib/modules.nix | 25 | ||||
-rw-r--r-- | lib/options.nix | 33 | ||||
-rw-r--r-- | lib/path/default.nix | 69 | ||||
-rw-r--r-- | lib/path/tests/unit.nix | 19 | ||||
-rw-r--r-- | lib/sources.nix | 6 | ||||
-rw-r--r-- | lib/strings.nix | 3 | ||||
-rw-r--r-- | lib/systems/architectures.nix | 5 | ||||
-rw-r--r-- | lib/systems/default.nix | 18 | ||||
-rw-r--r-- | lib/tests/systems.nix | 20 | ||||
-rw-r--r-- | lib/types.nix | 2 |
16 files changed, 183 insertions, 91 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 73b71f68db799..0335146e2a6b4 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -3,7 +3,7 @@ let inherit (builtins) head tail length; - inherit (lib.trivial) flip id mergeAttrs pipe; + inherit (lib.trivial) id mergeAttrs; inherit (lib.strings) concatStringsSep concatMapStringsSep escapeNixIdentifier sanitizeDerivationName; inherit (lib.lists) foldr foldl' concatMap concatLists elemAt all partition groupBy take foldl; in diff --git a/lib/customisation.nix b/lib/customisation.nix index fe32e890f3571..a9281b1ab698a 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -46,12 +46,6 @@ rec { // (drv.passthru or {}) // - # TODO(@Artturin): remove before release 23.05 and only have __spliced. - (lib.optionalAttrs (drv ? crossDrv && drv ? nativeDrv) { - crossDrv = overrideDerivation drv.crossDrv f; - nativeDrv = overrideDerivation drv.nativeDrv f; - }) - // lib.optionalAttrs (drv ? __spliced) { __spliced = {} // (lib.mapAttrs (_: sDrv: overrideDerivation sDrv f) drv.__spliced); }); diff --git a/lib/debug.nix b/lib/debug.nix index a851cd74778c9..97e87acccf0ef 100644 --- a/lib/debug.nix +++ b/lib/debug.nix @@ -15,22 +15,15 @@ { lib }: let inherit (lib) - isInt - attrNames isList isAttrs substring - addErrorContext attrValues concatLists - concatStringsSep const elem generators - head id - isDerivation - isFunction mapAttrs trace; in diff --git a/lib/default.nix b/lib/default.nix index 8fea4b8ad6374..73b8ad8715444 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -138,7 +138,7 @@ let mergeDefaultOption mergeOneOption mergeEqualOption mergeUniqueOption getValues getFiles optionAttrSetToDocList optionAttrSetToDocList' - scrubOptionValue literalExpression literalExample literalDocBook + scrubOptionValue literalExpression literalExample showOption showOptionWithDefLocs showFiles unknownModule mkOption mkPackageOption mkPackageOptionMD mdDoc literalMD; diff --git a/lib/filesystem.nix b/lib/filesystem.nix index 4860d4d02a773..f5bb8e9b59503 100644 --- a/lib/filesystem.nix +++ b/lib/filesystem.nix @@ -9,10 +9,6 @@ let pathExists ; - inherit (lib.strings) - hasPrefix - ; - inherit (lib.filesystem) pathType ; diff --git a/lib/licenses.nix b/lib/licenses.nix index 227bf6d0a3f43..c7e5b14a37c09 100644 --- a/lib/licenses.nix +++ b/lib/licenses.nix @@ -1,7 +1,7 @@ { lib }: lib.mapAttrs (lname: lset: let - defaultLicense = rec { + defaultLicense = { shortName = lname; free = true; # Most of our licenses are Free, explicitly declare unfree additions as such! deprecated = false; @@ -98,6 +98,11 @@ in mkLicense lset) ({ fullName = "Artistic License 1.0"; }; + artistic1-cl8 = { + spdxId = "Artistic-1.0-cl8"; + fullName = "Artistic License 1.0 w/clause 8"; + }; + artistic2 = { spdxId = "Artistic-2.0"; fullName = "Artistic License 2.0"; @@ -295,11 +300,26 @@ in mkLicense lset) ({ free = false; }; + cc-by-sa-10 = { + spdxId = "CC-BY-SA-1.0"; + fullName = "Creative Commons Attribution Share Alike 1.0"; + }; + + cc-by-sa-20 = { + spdxId = "CC-BY-SA-2.0"; + fullName = "Creative Commons Attribution Share Alike 2.0"; + }; + cc-by-sa-25 = { spdxId = "CC-BY-SA-2.5"; fullName = "Creative Commons Attribution Share Alike 2.5"; }; + cc-by-10 = { + spdxId = "CC-BY-1.0"; + fullName = "Creative Commons Attribution 1.0"; + }; + cc-by-30 = { spdxId = "CC-BY-3.0"; fullName = "Creative Commons Attribution 3.0"; @@ -486,6 +506,16 @@ in mkLicense lset) ({ url = "http://www.schristiancollins.com/generaluser.php"; # license included in sources }; + gfl = { + fullName = "GUST Font License"; + url = "http://www.gust.org.pl/fonts/licenses/GUST-FONT-LICENSE.txt"; + }; + + gfsl = { + fullName = "GUST Font Source License"; + url = "http://www.gust.org.pl/fonts/licenses/GUST-FONT-SOURCE-LICENSE.txt"; + }; + gpl1Only = { spdxId = "GPL-1.0-only"; fullName = "GNU General Public License v1.0 only"; @@ -626,6 +656,11 @@ in mkLicense lset) ({ free = false; }; + knuth = { + fullName = "Knuth CTAN License"; + spdxId = "Knuth-CTAN"; + }; + lal12 = { spdxId = "LAL-1.2"; fullName = "Licence Art Libre 1.2"; @@ -702,11 +737,21 @@ in mkLicense lset) ({ url = "https://opensource.franz.com/preamble.html"; }; + lppl1 = { + spdxId = "LPPL-1.0"; + fullName = "LaTeX Project Public License v1.0"; + }; + lppl12 = { spdxId = "LPPL-1.2"; fullName = "LaTeX Project Public License v1.2"; }; + lppl13a = { + spdxId = "LPPL-1.3a"; + fullName = "LaTeX Project Public License v1.3a"; + }; + lppl13c = { spdxId = "LPPL-1.3c"; fullName = "LaTeX Project Public License v1.3c"; @@ -764,6 +809,12 @@ in mkLicense lset) ({ fullName = "Microsoft Public License"; }; + mulan-psl2 = { + spdxId = "MulanPSL-2.0"; + fullName = "Mulan Permissive Software License, Version 2"; + url = "https://license.coscl.org.cn/MulanPSL2"; + }; + nasa13 = { spdxId = "NASA-1.3"; fullName = "NASA Open Source Agreement 1.3"; diff --git a/lib/modules.nix b/lib/modules.nix index 381675f611df8..0bedd28e877e1 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -21,7 +21,6 @@ let isBool isFunction isList - isPath isString length mapAttrs @@ -134,11 +133,6 @@ let ${if prefix == [] then null # unset => visible else "internal"} = true; - # TODO: hidden during the markdown transition to not expose downstream - # users of the docs infra to markdown if they're not ready for it. - # we don't make this visible conditionally because it can impact - # performance (https://github.com/NixOS/nixpkgs/pull/208407#issuecomment-1368246192) - visible = false; # TODO: Change the type of this option to a submodule with a # freeformType, so that individual arguments can be documented # separately @@ -1180,14 +1174,11 @@ let use = id; }; - /* Transitional version of mkAliasOptionModule that uses MD docs. */ - mkAliasOptionModuleMD = from: to: doRename { - inherit from to; - visible = true; - warn = false; - use = id; - markdown = true; - }; + /* Transitional version of mkAliasOptionModule that uses MD docs. + + This function is no longer necessary and merely an alias of `mkAliasOptionModule`. + */ + mkAliasOptionModuleMD = mkAliasOptionModule; /* mkDerivedConfig : Option a -> (a -> Definition b) -> Definition b @@ -1209,7 +1200,7 @@ let (opt.highestPrio or defaultOverridePriority) (f opt.value); - doRename = { from, to, visible, warn, use, withPriority ? true, markdown ? false }: + doRename = { from, to, visible, warn, use, withPriority ? true }: { config, options, ... }: let fromOpt = getAttrFromPath from options; @@ -1220,9 +1211,7 @@ let { options = setAttrByPath from (mkOption { inherit visible; - description = if markdown - then lib.mdDoc "Alias of {option}`${showOption to}`." - else "Alias of <option>${showOption to}</option>."; + description = "Alias of {option}`${showOption to}`."; apply = x: use (toOf config); } // optionalAttrs (toType != null) { type = toType; diff --git a/lib/options.nix b/lib/options.nix index af7914bb51378..c42bc1e6c67e3 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -100,10 +100,7 @@ rec { name: mkOption { default = false; example = true; - description = - if name ? _type && name._type == "mdDoc" - then lib.mdDoc "Whether to enable ${name.text}." - else "Whether to enable ${name}."; + description = "Whether to enable ${name}."; type = lib.types.bool; }; @@ -185,10 +182,10 @@ rec { (if isList example then "pkgs." + concatStringsSep "." example else example); }); - /* Like mkPackageOption, but emit an mdDoc description instead of DocBook. */ - mkPackageOptionMD = pkgs: name: extra: - let option = mkPackageOption pkgs name extra; - in option // { description = lib.mdDoc option.description; }; + /* Alias of mkPackageOption. Previously used to create options with markdown + documentation, which is no longer required. + */ + mkPackageOptionMD = mkPackageOption; /* This option accepts anything, but it does not produce any result. @@ -344,26 +341,12 @@ rec { if ! isString text then throw "literalExpression expects a string." else { _type = "literalExpression"; inherit text; }; - literalExample = lib.warn "literalExample is deprecated, use literalExpression instead, or use literalDocBook for a non-Nix description." literalExpression; - - - /* For use in the `defaultText` and `example` option attributes. Causes the - given DocBook text to be inserted verbatim in the documentation, for when - a `literalExpression` would be too hard to read. - */ - literalDocBook = text: - if ! isString text then throw "literalDocBook expects a string." - else - lib.warnIf (lib.isInOldestRelease 2211) - "literalDocBook is deprecated, use literalMD instead" - { _type = "literalDocBook"; inherit text; }; + literalExample = lib.warn "literalExample is deprecated, use literalExpression instead, or use literalMD for a non-Nix description." literalExpression; /* Transition marker for documentation that's already migrated to markdown - syntax. + syntax. This is a no-op and no longer needed. */ - mdDoc = text: - if ! isString text then throw "mdDoc expects a string." - else { _type = "mdDoc"; inherit text; }; + mdDoc = lib.id; /* For use in the `defaultText` and `example` option attributes. Causes the given MD text to be inserted verbatim in the documentation, for when diff --git a/lib/path/default.nix b/lib/path/default.nix index a4a08668ae62e..936e9b0302534 100644 --- a/lib/path/default.nix +++ b/lib/path/default.nix @@ -7,6 +7,7 @@ let isPath split match + typeOf ; inherit (lib.lists) @@ -18,6 +19,7 @@ let all concatMap foldl' + take ; inherit (lib.strings) @@ -100,6 +102,22 @@ let # An empty string is not a valid relative path, so we need to return a `.` when we have no components (if components == [] then "." else concatStringsSep "/" components); + # Type: Path -> { root :: Path, components :: [ String ] } + # + # Deconstruct a path value type into: + # - root: The filesystem root of the path, generally `/` + # - components: All the path's components + # + # This is similar to `splitString "/" (toString path)` but safer + # because it can distinguish different filesystem roots + deconstructPath = + let + recurse = components: base: + # If the parent of a path is the path itself, then it's a filesystem root + if base == dirOf base then { root = base; inherit components; } + else recurse ([ (baseNameOf base) ] ++ components) (dirOf base); + in recurse []; + in /* No rec! Add dependencies on this file at the top. */ { /* Append a subpath string to a path. @@ -108,6 +126,12 @@ in /* No rec! Add dependencies on this file at the top. */ { More specifically, it checks that the first argument is a [path value type](https://nixos.org/manual/nix/stable/language/values.html#type-path"), and that the second argument is a valid subpath string (see `lib.path.subpath.isValid`). + Laws: + + - Not influenced by subpath normalisation + + append p s == append p (subpath.normalise s) + Type: append :: Path -> String -> Path @@ -149,6 +173,51 @@ in /* No rec! Add dependencies on this file at the top. */ { ${subpathInvalidReason subpath}''; path + ("/" + subpath); + /* + Whether the first path is a component-wise prefix of the second path. + + Laws: + + - `hasPrefix p q` is only true if `q == append p s` for some subpath `s`. + + - `hasPrefix` is a [non-strict partial order](https://en.wikipedia.org/wiki/Partially_ordered_set#Non-strict_partial_order) over the set of all path values + + Type: + hasPrefix :: Path -> Path -> Bool + + Example: + hasPrefix /foo /foo/bar + => true + hasPrefix /foo /foo + => true + hasPrefix /foo/bar /foo + => false + hasPrefix /. /foo + => true + */ + hasPrefix = + path1: + assert assertMsg + (isPath path1) + "lib.path.hasPrefix: First argument is of type ${typeOf path1}, but a path was expected"; + let + path1Deconstructed = deconstructPath path1; + in + path2: + assert assertMsg + (isPath path2) + "lib.path.hasPrefix: Second argument is of type ${typeOf path2}, but a path was expected"; + let + path2Deconstructed = deconstructPath path2; + in + assert assertMsg + (path1Deconstructed.root == path2Deconstructed.root) '' + lib.path.hasPrefix: Filesystem roots must be the same for both paths, but paths with different roots were given: + first argument: "${toString path1}" with root "${toString path1Deconstructed.root}" + second argument: "${toString path2}" with root "${toString path2Deconstructed.root}"''; + take (length path1Deconstructed.components) path2Deconstructed.components == path1Deconstructed.components; + + /* Whether a value is a valid subpath string. - The value is a string diff --git a/lib/path/tests/unit.nix b/lib/path/tests/unit.nix index 61c4ab4d6f2ee..9c5b752cf64a3 100644 --- a/lib/path/tests/unit.nix +++ b/lib/path/tests/unit.nix @@ -3,7 +3,7 @@ { libpath }: let lib = import libpath; - inherit (lib.path) append subpath; + inherit (lib.path) hasPrefix append subpath; cases = lib.runTests { # Test examples from the lib.path.append documentation @@ -40,6 +40,23 @@ let expected = false; }; + testHasPrefixExample1 = { + expr = hasPrefix /foo /foo/bar; + expected = true; + }; + testHasPrefixExample2 = { + expr = hasPrefix /foo /foo; + expected = true; + }; + testHasPrefixExample3 = { + expr = hasPrefix /foo/bar /foo; + expected = false; + }; + testHasPrefixExample4 = { + expr = hasPrefix /. /foo; + expected = true; + }; + # Test examples from the lib.path.subpath.isValid documentation testSubpathIsValidExample1 = { expr = subpath.isValid null; diff --git a/lib/sources.nix b/lib/sources.nix index d990777c6fcc7..8b7cd5c84f62d 100644 --- a/lib/sources.nix +++ b/lib/sources.nix @@ -5,22 +5,16 @@ let inherit (builtins) match - readDir split storeDir - tryEval ; inherit (lib) boolToString filter - getAttr isString - pathExists readFile ; inherit (lib.filesystem) - pathType - pathIsDirectory pathIsRegularFile ; diff --git a/lib/strings.nix b/lib/strings.nix index e875520c6858f..bb07f40d7a559 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -264,7 +264,8 @@ rec { lib.strings.hasPrefix: The first argument (${toString pref}) is a path value, but only strings are supported. There is almost certainly a bug in the calling code, since this function always returns `false` in such a case. This function also copies the path to the Nix store, which may not be what you want. - This behavior is deprecated and will throw an error in the future.'' + This behavior is deprecated and will throw an error in the future. + You might want to use `lib.path.hasPrefix` instead, which correctly supports paths.'' (substring 0 (stringLength pref) str == pref); /* Determine whether a string has given suffix. diff --git a/lib/systems/architectures.nix b/lib/systems/architectures.nix index 57b9184ca60cd..11668ae59a71a 100644 --- a/lib/systems/architectures.nix +++ b/lib/systems/architectures.nix @@ -18,6 +18,7 @@ rec { cascadelake = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma" ]; cooperlake = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma" ]; tigerlake = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma" ]; + alderlake = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "fma" ]; # x86_64 AMD btver1 = [ "sse3" "ssse3" "sse4_1" "sse4_2" ]; btver2 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" ]; @@ -28,6 +29,7 @@ rec { znver1 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "fma" ]; znver2 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "fma" ]; znver3 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "fma" ]; + znver4 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "avx512" "fma" ]; # other armv5te = [ ]; armv6 = [ ]; @@ -55,6 +57,8 @@ rec { cascadelake = [ "skylake-avx512" ] ++ inferiors.cannonlake; cooperlake = [ "cascadelake" ] ++ inferiors.cascadelake; tigerlake = [ "icelake-server" ] ++ inferiors.icelake-server; + # CX16 does not exist on alderlake, while it does on nearly all other intel CPUs + alderlake = [ ]; # x86_64 AMD # TODO: fill this (need testing) @@ -86,6 +90,7 @@ rec { znver1 = [ "skylake" ] ++ inferiors.skylake; znver2 = [ "znver1" ] ++ inferiors.znver1; znver3 = [ "znver2" ] ++ inferiors.znver2; + znver4 = [ "znver3" ] ++ inferiors.znver3; # other armv5te = [ ]; diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 3558ce32fc8cb..78ccd50ba79a5 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -27,21 +27,6 @@ rec { let removeFunctions = a: lib.filterAttrs (_: v: !builtins.isFunction v) a; in a: b: removeFunctions a == removeFunctions b; - /* - Try to convert an elaborated system back to a simple string. If not possible, - return null. So we have the property: - - sys: _valid_ sys -> - sys == elaborate (toLosslessStringMaybe sys) - - NOTE: This property is not guaranteed when `sys` was elaborated by a different - version of Nixpkgs. - */ - toLosslessStringMaybe = sys: - if lib.isString sys then sys - else if equals sys (elaborate sys.system) then sys.system - else null; - /* List of all Nix system doubles the nixpkgs flake will expose the package set for. All systems listed here must be supported by nixpkgs as `localSystem`. @@ -226,8 +211,7 @@ rec { }; wine = (pkgs.winePackagesFor "wine${toString final.parsed.cpu.bits}").minimal; in - if final.parsed.kernel.name == pkgs.stdenv.hostPlatform.parsed.kernel.name && - pkgs.stdenv.hostPlatform.canExecute final + if pkgs.stdenv.hostPlatform.canExecute final then "${pkgs.runtimeShell} -c '\"$@\"' --" else if final.isWindows then "${wine}/bin/wine${lib.optionalString (final.parsed.cpu.bits == 64) "64"}" diff --git a/lib/tests/systems.nix b/lib/tests/systems.nix index 862496313e902..fe4657c9dee62 100644 --- a/lib/tests/systems.nix +++ b/lib/tests/systems.nix @@ -9,6 +9,22 @@ let expr = lib.sort lib.lessThan x; expected = lib.sort lib.lessThan y; }; + + /* + Try to convert an elaborated system back to a simple string. If not possible, + return null. So we have the property: + + sys: _valid_ sys -> + sys == elaborate (toLosslessStringMaybe sys) + + NOTE: This property is not guaranteed when `sys` was elaborated by a different + version of Nixpkgs. + */ + toLosslessStringMaybe = sys: + if lib.isString sys then sys + else if lib.systems.equals sys (lib.systems.elaborate sys.system) then sys.system + else null; + in lib.runTests ( # We assert that the new algorithmic way of generating these lists matches the @@ -55,11 +71,11 @@ lib.runTests ( }; test_toLosslessStringMaybe_example_x86_64-linux = { - expr = lib.systems.toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux"); + expr = toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux"); expected = "x86_64-linux"; }; test_toLosslessStringMaybe_fail = { - expr = lib.systems.toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux" // { something = "extra"; }); + expr = toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux" // { something = "extra"; }); expected = null; }; } diff --git a/lib/types.nix b/lib/types.nix index 9360d42f58506..d27d5750dfab1 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -211,7 +211,7 @@ rec { # nixos/doc/manual/development/option-types.xml! types = rec { - raw = mkOptionType rec { + raw = mkOptionType { name = "raw"; description = "raw value"; descriptionClass = "noun"; |