diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/attrsets.nix | 2 | ||||
-rw-r--r-- | lib/cli.nix | 11 | ||||
-rw-r--r-- | lib/default.nix | 27 | ||||
-rw-r--r-- | lib/fixed-points.nix | 152 | ||||
-rw-r--r-- | lib/licenses.nix | 38 | ||||
-rw-r--r-- | lib/systems/default.nix | 3 | ||||
-rw-r--r-- | lib/systems/examples.nix | 23 | ||||
-rw-r--r-- | lib/systems/flake-systems.nix | 4 | ||||
-rw-r--r-- | lib/systems/parse.nix | 1 | ||||
-rw-r--r-- | lib/systems/platforms.nix | 4 | ||||
-rw-r--r-- | lib/tests/misc.nix | 21 | ||||
-rw-r--r-- | lib/tests/release.nix | 4 | ||||
-rw-r--r-- | lib/trivial.nix | 62 |
13 files changed, 284 insertions, 68 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 83f8d0f34186e..c0ac6eeb41bcf 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -11,7 +11,7 @@ let in rec { - inherit (builtins) attrNames listToAttrs hasAttr isAttrs getAttr removeAttrs; + inherit (builtins) attrNames listToAttrs hasAttr isAttrs getAttr removeAttrs intersectAttrs; /** diff --git a/lib/cli.nix b/lib/cli.nix index fcffacb5ea996..311037c519a65 100644 --- a/lib/cli.nix +++ b/lib/cli.nix @@ -90,7 +90,16 @@ rec { mkOption ? k: v: if v == null then [] - else [ (mkOptionName k) (lib.generators.mkValueStringDefault {} v) ] + else if optionValueSeparator == null then + [ (mkOptionName k) (lib.generators.mkValueStringDefault {} v) ] + else + [ "${mkOptionName k}${optionValueSeparator}${lib.generators.mkValueStringDefault {} v}" ], + + # how to separate an option from its flag; + # by default, there is no separator, so option `-c` and value `5` + # would become ["-c" "5"]. + # This is useful if the command requires equals, for example, `-c=5`. + optionValueSeparator ? null }: options: let diff --git a/lib/default.nix b/lib/default.nix index d5d47defb8e64..9c6f886c9ee46 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -64,22 +64,21 @@ let # linux kernel configuration kernel = callLibs ./kernel.nix; - inherit (builtins) add addErrorContext attrNames concatLists - deepSeq elem elemAt filter genericClosure genList getAttr - hasAttr head isAttrs isBool isInt isList isPath isString length - lessThan listToAttrs pathExists readFile replaceStrings seq - stringLength sub substring tail trace; + # TODO: For consistency, all builtins should also be available from a sub-library; + # these are the only ones that are currently not + inherit (builtins) addErrorContext isPath trace; inherit (self.trivial) id const pipe concat or and xor bitAnd bitOr bitXor bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max importJSON importTOML warn warnIf warnIfNot throwIf throwIfNot checkListOfEnum info showWarnings nixpkgsVersion version isInOldestRelease - mod compare splitByAndCompare + mod compare splitByAndCompare seq deepSeq lessThan add sub functionArgs setFunctionArgs isFunction toFunction mirrorFunctionArgs - toHexString toBaseDigits inPureEvalMode; + toHexString toBaseDigits inPureEvalMode isBool isInt pathExists + genericClosure readFile; inherit (self.fixedPoints) fix fix' converge extends composeExtensions composeManyExtensions makeExtensible makeExtensibleWithCustomName; inherit (self.attrsets) attrByPath hasAttrByPath setAttrByPath - getAttrFromPath attrVals attrValues getAttrs catAttrs filterAttrs + getAttrFromPath attrVals attrNames attrValues getAttrs catAttrs filterAttrs filterAttrsRecursive foldlAttrs foldAttrs collect nameValuePair mapAttrs mapAttrs' mapAttrsToList attrsToList concatMapAttrs mapAttrsRecursive mapAttrsRecursiveCond genAttrs isDerivation toDerivation optionalAttrs @@ -87,14 +86,16 @@ let recursiveUpdate matchAttrs mergeAttrsList overrideExisting showAttrPath getOutput getBin getLib getDev getMan chooseDevOutputs zipWithNames zip recurseIntoAttrs dontRecurseIntoAttrs cartesianProduct cartesianProductOfSets - mapCartesianProduct updateManyAttrsByPath; - inherit (self.lists) singleton forEach foldr fold foldl foldl' imap0 imap1 - ifilter0 concatMap flatten remove findSingle findFirst any all count + mapCartesianProduct updateManyAttrsByPath listToAttrs hasAttr getAttr isAttrs intersectAttrs removeAttrs; + inherit (self.lists) singleton forEach map foldr fold foldl foldl' imap0 imap1 + filter ifilter0 concatMap flatten remove findSingle findFirst any all count optional optionals toList range replicate partition zipListsWith zipLists reverseList listDfs toposort sort sortOn naturalSort compareLists take drop sublist last init crossLists unique allUnique intersectLists - subtractLists mutuallyExclusive groupBy groupBy'; + subtractLists mutuallyExclusive groupBy groupBy' concatLists genList + length head tail elem elemAt isList; inherit (self.strings) concatStrings concatMapStrings concatImapStrings + stringLength substring isString replaceStrings intersperse concatStringsSep concatMapStringsSep concatImapStringsSep concatLines makeSearchPath makeSearchPathOutput makeLibraryPath makeIncludePath makeBinPath optionalString @@ -105,7 +106,7 @@ let escapeRegex escapeURL escapeXML replaceChars lowerChars upperChars toLower toUpper addContextFrom splitString removePrefix removeSuffix versionOlder versionAtLeast - getName getVersion + getName getVersion match split cmakeOptionType cmakeBool cmakeFeature mesonOption mesonBool mesonEnable nameFromURL enableFeature enableFeatureAs withFeature diff --git a/lib/fixed-points.nix b/lib/fixed-points.nix index 3bd18fdd2a5a9..2a31b44f27c17 100644 --- a/lib/fixed-points.nix +++ b/lib/fixed-points.nix @@ -1,6 +1,6 @@ { lib, ... }: rec { - /* + /** `fix f` computes the fixed point of the given function `f`. In other words, the return value is `x` in `x = f x`. `f` must be a lazy function. @@ -63,27 +63,52 @@ rec { See [`extends`](#function-library-lib.fixedPoints.extends) for an example use case. There `self` is also often called `final`. - Type: fix :: (a -> a) -> a - Example: - fix (self: { foo = "foo"; bar = "bar"; foobar = self.foo + self.bar; }) - => { bar = "bar"; foo = "foo"; foobar = "foobar"; } + # Inputs - fix (self: [ 1 2 (elemAt self 0 + elemAt self 1) ]) - => [ 1 2 3 ] + `f` + + : 1\. Function argument + + # Type + + ``` + fix :: (a -> a) -> a + ``` + + # Examples + :::{.example} + ## `lib.fixedPoints.fix` usage example + + ```nix + fix (self: { foo = "foo"; bar = "bar"; foobar = self.foo + self.bar; }) + => { bar = "bar"; foo = "foo"; foobar = "foobar"; } + + fix (self: [ 1 2 (elemAt self 0 + elemAt self 1) ]) + => [ 1 2 3 ] + ``` + + ::: */ fix = f: let x = f x; in x; - /* + /** A variant of `fix` that records the original recursive attribute set in the result, in an attribute named `__unfix__`. This is useful in combination with the `extends` function to implement deep overriding. + + + # Inputs + + `f` + + : 1\. Function argument */ fix' = f: let x = f x // { __unfix__ = f; }; in x; - /* + /** Return the fixpoint that `f` converges to when called iteratively, starting with the input `x`. @@ -92,7 +117,22 @@ rec { 0 ``` - Type: (a -> a) -> a -> a + + # Inputs + + `f` + + : 1\. Function argument + + `x` + + : 2\. Function argument + + # Type + + ``` + (a -> a) -> a -> a + ``` */ converge = f: x: let @@ -102,7 +142,7 @@ rec { then x else converge f x'; - /* + /** Extend a function using an overlay. Overlays allow modifying and extending fixed-point functions, specifically ones returning attribute sets. @@ -217,32 +257,50 @@ rec { ``` ::: - Type: - extends :: (Attrs -> Attrs -> Attrs) # The overlay to apply to the fixed-point function - -> (Attrs -> Attrs) # A fixed-point function - -> (Attrs -> Attrs) # The resulting fixed-point function - Example: - f = final: { a = 1; b = final.a + 2; } + # Inputs + + `overlay` - fix f - => { a = 1; b = 3; } + : The overlay to apply to the fixed-point function - fix (extends (final: prev: { a = prev.a + 10; }) f) - => { a = 11; b = 13; } + `f` - fix (extends (final: prev: { b = final.a + 5; }) f) - => { a = 1; b = 6; } + : The fixed-point function - fix (extends (final: prev: { c = final.a + final.b; }) f) - => { a = 1; b = 3; c = 4; } + # Type + + ``` + extends :: (Attrs -> Attrs -> Attrs) # The overlay to apply to the fixed-point function + -> (Attrs -> Attrs) # A fixed-point function + -> (Attrs -> Attrs) # The resulting fixed-point function + ``` + + # Examples + :::{.example} + ## `lib.fixedPoints.extends` usage example + + ```nix + f = final: { a = 1; b = final.a + 2; } + + fix f + => { a = 1; b = 3; } + + fix (extends (final: prev: { a = prev.a + 10; }) f) + => { a = 11; b = 13; } + + fix (extends (final: prev: { b = final.a + 5; }) f) + => { a = 1; b = 6; } + + fix (extends (final: prev: { c = final.a + final.b; }) f) + => { a = 1; b = 3; c = 4; } + ``` + + ::: */ extends = - # The overlay to apply to the fixed-point function overlay: - # The fixed-point function f: - # Wrap with parenthesis to prevent nixdoc from rendering the `final` argument in the documentation # The result should be thought of as a function, the argument of that function is not an argument to `extends` itself ( final: @@ -252,10 +310,29 @@ rec { prev // overlay final prev ); - /* + /** Compose two extending functions of the type expected by 'extends' into one where changes made in the first are available in the 'super' of the second + + + # Inputs + + `f` + + : 1\. Function argument + + `g` + + : 2\. Function argument + + `final` + + : 3\. Function argument + + `prev` + + : 4\. Function argument */ composeExtensions = f: g: final: prev: @@ -263,7 +340,7 @@ rec { prev' = prev // fApplied; in fApplied // g final prev'; - /* + /** Compose several extending functions of the type expected by 'extends' into one where changes made in preceding functions are made available to subsequent ones. @@ -276,7 +353,7 @@ rec { composeManyExtensions = lib.foldr (x: y: composeExtensions x y) (final: prev: {}); - /* + /** Create an overridable, recursive attribute set. For example: ``` @@ -298,9 +375,20 @@ rec { */ makeExtensible = makeExtensibleWithCustomName "extend"; - /* + /** Same as `makeExtensible` but the name of the extending attribute is customized. + + + # Inputs + + `extenderName` + + : 1\. Function argument + + `rattrs` + + : 2\. Function argument */ makeExtensibleWithCustomName = extenderName: rattrs: fix' (self: (rattrs self) // { diff --git a/lib/licenses.nix b/lib/licenses.nix index 7d2a22bc25a47..a608d3ec3f543 100644 --- a/lib/licenses.nix +++ b/lib/licenses.nix @@ -362,6 +362,12 @@ in mkLicense lset) ({ fullName = "Creative Commons Attribution Share Alike 4.0"; }; + cc-sa-10 = { + shortName = "CC-SA-1.0"; + fullName = "Creative Commons Share Alike 1.0"; + url = "https://creativecommons.org/licenses/sa/1.0"; + }; + cddl = { spdxId = "CDDL-1.0"; fullName = "Common Development and Distribution License 1.0"; @@ -524,6 +530,13 @@ in mkLicense lset) ({ fullName = "Unspecified free software license"; }; + fsl11Mit = { + fullName = "Functional Source License, Version 1.1, MIT Future License"; + url = "https://fsl.software/FSL-1.1-MIT.template.md"; + free = false; + redistributable = true; + }; + ftl = { spdxId = "FTL"; fullName = "Freetype Project License"; @@ -902,6 +915,17 @@ in mkLicense lset) ({ free = false; }; + ncbiPd = { + spdxId = "NCBI-PD"; + fullname = "NCBI Public Domain Notice"; + # Due to United States copyright law, anything with this "license" does not have a copyright in the + # jurisdiction of the United States. However, other jurisdictions may assign the United States + # government copyright to the work, and the license explicitly states that in such a case, no license + # is granted. This is nonfree and nonredistributable in most jurisdictions other than the United States. + free = false; + redistributable = false; + }; + ncsa = { spdxId = "NCSA"; fullName = "University of Illinois/NCSA Open Source License"; @@ -1261,11 +1285,21 @@ in mkLicense lset) ({ fullName = "xinetd License"; }; + xskat = { + spdxId = "XSkat"; + fullName = "XSkat License"; + }; + zlib = { spdxId = "Zlib"; fullName = "zlib License"; }; + zsh = { + url = "https://github.com/zsh-users/zsh/blob/master/LICENCE"; + fulllName = "Zsh License"; + }; + zpl20 = { spdxId = "ZPL-2.0"; fullName = "Zope Public License 2.0"; @@ -1276,10 +1310,6 @@ in mkLicense lset) ({ fullName = "Zope Public License 2.1"; }; - xskat = { - spdxId = "XSkat"; - fullName = "XSkat License"; - }; } // { # TODO: remove legacy aliases apsl10 = { diff --git a/lib/systems/default.nix b/lib/systems/default.nix index fbd6c323bf425..0981122388bb1 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -81,7 +81,7 @@ let && final.parsed.kernel == platform.parsed.kernel; isCompatible = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details"; # Derived meta-data - useLLVM = final.isFreeBSD; + useLLVM = final.isFreeBSD || final.isOpenBSD; libc = /**/ if final.isDarwin then "libSystem" @@ -93,6 +93,7 @@ let else if final.isAndroid then "bionic" else if final.isLinux /* default */ then "glibc" else if final.isFreeBSD then "fblibc" + else if final.isOpenBSD then "oblibc" else if final.isNetBSD then "nblibc" else if final.isAvr then "avrlibc" else if final.isGhcjs then null diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 8a3726f369682..7e50266748434 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -59,24 +59,24 @@ rec { armv7a-android-prebuilt = { config = "armv7a-unknown-linux-androideabi"; - rustc.config = "armv7-linux-androideabi"; - sdkVer = "28"; - ndkVer = "24"; + rust.rustcTarget = "armv7-linux-androideabi"; + sdkVer = "33"; + ndkVer = "26"; useAndroidPrebuilt = true; } // platforms.armv7a-android; aarch64-android-prebuilt = { config = "aarch64-unknown-linux-android"; - rustc.config = "aarch64-linux-android"; - sdkVer = "28"; - ndkVer = "24"; + rust.rustcTarget = "aarch64-linux-android"; + sdkVer = "33"; + ndkVer = "26"; useAndroidPrebuilt = true; }; aarch64-android = { config = "aarch64-unknown-linux-android"; - sdkVer = "30"; - ndkVer = "24"; + sdkVer = "33"; + ndkVer = "26"; libc = "bionic"; useAndroidPrebuilt = false; useLLVM = true; @@ -207,7 +207,7 @@ rec { aarch64-embedded = { config = "aarch64-none-elf"; libc = "newlib"; - rustc.config = "aarch64-unknown-none"; + rust.rustcTarget = "aarch64-unknown-none"; }; aarch64be-embedded = { @@ -342,6 +342,11 @@ rec { useLLVM = true; }; + x86_64-openbsd = { + config = "x86_64-unknown-openbsd"; + useLLVM = true; + }; + # # WASM # diff --git a/lib/systems/flake-systems.nix b/lib/systems/flake-systems.nix index b1988c6a4fbb0..a68580ff1407b 100644 --- a/lib/systems/flake-systems.nix +++ b/lib/systems/flake-systems.nix @@ -16,12 +16,12 @@ "armv6l-linux" "armv7l-linux" "i686-linux" - "mipsel-linux" + # "mipsel-linux" is excluded because it is not bootstrapped # Other platforms with sufficient support in stdenv which is not formally # mandated by their platform tier. "aarch64-darwin" - "armv5tel-linux" + # "armv5tel-linux" is excluded because it is not bootstrapped "powerpc64le-linux" "riscv64-linux" diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 4890912d7fed4..1d7c95943a794 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -469,6 +469,7 @@ rec { elem (elemAt l 2) [ "wasi" "redox" "mmixware" "ghcjs" "mingw32" ] || hasPrefix "freebsd" (elemAt l 2) || hasPrefix "netbsd" (elemAt l 2) || + hasPrefix "openbsd" (elemAt l 2) || hasPrefix "genode" (elemAt l 2) then { cpu = elemAt l 0; diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index d2e8f77bec03e..403ffc028f0be 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -535,11 +535,9 @@ rec { name = "riscv-multiplatform"; target = "Image"; autoModules = true; + preferBuiltin = true; baseConfig = "defconfig"; DTB = true; - extraConfig = '' - SERIAL_OF_PLATFORM y - ''; }; }; diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 6774939023d20..408ea54162938 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -1639,6 +1639,27 @@ runTests { ]; }; + testToGNUCommandLineSeparator = { + expr = cli.toGNUCommandLine { optionValueSeparator = "="; } { + data = builtins.toJSON { id = 0; }; + X = "PUT"; + retry = 3; + retry-delay = null; + url = [ "https://example.com/foo" "https://example.com/bar" ]; + silent = false; + verbose = true; + }; + + expected = [ + "-X=PUT" + "--data={\"id\":0}" + "--retry=3" + "--url=https://example.com/foo" + "--url=https://example.com/bar" + "--verbose" + ]; + }; + testToGNUCommandLineShell = { expr = cli.toGNUCommandLineShell {} { data = builtins.toJSON { id = 0; }; diff --git a/lib/tests/release.nix b/lib/tests/release.nix index 1447e88170913..084fbd94d34c2 100644 --- a/lib/tests/release.nix +++ b/lib/tests/release.nix @@ -24,7 +24,9 @@ in # # https://github.com/NixOS/nixpkgs/issues/272591 # - [(import ../../pkgs/test/release {})] + [(import ../../pkgs/test/release { + inherit pkgs lib nix; + })] ; } diff --git a/lib/trivial.nix b/lib/trivial.nix index dee7eca9699a0..20a3ffebbc2bb 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -403,7 +403,7 @@ in { On each release the first letter is bumped and a new animal is chosen starting with that new letter. */ - codeName = "Vicuña"; + codeName = "Vicuna"; /** Returns the current nixpkgs version suffix as string. @@ -623,6 +623,37 @@ in { /** Reads a JSON file. + # Examples + :::{.example} + ## `lib.trivial.importJSON` usage example + + example.json + ```json + { + "title": "Example JSON", + "hello": { + "world": "foo", + "bar": { + "foobar": true + } + } + } + ``` + + ```nix + importJSON ./example.json + => { + title = "Example JSON"; + hello = { + world = "foo"; + bar = { + foobar = true; + }; + }; + } + ``` + + ::: # Inputs @@ -642,6 +673,35 @@ in { /** Reads a TOML file. + # Examples + :::{.example} + ## `lib.trivial.importTOML` usage example + + example.toml + ```toml + title = "TOML Example" + + [hello] + world = "foo" + + [hello.bar] + foobar = true + ``` + + ```nix + importTOML ./example.toml + => { + title = "TOML Example"; + hello = { + world = "foo"; + bar = { + foobar = true; + }; + }; + } + ``` + + ::: # Inputs |