mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-17 19:21:04 +00:00
lib.systems: use explicit attrset instead of rec
This allows refactoring in the file without accidentally modifying the public interface of the file. Also, pull in symbols consistently from `lib` instead of `builtins`.
This commit is contained in:
parent
b022be4d67
commit
5988f8f841
|
@ -1,7 +1,25 @@
|
||||||
{ lib }:
|
{ 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; };
|
doubles = import ./doubles.nix { inherit lib; };
|
||||||
parse = import ./parse.nix { inherit lib; };
|
parse = import ./parse.nix { inherit lib; };
|
||||||
inspect = import ./inspect.nix { inherit lib; };
|
inspect = import ./inspect.nix { inherit lib; };
|
||||||
|
@ -24,7 +42,7 @@ rec {
|
||||||
both arguments have been `elaborate`-d.
|
both arguments have been `elaborate`-d.
|
||||||
*/
|
*/
|
||||||
equals =
|
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;
|
in a: b: removeFunctions a == removeFunctions b;
|
||||||
|
|
||||||
/* List of all Nix system doubles the nixpkgs flake will expose the package set
|
/* 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
|
# clearly preferred, and to prevent cycles. A simpler fixed point where the RHS
|
||||||
# always just used `final.*` would fail on both counts.
|
# always just used `final.*` would fail on both counts.
|
||||||
elaborate = args': let
|
elaborate = args': let
|
||||||
args = if lib.isString args' then { system = args'; }
|
args = if isString args' then { system = args'; }
|
||||||
else args';
|
else args';
|
||||||
|
|
||||||
# TODO: deprecate args.rustc in favour of args.rust after 23.05 is EOL.
|
# TODO: deprecate args.rustc in favour of args.rust after 23.05 is EOL.
|
||||||
|
@ -96,7 +114,7 @@ rec {
|
||||||
then "lib64"
|
then "lib64"
|
||||||
else "lib"
|
else "lib"
|
||||||
else null;
|
else null;
|
||||||
extensions = lib.optionalAttrs final.hasSharedLibraries {
|
extensions = optionalAttrs final.hasSharedLibraries {
|
||||||
sharedLibrary =
|
sharedLibrary =
|
||||||
if final.isDarwin then ".dylib"
|
if final.isDarwin then ".dylib"
|
||||||
else if final.isWindows then ".dll"
|
else if final.isWindows then ".dll"
|
||||||
|
@ -134,9 +152,9 @@ rec {
|
||||||
# uname -m
|
# uname -m
|
||||||
processor =
|
processor =
|
||||||
if final.isPower64
|
if final.isPower64
|
||||||
then "ppc64${lib.optionalString final.isLittleEndian "le"}"
|
then "ppc64${optionalString final.isLittleEndian "le"}"
|
||||||
else if final.isPower
|
else if final.isPower
|
||||||
then "ppc${lib.optionalString final.isLittleEndian "le"}"
|
then "ppc${optionalString final.isLittleEndian "le"}"
|
||||||
else if final.isMips64
|
else if final.isMips64
|
||||||
then "mips64" # endianness is *not* included on mips64
|
then "mips64" # endianness is *not* included on mips64
|
||||||
else final.parsed.cpu.name;
|
else final.parsed.cpu.name;
|
||||||
|
@ -202,8 +220,8 @@ rec {
|
||||||
else if final.isS390 && !final.isS390x then null
|
else if final.isS390 && !final.isS390x then null
|
||||||
else if final.isx86_64 then "x86_64"
|
else if final.isx86_64 then "x86_64"
|
||||||
else if final.isx86 then "i386"
|
else if final.isx86 then "i386"
|
||||||
else if final.isMips64n32 then "mipsn32${lib.optionalString final.isLittleEndian "el"}"
|
else if final.isMips64n32 then "mipsn32${optionalString final.isLittleEndian "el"}"
|
||||||
else if final.isMips64 then "mips64${lib.optionalString final.isLittleEndian "el"}"
|
else if final.isMips64 then "mips64${optionalString final.isLittleEndian "el"}"
|
||||||
else final.uname.processor;
|
else final.uname.processor;
|
||||||
|
|
||||||
# Name used by UEFI for architectures.
|
# Name used by UEFI for architectures.
|
||||||
|
@ -255,7 +273,7 @@ rec {
|
||||||
if pkgs.stdenv.hostPlatform.canExecute final
|
if pkgs.stdenv.hostPlatform.canExecute final
|
||||||
then "${pkgs.runtimeShell} -c '\"$@\"' --"
|
then "${pkgs.runtimeShell} -c '\"$@\"' --"
|
||||||
else if final.isWindows
|
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
|
else if final.isLinux && pkgs.stdenv.hostPlatform.isLinux && final.qemuArch != null
|
||||||
then "${qemu-user}/bin/qemu-${final.qemuArch}"
|
then "${qemu-user}/bin/qemu-${final.qemuArch}"
|
||||||
else if final.isWasi
|
else if final.isWasi
|
||||||
|
@ -306,10 +324,10 @@ rec {
|
||||||
let
|
let
|
||||||
f = args.rustc.platform.target-family;
|
f = args.rustc.platform.target-family;
|
||||||
in
|
in
|
||||||
if builtins.isList f then f else [ f ]
|
if isList f then f else [ f ]
|
||||||
)
|
)
|
||||||
else lib.optional final.isUnix "unix"
|
else optional final.isUnix "unix"
|
||||||
++ lib.optional final.isWindows "windows";
|
++ optional final.isWindows "windows";
|
||||||
|
|
||||||
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_vendor
|
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_vendor
|
||||||
vendor = let
|
vendor = let
|
||||||
|
@ -333,13 +351,13 @@ rec {
|
||||||
vendor_ = final.rust.platform.vendor;
|
vendor_ = final.rust.platform.vendor;
|
||||||
# TODO: deprecate args.rustc in favour of args.rust after 23.05 is EOL.
|
# TODO: deprecate args.rustc in favour of args.rust after 23.05 is EOL.
|
||||||
in args.rust.rustcTarget or args.rustc.config
|
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
|
# The name of the rust target if it is standard, or the json file
|
||||||
# containing the custom target spec.
|
# containing the custom target spec.
|
||||||
rustcTargetSpec = rust.rustcTargetSpec or (
|
rustcTargetSpec = rust.rustcTargetSpec or (
|
||||||
/**/ if rust ? platform
|
/**/ 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);
|
else final.rust.rustcTarget);
|
||||||
|
|
||||||
# The name of the rust target if it is standard, or the
|
# The name of the rust target if it is standard, or the
|
||||||
|
@ -348,7 +366,7 @@ rec {
|
||||||
#
|
#
|
||||||
# This is the name used by Cargo for target subdirectories.
|
# This is the name used by Cargo for target subdirectories.
|
||||||
cargoShortTarget =
|
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
|
# When used as part of an environment variable name, triples are
|
||||||
# uppercased and have all hyphens replaced by underscores:
|
# uppercased and have all hyphens replaced by underscores:
|
||||||
|
@ -356,17 +374,17 @@ rec {
|
||||||
# https://github.com/rust-lang/cargo/pull/9169
|
# https://github.com/rust-lang/cargo/pull/9169
|
||||||
# https://github.com/rust-lang/cargo/issues/8285#issuecomment-634202431
|
# https://github.com/rust-lang/cargo/issues/8285#issuecomment-634202431
|
||||||
cargoEnvVarTarget =
|
cargoEnvVarTarget =
|
||||||
lib.strings.replaceStrings ["-"] ["_"]
|
replaceStrings ["-"] ["_"]
|
||||||
(lib.strings.toUpper final.rust.cargoShortTarget);
|
(toUpper final.rust.cargoShortTarget);
|
||||||
|
|
||||||
# True if the target is no_std
|
# True if the target is no_std
|
||||||
# https://github.com/rust-lang/rust/blob/2e44c17c12cec45b6a682b1e53a04ac5b5fcc9d2/src/bootstrap/config.rs#L415-L421
|
# https://github.com/rust-lang/rust/blob/2e44c17c12cec45b6a682b1e53a04ac5b5fcc9d2/src/bootstrap/config.rs#L415-L421
|
||||||
isNoStdTarget =
|
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;
|
in assert final.useAndroidPrebuilt -> final.isAndroid;
|
||||||
assert lib.foldl
|
assert foldl
|
||||||
(pass: { assertion, message }:
|
(pass: { assertion, message }:
|
||||||
if assertion final
|
if assertion final
|
||||||
then pass
|
then pass
|
||||||
|
@ -374,4 +392,20 @@ rec {
|
||||||
true
|
true
|
||||||
(final.parsed.abi.assertions or []);
|
(final.parsed.abi.assertions or []);
|
||||||
final;
|
final;
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
# Everything in this attrset is the public interface of the file.
|
||||||
|
{
|
||||||
|
inherit
|
||||||
|
architectures
|
||||||
|
doubles
|
||||||
|
elaborate
|
||||||
|
equals
|
||||||
|
examples
|
||||||
|
flakeExposed
|
||||||
|
inspect
|
||||||
|
parse
|
||||||
|
platforms
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue