From add8a4df9ff846464d2c092cf228194066ab142e Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Sat, 2 Nov 2024 06:32:20 +0000 Subject: [PATCH] package.nix: Fix cross devShell The devShell relied on several packages directly from `pkgs` or used with a non-splice-aware functions. These would be built for the host system, making them useless in a devShell for the build system. Make sure that all packages are for the build system when needed. Some other minor changes also required: * Make devShells use `clangStdenv` because GCC is currently broken * Disable rr when making a cross stdenv Change-Id: Iee5f8a1a0c594139a50f2261b203491bd1644866 --- flake.nix | 2 +- package.nix | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/flake.nix b/flake.nix index 7eef62e63..5b9da52cd 100644 --- a/flake.nix +++ b/flake.nix @@ -486,7 +486,7 @@ let pkgs = nixpkgsFor.${system}.cross.${crossSystem}; in - makeShell pkgs pkgs.stdenv + makeShell pkgs pkgs.clangStdenv )) // { default = self.devShells.${system}.native-clangStdenvPackages; diff --git a/package.nix b/package.nix index 39ecea714..bb5ae1dee 100644 --- a/package.nix +++ b/package.nix @@ -456,6 +456,8 @@ stdenv.mkDerivation (finalAttrs: { # it's easier to parameterize the devShell off an already called package.nix. mkDevShell = { + pkgsBuildHost, + mkShell, bashInteractive, @@ -472,6 +474,13 @@ stdenv.mkDerivation (finalAttrs: { contribNotice, check-syscalls, + # Rust development tools + rust-analyzer, + cargo, + rustc, + rustfmt, + rustPlatform, + # debuggers gdb, rr, @@ -479,7 +488,7 @@ stdenv.mkDerivation (finalAttrs: { let glibcFix = lib.optionalAttrs (buildPlatform.isLinux && glibcLocales != null) { # Required to make non-NixOS Linux not complain about missing locale files during configure in a dev shell - LOCALE_ARCHIVE = "${lib.getLib pkgs.glibcLocales}/lib/locale/locale-archive"; + LOCALE_ARCHIVE = "${lib.getLib pkgsBuildHost.glibcLocales}/lib/locale/locale-archive"; }; pythonPackages = ( @@ -494,10 +503,10 @@ stdenv.mkDerivation (finalAttrs: { p.requests p.xdg-base-dirs p.packaging - (p.toPythonModule xonsh.passthru.unwrapped) + (p.toPythonModule pkgsBuildHost.xonsh.passthru.unwrapped) ] ); - pythonEnv = python3.withPackages pythonPackages; + pythonEnv = python3.pythonOnBuildForHost.withPackages pythonPackages; # pkgs.mkShell uses pkgs.stdenv by default, regardless of inputsFrom. actualMkShell = mkShell.override { inherit stdenv; }; @@ -545,12 +554,12 @@ stdenv.mkDerivation (finalAttrs: { stdenv.cc ] ++ [ - pkgs.rust-analyzer - pkgs.cargo - pkgs.rustc - pkgs.rustfmt - pkgs.rustPlatform.rustLibSrc - pkgs.rustPlatform.rustcSrc + rust-analyzer + cargo + rustc + rustfmt + rustPlatform.rustLibSrc + rustPlatform.rustcSrc ] ++ lib.optionals stdenv.cc.isClang [ # Required for clang-tidy checks. @@ -560,7 +569,7 @@ stdenv.mkDerivation (finalAttrs: { ++ lib.optional (pre-commit-checks ? enabledPackages) pre-commit-checks.enabledPackages ++ lib.optional (lib.meta.availableOn buildPlatform clangbuildanalyzer) clangbuildanalyzer ++ lib.optional (!stdenv.isDarwin) gdb - ++ lib.optional (lib.meta.availableOn buildPlatform rr) rr + ++ lib.optional (lib.meta.availableOn buildPlatform rr && hostPlatform == buildPlatform) rr ++ finalAttrs.checkInputs; shellHook = ''