diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cli.nix | 11 | ||||
-rw-r--r-- | lib/fixed-points.nix | 152 | ||||
-rw-r--r-- | lib/licenses.nix | 17 | ||||
-rw-r--r-- | lib/systems/default.nix | 3 | ||||
-rw-r--r-- | lib/systems/examples.nix | 11 | ||||
-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 |
11 files changed, 246 insertions, 44 deletions
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/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 16efe6a0d0be5..64d9825ab198f 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"; @@ -902,6 +908,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"; 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..6a9427b2d9de7 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -59,7 +59,7 @@ rec { armv7a-android-prebuilt = { config = "armv7a-unknown-linux-androideabi"; - rustc.config = "armv7-linux-androideabi"; + rust.rustcTarget = "armv7-linux-androideabi"; sdkVer = "28"; ndkVer = "24"; useAndroidPrebuilt = true; @@ -67,7 +67,7 @@ rec { aarch64-android-prebuilt = { config = "aarch64-unknown-linux-android"; - rustc.config = "aarch64-linux-android"; + rust.rustcTarget = "aarch64-linux-android"; sdkVer = "28"; ndkVer = "24"; useAndroidPrebuilt = 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 |