From fe0ad4e02aa89f2c035ab783ebf99c085fd01597 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Tue, 7 May 2024 15:25:08 -0600 Subject: [PATCH] flake: refactor devShell creation Now instead of a derivation overridden from Lix, we use a mkShell derivation parameterized on an already called package.nix. This also lets callPackage take care of the buildPackages distinction for the devShell. Change-Id: I5ddfec40d83fa6136032da7606fe6d3d5014ef42 --- flake.nix | 65 ++--------------------------------------------------- package.nix | 53 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 66 deletions(-) diff --git a/flake.nix b/flake.nix index c03ec35ce..747723ff2 100644 --- a/flake.nix +++ b/flake.nix @@ -365,72 +365,11 @@ nix = pkgs.callPackage ./package.nix { inherit stdenv versionSuffix; busybox-sandbox-shell = pkgs.busybox-sandbox-shell or pkgs.default-busybox-sandbox; - forDevShell = true; + internalApiDocs = true; }; pre-commit = self.hydraJobs.pre-commit.${pkgs.system} or { }; in - (nix.override { - buildUnreleasedNotes = true; - officialRelease = false; - }).overrideAttrs - ( - prev: - { - # Required for clang-tidy checks - buildInputs = - prev.buildInputs - ++ [ - pkgs.just - pkgs.nixfmt - ] - ++ lib.optional (pre-commit ? enabledPackages) pre-commit.enabledPackages - ++ lib.optionals (stdenv.cc.isClang) [ - pkgs.llvmPackages.llvm - pkgs.llvmPackages.clang-unwrapped.dev - ]; - nativeBuildInputs = - prev.nativeBuildInputs - ++ lib.optional (stdenv.cc.isClang && !stdenv.buildPlatform.isDarwin) pkgs.buildPackages.bear - # Required for clang-tidy checks - ++ lib.optionals (stdenv.cc.isClang) [ - pkgs.buildPackages.cmake - pkgs.buildPackages.ninja - pkgs.buildPackages.llvmPackages.llvm.dev - ] - ++ - lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) - # for some reason that seems accidental and was changed in - # NixOS 24.05-pre, clang-tools is pinned to LLVM 14 when - # default LLVM is newer. - (pkgs.buildPackages.clang-tools.override { inherit (pkgs.buildPackages) llvmPackages; }) - ++ - lib.optionals (lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.buildPackages.clangbuildanalyzer) - [ pkgs.buildPackages.clangbuildanalyzer ]; - - src = null; - - strictDeps = false; - - shellHook = '' - PATH=$prefix/bin:$PATH - unset PYTHONPATH - export MANPATH=$out/share/man:$MANPATH - - # Make bash completion work. - XDG_DATA_DIRS+=:$out/share - - ${lib.optionalString (pre-commit ? shellHook) pre-commit.shellHook} - # Allow `touch .nocontribmsg` to turn this notice off. - if ! [[ -f .nocontribmsg ]]; then - cat ${contribNotice} - fi - ''; - } - // lib.optionalAttrs (stdenv.buildPlatform.isLinux && pkgs.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"; - } - ); + pkgs.callPackage nix.mkDevShell { pre-commit-checks = pre-commit; }; in forAllSystems ( system: diff --git a/package.nix b/package.nix index 7b086c77e..f1e938a30 100644 --- a/package.nix +++ b/package.nix @@ -57,8 +57,6 @@ # Set to true to build the release notes for the next release. buildUnreleasedNotes ? false, internalApiDocs ? false, - # Avoid setting things that would interfere with a functioning devShell - forDevShell ? false, # Not a real argument, just the only way to approximate let-binding some # stuff for argument defaults. @@ -241,7 +239,7 @@ stdenv.mkDerivation (finalAttrs: { ] ++ lib.optional stdenv.hostPlatform.isLinux util-linuxMinimal ++ lib.optional (!officialRelease && buildUnreleasedNotes) build-release-notes - ++ lib.optional (internalApiDocs || forDevShell) doxygen; + ++ lib.optional internalApiDocs doxygen; buildInputs = [ @@ -383,5 +381,54 @@ stdenv.mkDerivation (finalAttrs: { # flake.nix exports that into its overlay. passthru = { inherit (__forDefaults) boehmgc-nix libseccomp-nix; + + # The collection of dependency logic for this derivation is complicated enough that + # it's easier to parameterize the devShell off an already called package.nix. + mkDevShell = + { + mkShell, + just, + nixfmt, + glibcLocales, + bear, + pre-commit-checks, + clang-tools, + llvmPackages, + }: + let + glibcFix = lib.optionalAttrs (stdenv.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"; + }; + # for some reason that seems accidental and was changed in + # NixOS 24.05-pre, clang-tools is pinned to LLVM 14 when + # default LLVM is newer. + clang-tools_llvm = clang-tools.override { inherit llvmPackages; }; + in + mkShell ( + glibcFix + // { + + inputsFrom = [ finalAttrs ]; + + # For Meson to find Boost. + env = finalAttrs.env; + + packages = + [ + just + nixfmt + ] + ++ lib.optionals stdenv.cc.isClang [ + # Required for clang-tidy checks. + llvmPackages.llvm + llvmPackages.clang-unwrapped.dev + ] + ++ lib.optional (pre-commit-checks ? enabledPackages) pre-commit-checks.enabledPackages + ++ lib.optional (stdenv.cc.isClang && !stdenv.buildPlatform.isDarwin) bear + ++ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) clang-tools_llvm + ++ finalAttrs.checkInputs; + } + ); }; })