diff options
author | Alyssa Ross <hi@alyssa.is> | 2024-04-10 20:43:08 +0200 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2024-04-10 20:43:08 +0200 |
commit | 69bfdf2484041b9d242840c4e5017b4703383bb0 (patch) | |
tree | d8bdaa69e7990d7d6f09b594b3c425f742acd2d0 /nixpkgs/lib | |
parent | c8aee4b4363b6bf905a521b05b7476960e8286c8 (diff) | |
parent | d8fe5e6c92d0d190646fb9f1056741a229980089 (diff) | |
download | nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar.gz nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar.bz2 nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar.lz nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar.xz nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.tar.zst nixlib-69bfdf2484041b9d242840c4e5017b4703383bb0.zip |
Merge commit 'd8fe5e6c'
Conflicts: nixpkgs/pkgs/build-support/go/module.nix
Diffstat (limited to 'nixpkgs/lib')
-rw-r--r-- | nixpkgs/lib/cli.nix | 95 | ||||
-rw-r--r-- | nixpkgs/lib/customisation.nix | 317 | ||||
-rw-r--r-- | nixpkgs/lib/licenses.nix | 6 | ||||
-rw-r--r-- | nixpkgs/lib/systems/default.nix | 74 | ||||
-rw-r--r-- | nixpkgs/lib/systems/inspect.nix | 49 | ||||
-rw-r--r-- | nixpkgs/lib/systems/parse.nix | 68 |
6 files changed, 433 insertions, 176 deletions
diff --git a/nixpkgs/lib/cli.nix b/nixpkgs/lib/cli.nix index c96d4dbb0432..fcffacb5ea99 100644 --- a/nixpkgs/lib/cli.nix +++ b/nixpkgs/lib/cli.nix @@ -1,43 +1,64 @@ { lib }: rec { - /* Automatically convert an attribute set to command-line options. - - This helps protect against malformed command lines and also to reduce - boilerplate related to command-line construction for simple use cases. - - `toGNUCommandLine` returns a list of nix strings. - `toGNUCommandLineShell` returns an escaped shell string. - - Example: - cli.toGNUCommandLine {} { - 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; - } - => [ - "-X" "PUT" - "--data" "{\"id\":0}" - "--retry" "3" - "--url" "https://example.com/foo" - "--url" "https://example.com/bar" - "--verbose" - ] - - cli.toGNUCommandLineShell {} { - 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; - } - => "'-X' 'PUT' '--data' '{\"id\":0}' '--retry' '3' '--url' 'https://example.com/foo' '--url' 'https://example.com/bar' '--verbose'"; + /** + Automatically convert an attribute set to command-line options. + + This helps protect against malformed command lines and also to reduce + boilerplate related to command-line construction for simple use cases. + + `toGNUCommandLine` returns a list of nix strings. + + `toGNUCommandLineShell` returns an escaped shell string. + + + # Inputs + + `options` + + : 1\. Function argument + + `attrs` + + : 2\. Function argument + + + # Examples + :::{.example} + ## `lib.cli.toGNUCommandLineShell` usage example + + ```nix + cli.toGNUCommandLine {} { + 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; + } + => [ + "-X" "PUT" + "--data" "{\"id\":0}" + "--retry" "3" + "--url" "https://example.com/foo" + "--url" "https://example.com/bar" + "--verbose" + ] + + cli.toGNUCommandLineShell {} { + 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; + } + => "'-X' 'PUT' '--data' '{\"id\":0}' '--retry' '3' '--url' 'https://example.com/foo' '--url' 'https://example.com/bar' '--verbose'"; + ``` + + ::: */ toGNUCommandLineShell = options: attrs: lib.escapeShellArgs (toGNUCommandLine options attrs); diff --git a/nixpkgs/lib/customisation.nix b/nixpkgs/lib/customisation.nix index 66638b63342a..0e0d79120296 100644 --- a/nixpkgs/lib/customisation.nix +++ b/nixpkgs/lib/customisation.nix @@ -15,42 +15,64 @@ in rec { - /* `overrideDerivation drv f` takes a derivation (i.e., the result - of a call to the builtin function `derivation`) and returns a new - derivation in which the attributes of the original are overridden - according to the function `f`. The function `f` is called with - the original derivation attributes. - - `overrideDerivation` allows certain "ad-hoc" customisation - scenarios (e.g. in ~/.config/nixpkgs/config.nix). For instance, - if you want to "patch" the derivation returned by a package - function in Nixpkgs to build another version than what the - function itself provides. - - For another application, see build-support/vm, where this - function is used to build arbitrary derivations inside a QEMU - virtual machine. - - Note that in order to preserve evaluation errors, the new derivation's - outPath depends on the old one's, which means that this function cannot - be used in circular situations when the old derivation also depends on the - new one. - - You should in general prefer `drv.overrideAttrs` over this function; - see the nixpkgs manual for more information on overriding. - - Example: - mySed = overrideDerivation pkgs.gnused (oldAttrs: { - name = "sed-4.2.2-pre"; - src = fetchurl { - url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2; - hash = "sha256-MxBJRcM2rYzQYwJ5XKxhXTQByvSg5jZc5cSHEZoB2IY="; - }; - patches = []; - }); - - Type: - overrideDerivation :: Derivation -> ( Derivation -> AttrSet ) -> Derivation + /** + `overrideDerivation drv f` takes a derivation (i.e., the result + of a call to the builtin function `derivation`) and returns a new + derivation in which the attributes of the original are overridden + according to the function `f`. The function `f` is called with + the original derivation attributes. + + `overrideDerivation` allows certain "ad-hoc" customisation + scenarios (e.g. in ~/.config/nixpkgs/config.nix). For instance, + if you want to "patch" the derivation returned by a package + function in Nixpkgs to build another version than what the + function itself provides. + + For another application, see build-support/vm, where this + function is used to build arbitrary derivations inside a QEMU + virtual machine. + + Note that in order to preserve evaluation errors, the new derivation's + outPath depends on the old one's, which means that this function cannot + be used in circular situations when the old derivation also depends on the + new one. + + You should in general prefer `drv.overrideAttrs` over this function; + see the nixpkgs manual for more information on overriding. + + + # Inputs + + `drv` + + : 1\. Function argument + + `f` + + : 2\. Function argument + + # Type + + ``` + overrideDerivation :: Derivation -> ( Derivation -> AttrSet ) -> Derivation + ``` + + # Examples + :::{.example} + ## `lib.customisation.overrideDerivation` usage example + + ```nix + mySed = overrideDerivation pkgs.gnused (oldAttrs: { + name = "sed-4.2.2-pre"; + src = fetchurl { + url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2; + hash = "sha256-MxBJRcM2rYzQYwJ5XKxhXTQByvSg5jZc5cSHEZoB2IY="; + }; + patches = []; + }); + ``` + + ::: */ overrideDerivation = drv: f: let @@ -67,26 +89,44 @@ rec { }); - /* `makeOverridable` takes a function from attribute set to attribute set and - injects `override` attribute which can be used to override arguments of - the function. + /** + `makeOverridable` takes a function from attribute set to attribute set and + injects `override` attribute which can be used to override arguments of + the function. - Please refer to documentation on [`<pkg>.overrideDerivation`](#sec-pkg-overrideDerivation) to learn about `overrideDerivation` and caveats - related to its use. + Please refer to documentation on [`<pkg>.overrideDerivation`](#sec-pkg-overrideDerivation) to learn about `overrideDerivation` and caveats + related to its use. - Example: - nix-repl> x = {a, b}: { result = a + b; } - nix-repl> y = lib.makeOverridable x { a = 1; b = 2; } + # Inputs - nix-repl> y - { override = «lambda»; overrideDerivation = «lambda»; result = 3; } + `f` - nix-repl> y.override { a = 10; } - { override = «lambda»; overrideDerivation = «lambda»; result = 12; } + : 1\. Function argument - Type: - makeOverridable :: (AttrSet -> a) -> AttrSet -> a + # Type + + ``` + makeOverridable :: (AttrSet -> a) -> AttrSet -> a + ``` + + # Examples + :::{.example} + ## `lib.customisation.makeOverridable` usage example + + ```nix + nix-repl> x = {a, b}: { result = a + b; } + + nix-repl> y = lib.makeOverridable x { a = 1; b = 2; } + + nix-repl> y + { override = «lambda»; overrideDerivation = «lambda»; result = 3; } + + nix-repl> y.override { a = 10; } + { override = «lambda»; overrideDerivation = «lambda»; result = 12; } + ``` + + ::: */ makeOverridable = f: let @@ -120,7 +160,8 @@ rec { else result); - /* Call the package function in the file `fn` with the required + /** + Call the package function in the file `fn` with the required arguments automatically. The function is called with the arguments `args`, but any missing arguments are obtained from `autoArgs`. This function is intended to be partially @@ -147,8 +188,26 @@ rec { <!-- TODO: Apply "Example:" tag to the examples above --> - Type: - callPackageWith :: AttrSet -> ((AttrSet -> a) | Path) -> AttrSet -> a + + # Inputs + + `autoArgs` + + : 1\. Function argument + + `fn` + + : 2\. Function argument + + `args` + + : 3\. Function argument + + # Type + + ``` + callPackageWith :: AttrSet -> ((AttrSet -> a) | Path) -> AttrSet -> a + ``` */ callPackageWith = autoArgs: fn: args: let @@ -210,12 +269,31 @@ rec { else abort "lib.customisation.callPackageWith: ${error}"; - /* Like callPackage, but for a function that returns an attribute - set of derivations. The override function is added to the - individual attributes. + /** + Like callPackage, but for a function that returns an attribute + set of derivations. The override function is added to the + individual attributes. + + + # Inputs + + `autoArgs` + + : 1\. Function argument + + `fn` + + : 2\. Function argument + + `args` + + : 3\. Function argument + + # Type - Type: - callPackagesWith :: AttrSet -> ((AttrSet -> AttrSet) | Path) -> AttrSet -> AttrSet + ``` + callPackagesWith :: AttrSet -> ((AttrSet -> AttrSet) | Path) -> AttrSet -> AttrSet + ``` */ callPackagesWith = autoArgs: fn: args: let @@ -233,11 +311,30 @@ rec { else mapAttrs mkAttrOverridable pkgs; - /* Add attributes to each output of a derivation without changing - the derivation itself and check a given condition when evaluating. + /** + Add attributes to each output of a derivation without changing + the derivation itself and check a given condition when evaluating. + + + # Inputs + + `condition` + + : 1\. Function argument + + `passthru` + + : 2\. Function argument + + `drv` - Type: - extendDerivation :: Bool -> Any -> Derivation -> Derivation + : 3\. Function argument + + # Type + + ``` + extendDerivation :: Bool -> Any -> Derivation -> Derivation + ``` */ extendDerivation = condition: passthru: drv: let @@ -269,13 +366,24 @@ rec { outPath = assert condition; drv.outPath; }; - /* Strip a derivation of all non-essential attributes, returning - only those needed by hydra-eval-jobs. Also strictly evaluate the - result to ensure that there are no thunks kept alive to prevent - garbage collection. + /** + Strip a derivation of all non-essential attributes, returning + only those needed by hydra-eval-jobs. Also strictly evaluate the + result to ensure that there are no thunks kept alive to prevent + garbage collection. + + + # Inputs + + `drv` + + : 1\. Function argument - Type: - hydraJob :: (Derivation | Null) -> (Derivation | Null) + # Type + + ``` + hydraJob :: (Derivation | Null) -> (Derivation | Null) + ``` */ hydraJob = drv: let @@ -443,32 +551,65 @@ rec { }; in self; - /* backward compatibility with old uncurried form; deprecated */ + /** + backward compatibility with old uncurried form; deprecated + + + # Inputs + + `splicePackages` + + : 1\. Function argument + + `newScope` + + : 2\. Function argument + + `otherSplices` + + : 3\. Function argument + + `keep` + + : 4\. Function argument + + `extra` + + : 5\. Function argument + + `f` + + : 6\. Function argument + */ makeScopeWithSplicing = splicePackages: newScope: otherSplices: keep: extra: f: makeScopeWithSplicing' { inherit splicePackages newScope; } { inherit otherSplices keep extra f; }; - /* Like makeScope, but aims to support cross compilation. It's still ugly, but - hopefully it helps a little bit. - - Type: - makeScopeWithSplicing' :: - { splicePackages :: Splice -> AttrSet - , newScope :: AttrSet -> ((AttrSet -> a) | Path) -> AttrSet -> a - } - -> { otherSplices :: Splice, keep :: AttrSet -> AttrSet, extra :: AttrSet -> AttrSet } - -> AttrSet - - Splice :: - { pkgsBuildBuild :: AttrSet - , pkgsBuildHost :: AttrSet - , pkgsBuildTarget :: AttrSet - , pkgsHostHost :: AttrSet - , pkgsHostTarget :: AttrSet - , pkgsTargetTarget :: AttrSet - } + /** + Like makeScope, but aims to support cross compilation. It's still ugly, but + hopefully it helps a little bit. + + # Type + + ``` + makeScopeWithSplicing' :: + { splicePackages :: Splice -> AttrSet + , newScope :: AttrSet -> ((AttrSet -> a) | Path) -> AttrSet -> a + } + -> { otherSplices :: Splice, keep :: AttrSet -> AttrSet, extra :: AttrSet -> AttrSet } + -> AttrSet + + Splice :: + { pkgsBuildBuild :: AttrSet + , pkgsBuildHost :: AttrSet + , pkgsBuildTarget :: AttrSet + , pkgsHostHost :: AttrSet + , pkgsHostTarget :: AttrSet + , pkgsTargetTarget :: AttrSet + } + ``` */ makeScopeWithSplicing' = { splicePackages diff --git a/nixpkgs/lib/licenses.nix b/nixpkgs/lib/licenses.nix index 4cda7e5c01a3..358b77117a36 100644 --- a/nixpkgs/lib/licenses.nix +++ b/nixpkgs/lib/licenses.nix @@ -392,6 +392,12 @@ in mkLicense lset) ({ fullName = "Common Public Attribution License 1.0"; }; + commons-clause = { + fullName = "Commons Clause License"; + url = "https://commonsclause.com/"; + free = false; + }; + cpl10 = { spdxId = "CPL-1.0"; fullName = "Common Public License 1.0"; diff --git a/nixpkgs/lib/systems/default.nix b/nixpkgs/lib/systems/default.nix index a71ea9209cb8..83ed32ed3275 100644 --- a/nixpkgs/lib/systems/default.nix +++ b/nixpkgs/lib/systems/default.nix @@ -1,7 +1,25 @@ { lib }: - let inherit (lib.attrsets) mapAttrs; in -rec { +let + inherit (lib) + any + filterAttrs + foldl + hasInfix + isFunction + isList + isString + mapAttrs + optional + optionalAttrs + optionalString + removeSuffix + replaceStrings + toUpper + ; + + inherit (lib.strings) toJSON; + doubles = import ./doubles.nix { inherit lib; }; parse = import ./parse.nix { inherit lib; }; inspect = import ./inspect.nix { inherit lib; }; @@ -24,7 +42,7 @@ rec { both arguments have been `elaborate`-d. */ equals = - let removeFunctions = a: lib.filterAttrs (_: v: !builtins.isFunction v) a; + let removeFunctions = a: filterAttrs (_: v: !isFunction v) a; in a: b: removeFunctions a == removeFunctions b; /* List of all Nix system doubles the nixpkgs flake will expose the package set @@ -41,7 +59,7 @@ rec { # clearly preferred, and to prevent cycles. A simpler fixed point where the RHS # always just used `final.*` would fail on both counts. elaborate = args': let - args = if lib.isString args' then { system = args'; } + args = if isString args' then { system = args'; } else args'; # TODO: deprecate args.rustc in favour of args.rust after 23.05 is EOL. @@ -96,7 +114,7 @@ rec { then "lib64" else "lib" else null; - extensions = lib.optionalAttrs final.hasSharedLibraries { + extensions = optionalAttrs final.hasSharedLibraries { sharedLibrary = if final.isDarwin then ".dylib" else if final.isWindows then ".dll" @@ -134,9 +152,9 @@ rec { # uname -m processor = if final.isPower64 - then "ppc64${lib.optionalString final.isLittleEndian "le"}" + then "ppc64${optionalString final.isLittleEndian "le"}" else if final.isPower - then "ppc${lib.optionalString final.isLittleEndian "le"}" + then "ppc${optionalString final.isLittleEndian "le"}" else if final.isMips64 then "mips64" # endianness is *not* included on mips64 else final.parsed.cpu.name; @@ -202,8 +220,8 @@ rec { else if final.isS390 && !final.isS390x then null else if final.isx86_64 then "x86_64" else if final.isx86 then "i386" - else if final.isMips64n32 then "mipsn32${lib.optionalString final.isLittleEndian "el"}" - else if final.isMips64 then "mips64${lib.optionalString final.isLittleEndian "el"}" + else if final.isMips64n32 then "mipsn32${optionalString final.isLittleEndian "el"}" + else if final.isMips64 then "mips64${optionalString final.isLittleEndian "el"}" else final.uname.processor; # Name used by UEFI for architectures. @@ -259,7 +277,7 @@ rec { 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"}" + then "${wine}/bin/wine${optionalString (final.parsed.cpu.bits == 64) "64"}" else if final.isLinux && pkgs.stdenv.hostPlatform.isLinux && final.qemuArch != null then "${qemu-user}/bin/qemu-${final.qemuArch}" else if final.isWasi @@ -310,10 +328,10 @@ rec { let f = args.rustc.platform.target-family; in - if builtins.isList f then f else [ f ] + if isList f then f else [ f ] ) - else lib.optional final.isUnix "unix" - ++ lib.optional final.isWindows "windows"; + else optional final.isUnix "unix" + ++ optional final.isWindows "windows"; # https://doc.rust-lang.org/reference/conditional-compilation.html#target_vendor vendor = let @@ -337,13 +355,13 @@ rec { vendor_ = final.rust.platform.vendor; # TODO: deprecate args.rustc in favour of args.rust after 23.05 is EOL. in args.rust.rustcTarget or args.rustc.config - or "${cpu_}-${vendor_}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; + or "${cpu_}-${vendor_}-${kernel.name}${optionalString (abi.name != "unknown") "-${abi.name}"}"; # The name of the rust target if it is standard, or the json file # containing the custom target spec. rustcTargetSpec = rust.rustcTargetSpec or ( /**/ if rust ? platform - then builtins.toFile (final.rust.rustcTarget + ".json") (builtins.toJSON rust.platform) + then builtins.toFile (final.rust.rustcTarget + ".json") (toJSON rust.platform) else final.rust.rustcTarget); # The name of the rust target if it is standard, or the @@ -352,7 +370,7 @@ rec { # # This is the name used by Cargo for target subdirectories. cargoShortTarget = - lib.removeSuffix ".json" (baseNameOf "${final.rust.rustcTargetSpec}"); + removeSuffix ".json" (baseNameOf "${final.rust.rustcTargetSpec}"); # When used as part of an environment variable name, triples are # uppercased and have all hyphens replaced by underscores: @@ -360,17 +378,17 @@ rec { # https://github.com/rust-lang/cargo/pull/9169 # https://github.com/rust-lang/cargo/issues/8285#issuecomment-634202431 cargoEnvVarTarget = - lib.strings.replaceStrings ["-"] ["_"] - (lib.strings.toUpper final.rust.cargoShortTarget); + replaceStrings ["-"] ["_"] + (toUpper final.rust.cargoShortTarget); # True if the target is no_std # https://github.com/rust-lang/rust/blob/2e44c17c12cec45b6a682b1e53a04ac5b5fcc9d2/src/bootstrap/config.rs#L415-L421 isNoStdTarget = - builtins.any (t: lib.hasInfix t final.rust.rustcTarget) ["-none" "nvptx" "switch" "-uefi"]; + any (t: hasInfix t final.rust.rustcTarget) ["-none" "nvptx" "switch" "-uefi"]; }; }; in assert final.useAndroidPrebuilt -> final.isAndroid; - assert lib.foldl + assert foldl (pass: { assertion, message }: if assertion final then pass @@ -378,4 +396,20 @@ rec { true (final.parsed.abi.assertions or []); final; + +in + +# Everything in this attrset is the public interface of the file. +{ + inherit + architectures + doubles + elaborate + equals + examples + flakeExposed + inspect + parse + platforms + ; } diff --git a/nixpkgs/lib/systems/inspect.nix b/nixpkgs/lib/systems/inspect.nix index c6a33781ae28..ebc7ab366876 100644 --- a/nixpkgs/lib/systems/inspect.nix +++ b/nixpkgs/lib/systems/inspect.nix @@ -1,10 +1,31 @@ { lib }: -with import ./parse.nix { inherit lib; }; -with lib.attrsets; -with lib.lists; -let abis_ = abis; in -let abis = lib.mapAttrs (_: abi: builtins.removeAttrs abi [ "assertions" ]) abis_; in +let + inherit (lib) + any + attrValues + concatMap + filter + hasPrefix + isList + mapAttrs + matchAttrs + recursiveUpdateUntil + toList + ; + + inherit (lib.strings) toJSON; + + inherit (lib.systems.parse) + kernels + kernelFamilies + significantBytes + cpuTypes + execFormats + ; + + abis = mapAttrs (_: abi: removeAttrs abi [ "assertions" ]) lib.systems.parse.abis; +in rec { # these patterns are to be matched against {host,build,target}Platform.parsed @@ -32,8 +53,8 @@ rec { isx86 = { cpu = { family = "x86"; }; }; isAarch32 = { cpu = { family = "arm"; bits = 32; }; }; isArmv7 = map ({ arch, ... }: { cpu = { inherit arch; }; }) - (lib.filter (cpu: lib.hasPrefix "armv7" cpu.arch or "") - (lib.attrValues cpuTypes)); + (filter (cpu: hasPrefix "armv7" cpu.arch or "") + (attrValues cpuTypes)); isAarch64 = { cpu = { family = "arm"; bits = 64; }; }; isAarch = { cpu = { family = "arm"; }; }; isMicroBlaze = { cpu = { family = "microblaze"; }; }; @@ -111,19 +132,19 @@ rec { let # patterns can be either a list or a (bare) singleton; turn # them into singletons for uniform handling - pat1 = lib.toList pat1_; - pat2 = lib.toList pat2_; + pat1 = toList pat1_; + pat2 = toList pat2_; in - lib.concatMap (attr1: + concatMap (attr1: map (attr2: - lib.recursiveUpdateUntil + recursiveUpdateUntil (path: subattr1: subattr2: if (builtins.intersectAttrs subattr1 subattr2) == {} || subattr1 == subattr2 then true else throw '' pattern conflict at path ${toString path}: - ${builtins.toJSON subattr1} - ${builtins.toJSON subattr2} + ${toJSON subattr1} + ${toJSON subattr2} '') attr1 attr2 @@ -132,7 +153,7 @@ rec { pat1; matchAnyAttrs = patterns: - if builtins.isList patterns then attrs: any (pattern: matchAttrs pattern attrs) patterns + if isList patterns then attrs: any (pattern: matchAttrs pattern attrs) patterns else matchAttrs patterns; predicates = mapAttrs (_: matchAnyAttrs) patterns; diff --git a/nixpkgs/lib/systems/parse.nix b/nixpkgs/lib/systems/parse.nix index b69ad669e187..191e9734b879 100644 --- a/nixpkgs/lib/systems/parse.nix +++ b/nixpkgs/lib/systems/parse.nix @@ -15,14 +15,45 @@ # systems that overlap with existing ones and won't notice something amiss. # { lib }: -with lib.lists; -with lib.types; -with lib.attrsets; -with lib.strings; -with (import ./inspect.nix { inherit lib; }).predicates; let - inherit (lib.options) mergeOneOption; + inherit (lib) + all + any + attrValues + elem + elemAt + hasPrefix + id + length + mapAttrs + mergeOneOption + optionalString + splitString + versionAtLeast + ; + + inherit (lib.strings) match; + + inherit (lib.systems.inspect.predicates) + isAarch32 + isBigEndian + isDarwin + isLinux + isPower64 + isWindows + ; + + inherit (lib.types) + enum + float + isType + mkOptionType + number + setType + string + types + ; setTypes = type: mapAttrs (name: value: @@ -33,10 +64,10 @@ let # regex `e?abi.*$` when determining the validity of a triple. In # other words, `i386-linuxabichickenlips` is a valid triple. removeAbiSuffix = x: - let match = builtins.match "(.*)e?abi.*" x; - in if match==null + let found = match "(.*)e?abi.*" x; + in if found == null then x - else lib.elemAt match 0; + else elemAt found 0; in @@ -76,7 +107,7 @@ rec { types.cpuType = enum (attrValues cpuTypes); - cpuTypes = with significantBytes; setTypes types.openCpuType { + cpuTypes = let inherit (significantBytes) bigEndian littleEndian; in setTypes types.openCpuType { arm = { bits = 32; significantByte = littleEndian; family = "arm"; }; armv5tel = { bits = 32; significantByte = littleEndian; family = "arm"; version = "5"; arch = "armv5t"; }; armv6m = { bits = 32; significantByte = littleEndian; family = "arm"; version = "6"; arch = "armv6-m"; }; @@ -166,7 +197,7 @@ rec { # Note: Since 22.11 the archs of a mode switching CPU are no longer considered # pairwise compatible. Mode switching implies that binaries built for A # and B respectively can't be executed at the same time. - isCompatible = a: b: with cpuTypes; lib.any lib.id [ + isCompatible = with cpuTypes; a: b: any id [ # x86 (b == i386 && isCompatible a i486) (b == i486 && isCompatible a i586) @@ -287,7 +318,10 @@ rec { types.kernel = enum (attrValues kernels); - kernels = with execFormats; with kernelFamilies; setTypes types.openKernel { + kernels = let + inherit (execFormats) elf pe wasm unknown macho; + inherit (kernelFamilies) bsd darwin; + in setTypes types.openKernel { # TODO(@Ericson2314): Don't want to mass-rebuild yet to keeping 'darwin' as # the normalized name for macOS. macos = { execFormat = macho; families = { inherit darwin; }; name = "darwin"; }; @@ -359,7 +393,7 @@ rec { The "gnu" ABI is ambiguous on 32-bit ARM. Use "gnueabi" or "gnueabihf" instead. ''; } - { assertion = platform: with platform; !(isPower64 && isBigEndian); + { assertion = platform: !(platform.isPower64 && platform.isBigEndian); message = '' The "gnu" ABI is ambiguous on big-endian 64-bit PowerPC. Use "gnuabielfv2" or "gnuabielfv1" instead. ''; @@ -480,7 +514,7 @@ rec { /**/ if args ? abi then getAbi args.abi else if isLinux parsed || isWindows parsed then if isAarch32 parsed then - if lib.versionAtLeast (parsed.cpu.version or "0") "6" + if versionAtLeast (parsed.cpu.version or "0") "6" then abis.gnueabihf else abis.gnueabi # Default ppc64 BE to ELFv2 @@ -491,7 +525,7 @@ rec { in mkSystem parsed; - mkSystemFromString = s: mkSystemFromSkeleton (mkSkeletonFromList (lib.splitString "-" s)); + mkSystemFromString = s: mkSystemFromSkeleton (mkSkeletonFromList (splitString "-" s)); kernelName = kernel: kernel.name + toString (kernel.version or ""); @@ -503,10 +537,10 @@ rec { tripleFromSystem = { cpu, vendor, kernel, abi, ... } @ sys: assert isSystem sys; let optExecFormat = - lib.optionalString (kernel.name == "netbsd" && + optionalString (kernel.name == "netbsd" && gnuNetBSDDefaultExecFormat cpu != kernel.execFormat) kernel.execFormat.name; - optAbi = lib.optionalString (abi != abis.unknown) "-${abi.name}"; + optAbi = optionalString (abi != abis.unknown) "-${abi.name}"; in "${cpu.name}-${vendor.name}-${kernelName kernel}${optExecFormat}${optAbi}"; ################################################################################ |