From e700e52405d7b7a4bb26f665d9557a401f434ae4 Mon Sep 17 00:00:00 2001 From: Artturin Date: Wed, 4 Dec 2024 21:53:50 +0200 Subject: [PATCH 01/10] python2: Fix alias usage on cross --- pkgs/development/interpreters/python/cpython/2.7/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/interpreters/python/cpython/2.7/default.nix b/pkgs/development/interpreters/python/cpython/2.7/default.nix index 7e926d682810b..063a96dea0f1d 100644 --- a/pkgs/development/interpreters/python/cpython/2.7/default.nix +++ b/pkgs/development/interpreters/python/cpython/2.7/default.nix @@ -204,7 +204,7 @@ let ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ "--disable-toolbox-glue" ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ - "PYTHON_FOR_BUILD=${lib.getBin buildPackages.python}/bin/python" + "PYTHON_FOR_BUILD=${lib.getBin buildPackages.python27}/bin/python" "ac_cv_buggy_getaddrinfo=no" # Assume little-endian IEEE 754 floating point when cross compiling "ac_cv_little_endian_double=yes" @@ -239,7 +239,7 @@ let nativeBuildInputs = [ autoreconfHook ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) - [ buildPackages.stdenv.cc buildPackages.python ]; + [ buildPackages.stdenv.cc buildPackages.python27 ]; mkPaths = paths: { C_INCLUDE_PATH = lib.makeSearchPathOutput "dev" "include" paths; From 40e543da83c5c123e25c7694dd3a6aa97691e985 Mon Sep 17 00:00:00 2001 From: Artturin Date: Wed, 4 Dec 2024 22:04:56 +0200 Subject: [PATCH 02/10] saleae-logic: Use platforms instead of assert --- pkgs/by-name/sa/saleae-logic/package.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/by-name/sa/saleae-logic/package.nix b/pkgs/by-name/sa/saleae-logic/package.nix index 27b01dc5ffe1c..7d1a95418e1a6 100644 --- a/pkgs/by-name/sa/saleae-logic/package.nix +++ b/pkgs/by-name/sa/saleae-logic/package.nix @@ -22,8 +22,6 @@ let in -assert stdenv.hostPlatform.system == "x86_64-linux"; - stdenv.mkDerivation rec { pname = "saleae-logic"; version = "1.2.18"; @@ -92,7 +90,7 @@ stdenv.mkDerivation rec { homepage = "https://www.saleae.com/"; sourceProvenance = with sourceTypes; [ binaryNativeCode ]; license = licenses.unfree; - platforms = platforms.linux; + platforms = intersectLists platforms.x86_64 platforms.linux; maintainers = [ maintainers.bjornfor ]; }; } From 266e22539baa60a181a1f34290e76273cfb58a08 Mon Sep 17 00:00:00 2001 From: Artturin Date: Fri, 6 Dec 2024 03:26:53 +0200 Subject: [PATCH 03/10] haskellPackages.mkDerivation: Fix `cannot coerce null to a string` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.github.com/NixOS/nixpkgs/issues/362272 Fixes ``` $ nix repl --file . --system aarch64-darwin nix-repl> pkgsCross.aarch64-multiplatform.haskellPackages.ghc-lib.env error: … while evaluating attribute 'LOCALE_ARCHIVE' of derivation 'ghc-shell-for-ghc-lib-aarch64-unknown-linux-gnu-9.6.6.20240701-aarch64-unknown-linux-gnu' error: cannot coerce null to a string: null ``` --- pkgs/development/haskell-modules/generic-builder.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 14afa3dfe6b44..7617bae86ecee 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -802,7 +802,7 @@ stdenv.mkDerivation ({ buildInputs = otherBuildInputsSystem; LANG = "en_US.UTF-8"; - LOCALE_ARCHIVE = lib.optionalString (stdenv.hostPlatform.libc == "glibc") "${buildPackages.glibcLocales}/lib/locale/locale-archive"; + LOCALE_ARCHIVE = lib.optionalString (stdenv.buildPlatform.libc == "glibc") "${buildPackages.glibcLocales}/lib/locale/locale-archive"; "NIX_${ghcCommandCaps}" = "${ghcEnv}/bin/${ghcCommand}"; "NIX_${ghcCommandCaps}PKG" = "${ghcEnv}/bin/${ghcCommand}-pkg"; # TODO: is this still valid? From 68ebeaf5fe4d88e02b82103e0085b27326648dc4 Mon Sep 17 00:00:00 2001 From: Artturin Date: Fri, 6 Dec 2024 04:01:59 +0200 Subject: [PATCH 04/10] treewide: Change unnecessary aborts to throws `throw`s are better because they don't abort evaluation when evaluating the whole set. Fixes `error: evaluation aborted with the following error message: 'Unsupported platform: arm64.'` on linux cross from darwin --- pkgs/applications/networking/cluster/k3s/builder.nix | 8 ++++---- pkgs/by-name/de/debase/package.nix | 2 +- pkgs/by-name/ni/nim-unwrapped-2_2/package.nix | 4 ++-- pkgs/by-name/vi/virtual-ans/package.nix | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/applications/networking/cluster/k3s/builder.nix b/pkgs/applications/networking/cluster/k3s/builder.nix index abf25306acab1..c19bf46fa263b 100644 --- a/pkgs/applications/networking/cluster/k3s/builder.nix +++ b/pkgs/applications/networking/cluster/k3s/builder.nix @@ -137,7 +137,7 @@ let s: mutFirstChar lib.toLower (lib.concatMapStrings (mutFirstChar lib.toUpper) (lib.splitString "-" s)); - # finds the images archive for the desired architecture, aborts in case no suitable archive is found + # finds the images archive for the desired architecture, throws in case no suitable archive is found findImagesArchive = arch: let @@ -145,17 +145,17 @@ let in lib.findFirst ( n: lib.hasInfix arch n - ) (abort "k3s: no airgap images for ${arch} available") imagesVersionsNames; + ) (throw "k3s: no airgap images for ${arch} available") imagesVersionsNames; # a shortcut that provides the images archive for the host platform. Currently only supports - # aarch64 (arm64) and x86_64 (amd64), aborts on other architectures. + # aarch64 (arm64) and x86_64 (amd64), throws on other architectures. airgapImages = fetchurl ( if stdenv.hostPlatform.isAarch64 then imagesVersions.${findImagesArchive "arm64"} else if stdenv.hostPlatform.isx86_64 then imagesVersions.${findImagesArchive "amd64"} else - abort "k3s: airgap images cannot be found automatically for architecture ${stdenv.hostPlatform.linuxArch}, consider using an image archive with an explicit architecture." + throw "k3s: airgap images cannot be found automatically for architecture ${stdenv.hostPlatform.linuxArch}, consider using an image archive with an explicit architecture." ); # so, k3s is a complicated thing to package diff --git a/pkgs/by-name/de/debase/package.nix b/pkgs/by-name/de/debase/package.nix index 1b300f1e21de5..70be9b81eed63 100644 --- a/pkgs/by-name/de/debase/package.nix +++ b/pkgs/by-name/de/debase/package.nix @@ -72,7 +72,7 @@ stdenv.mkDerivation rec { else if stdenv.hostPlatform.isAarch64 then "arm64" else - abort "unsupported system: ${stdenv.system}" + throw "unsupported system: ${stdenv.system}" }" ]; diff --git a/pkgs/by-name/ni/nim-unwrapped-2_2/package.nix b/pkgs/by-name/ni/nim-unwrapped-2_2/package.nix index 311c0f5b9d806..41307f3202715 100644 --- a/pkgs/by-name/ni/nim-unwrapped-2_2/package.nix +++ b/pkgs/by-name/ni/nim-unwrapped-2_2/package.nix @@ -45,7 +45,7 @@ let else if isx86_64 then "amd64" else - abort "no Nim CPU support known for ${config}"; + throw "no Nim CPU support known for ${config}"; parseOs = platform: @@ -72,7 +72,7 @@ let else if isiOS then "iOS" else - abort "no Nim OS support known for ${config}"; + throw "no Nim OS support known for ${config}"; parsePlatform = p: { cpu = parseCpu p; diff --git a/pkgs/by-name/vi/virtual-ans/package.nix b/pkgs/by-name/vi/virtual-ans/package.nix index 4a7467da125d6..e71bc00e3042b 100644 --- a/pkgs/by-name/vi/virtual-ans/package.nix +++ b/pkgs/by-name/vi/virtual-ans/package.nix @@ -46,7 +46,7 @@ stdenv.mkDerivation rec { startScript = if stdenv.hostPlatform.isx86_32 then "START_LINUX_X86" else if stdenv.hostPlatform.isx86_64 then "START_LINUX_X86_64" #else if stdenv.hostPlatform.isDarwin then "START_MACOS.app" # disabled because I cannot test on Darwin - else abort "Unsupported platform: ${stdenv.hostPlatform.linuxArch}."; + else throw "Unsupported platform: ${stdenv.hostPlatform.linuxArch}."; linuxExecutable = if stdenv.hostPlatform.isx86_32 then "pixilang_linux_x86" else if stdenv.hostPlatform.isx86_64 then "pixilang_linux_x86_64" From 653b3558ee1b3b409e34cc6c8ff06c084394ed0f Mon Sep 17 00:00:00 2001 From: Artturin Date: Fri, 6 Dec 2024 18:53:43 +0200 Subject: [PATCH 05/10] tests-stdenv-gcc-stageCompare: Fail gracefullyier Don't fail with a missing attribute error, so the error can be handled. --- pkgs/test/stdenv/gcc-stageCompare.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/test/stdenv/gcc-stageCompare.nix b/pkgs/test/stdenv/gcc-stageCompare.nix index e5c2ed5921b30..c4a0179fb8463 100644 --- a/pkgs/test/stdenv/gcc-stageCompare.nix +++ b/pkgs/test/stdenv/gcc-stageCompare.nix @@ -14,6 +14,7 @@ }: assert stdenv.cc.isGNU; + with pkgs; # rebuild gcc using the "final" stdenv let gcc-stageCompare = (gcc-unwrapped.override { @@ -25,7 +26,9 @@ let gcc-stageCompare = (gcc-unwrapped.override { }).overrideAttrs(_: { NIX_OUTPATH_USED_AS_RANDOM_SEED = stdenv.cc.cc.out; }); -in (runCommand "gcc-stageCompare" {} '' +in +assert lib.assertMsg (gcc-stageCompare ? checksum) "tests-stdenv-gcc-stageCompare: No `checksum` output in `gcc-stageCompare` see conditional in `gcc/common/checksum.nix`"; +(runCommand "gcc-stageCompare" {} '' diff -sr ${pkgs.gcc-unwrapped.checksum}/checksums ${gcc-stageCompare.checksum}/checksums && touch $out '').overrideAttrs (a: { meta = (a.meta or { }) // { platforms = lib.platforms.linux; }; From d9323ae92d3a577cc93e8cbedddbcd70446b160f Mon Sep 17 00:00:00 2001 From: Artturin Date: Sat, 7 Dec 2024 21:47:20 +0200 Subject: [PATCH 06/10] frr: Fix cross `snmpSupport` to remove warning which interferes with cross eval Release eval fails with ``` nix-env failed: trace: evaluation warning: cannot enable SNMP support due to cross-compilation issues with net-snmp-config ``` --- pkgs/by-name/fr/frr/package.nix | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/pkgs/by-name/fr/frr/package.nix b/pkgs/by-name/fr/frr/package.nix index 29f2d42d28f8f..bc96316e71111 100644 --- a/pkgs/by-name/fr/frr/package.nix +++ b/pkgs/by-name/fr/frr/package.nix @@ -33,15 +33,9 @@ , nettools , nixosTests -# FRR's configure.ac gets SNMP options by executing net-snmp-config on the build host -# This leads to compilation errors when cross compiling. -# E.g. net-snmp-config for x86_64 does not return the ARM64 paths. -# -# SNMP_LIBS="`${NETSNMP_CONFIG} --agent-libs`" -# SNMP_CFLAGS="`${NETSNMP_CONFIG} --base-cflags`" -, snmpSupport ? stdenv.buildPlatform.canExecute stdenv.hostPlatform - -# other general options besides snmp support + +# general options +, snmpSupport ? true , rpkiSupport ? true , numMultipath ? 64 , watchfrrSupport ? true @@ -81,9 +75,6 @@ , ospfApi ? true }: -lib.warnIf (!(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) - "cannot enable SNMP support due to cross-compilation issues with net-snmp-config" - stdenv.mkDerivation (finalAttrs: { pname = "frr"; version = "10.1"; @@ -194,6 +185,9 @@ stdenv.mkDerivation (finalAttrs: { (lib.strings.enableFeature ospfApi "ospfapi") # Cumulus options (lib.strings.enableFeature cumulusSupport "cumulus") + ] ++ lib.optionals snmpSupport [ + # Used during build for paths, `dev` has build shebangs so can be run during build. + "NETSNMP_CONFIG=${lib.getDev net-snmp}/bin/net-snmp-config" ]; postPatch = '' From c9b3b5de62425be792ecbdc232f38a762ee95311 Mon Sep 17 00:00:00 2001 From: Artturin Date: Sun, 8 Dec 2024 21:59:01 +0200 Subject: [PATCH 07/10] reposilitePlugins: Fix eval --- pkgs/by-name/re/reposilite/plugins.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/re/reposilite/plugins.nix b/pkgs/by-name/re/reposilite/plugins.nix index 28ecae2264f4a..3d80d92673eef 100644 --- a/pkgs/by-name/re/reposilite/plugins.nix +++ b/pkgs/by-name/re/reposilite/plugins.nix @@ -3,7 +3,7 @@ makeScopeWithSplicing', }: makeScopeWithSplicing' { - otherSplices = generateSplicesForMkScope; + otherSplices = generateSplicesForMkScope "reposilitePlugins"; f = self: { From 764c99481a7d26b44aedfb61b0bc17cfa2d95e4a Mon Sep 17 00:00:00 2001 From: Artturin Date: Mon, 9 Dec 2024 20:04:11 +0200 Subject: [PATCH 08/10] lib/tests/release.nix: Fix build if `impure.nix` returns a cross pkgs In https://www.github.com/NixOS/nixpkgs/pull/341067 `ofborg-eval-lib-tests` fails because it uses `pkgsHostTarget` of the cross pkgs ```diff diff --git a/pkgs/top-level/impure.nix b/pkgs/top-level/impure.nix index 4d847e280f4b..7f0099b254f0 100644 --- a/pkgs/top-level/impure.nix +++ b/pkgs/top-level/impure.nix @@ -86,4 +86,6 @@ assert args ? system -> !(args ? localSystem); import ./. (builtins.removeAttrs args [ "system" ] // { inherit config overlays localSystem; -}) +} // (if ((localSystem.system or localSystem) == "x86_64-linux" || (localSystem.system or localSystem) == "aarch64-linux") then { + crossSystem = { config = "aarch64-unknown-linux-gnu"; }; + } else {}) ) ``` --- lib/tests/release.nix | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/tests/release.nix b/lib/tests/release.nix index 5334498d08449..d83c15c511fab 100644 --- a/lib/tests/release.nix +++ b/lib/tests/release.nix @@ -1,18 +1,23 @@ { # The pkgs used for dependencies for the testing itself # Don't test properties of pkgs.lib, but rather the lib in the parent directory pkgs ? import ../.. {} // { lib = throw "pkgs.lib accessed, but the lib tests should use nixpkgs' lib path directly!"; }, + # For testing someone may edit impure.nix to return cross pkgs, use `pkgsBuildBuild` directly so everything here works. + pkgsBB ? pkgs.pkgsBuildBuild, nix ? pkgs-nixVersions.stable, nixVersions ? [ pkgs-nixVersions.minimum nix pkgs-nixVersions.latest ], - pkgs-nixVersions ? import ./nix-for-tests.nix { inherit pkgs; }, + pkgs-nixVersions ? import ./nix-for-tests.nix { pkgs = pkgsBB; }, }: let lib = import ../.; testWithNix = nix: - import ./test-with-nix.nix { inherit lib nix pkgs; }; + import ./test-with-nix.nix { + inherit lib nix; + pkgs = pkgsBB; + }; in - pkgs.symlinkJoin { + pkgsBB.symlinkJoin { name = "nixpkgs-lib-tests"; paths = map testWithNix nixVersions; } From 8a6ca8f17ca8b5123f81beab5fc648949e9ca473 Mon Sep 17 00:00:00 2001 From: Artturin Date: Mon, 9 Dec 2024 20:42:36 +0200 Subject: [PATCH 09/10] nixpkgs-manual.{lib-docs,tests}: Fix cross build --- doc/doc-support/lib-function-docs.nix | 2 +- doc/tests/manpage-urls.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/doc-support/lib-function-docs.nix b/doc/doc-support/lib-function-docs.nix index 61671bd39059b..51b4601975c32 100644 --- a/doc/doc-support/lib-function-docs.nix +++ b/doc/doc-support/lib-function-docs.nix @@ -95,7 +95,7 @@ stdenvNoCC.mkDerivation { fileset = ../../lib; }; - buildInputs = [ + nativeBuildInputs = [ nixdoc nix ]; diff --git a/doc/tests/manpage-urls.nix b/doc/tests/manpage-urls.nix index 214c236160098..913aebe4ebe80 100644 --- a/doc/tests/manpage-urls.nix +++ b/doc/tests/manpage-urls.nix @@ -17,7 +17,7 @@ invalidateFetcherByDrvHash ( { nativeBuildInputs = [ cacert - (python3.withPackages (p: [ + (python3.pythonOnBuildForHost.withPackages (p: [ p.aiohttp p.rich p.structlog From 276fe40ff34d0dcb0cf11a6f81c16fdbd6a66cd3 Mon Sep 17 00:00:00 2001 From: Artturin Date: Tue, 10 Dec 2024 17:03:55 +0200 Subject: [PATCH 10/10] swift: Fix eval failure `error: expected a string but found null: null` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dunno if this is correct, there's other `hostPlatform.isDarwin` conditionals which may be wrong. Leaving the other conditionals to swift maintainers or people who are interested in swift cross-compilation ``` $ nix repl --file . --system aarch64-darwin nix-repl> pkgsCross.aarch64-multiplatform.swift «derivation /nix/store/kqbaqwdfc9g0yvkq4ffrlqspranprlmy-swift-wrapper-aarch64-unknown-linux-gnu-5.8.drv» nix-repl> pkgsCross.aarch64-multiplatform.buildPackages.swift error: error: expected a string but found null: null at /home/artturin/nixgits/my-nixpkgs/.worktree/2/pkgs/development/compilers/swift/compiler/default.nix:586:11: 585| #WATCHOS_SIMULATOR 586| }.${targetPlatform.darwinPlatform}} | ^ 587| ``` --- pkgs/development/compilers/swift/compiler/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/compilers/swift/compiler/default.nix b/pkgs/development/compilers/swift/compiler/default.nix index 8e8cf798db4f2..b8a4159003222 100644 --- a/pkgs/development/compilers/swift/compiler/default.nix +++ b/pkgs/development/compilers/swift/compiler/default.nix @@ -541,7 +541,7 @@ in stdenv.mkDerivation { "; buildProject lldb llvm-project/lldb - ${lib.optionalString stdenv.hostPlatform.isDarwin '' + ${lib.optionalString stdenv.targetPlatform.isDarwin '' # Need to do a standalone build of concurrency for Darwin back deployment. # Based on: utils/swift_build_support/swift_build_support/products/backdeployconcurrency.py cmakeFlags="