Overriding llvmPackage source with local checkout in flake for clang-tools package

I am trying to create a dev environment where I can use clang-tools from a locally modified LLVM checkout.
I am not trying to do anything with a special stdenv, I only want to add a customized clang-tools package to the dev env.

My current flake is (flake used via direnv, with --impure due to the path):

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs =
    {
      self,
      nixpkgs,
    }:
    let
      system = "x86_64-linux";
      overlays = [
        (final: prev: {
          llvmPackages_custom = prev.llvmPackages_git.override (prev: {
            src = /home/user/dev/llvm/;
            doCheck = false;
            dontUnpack = true;
          });
        })
      ];
      pkgs = import nixpkgs {
        inherit system overlays;
      };
    in
    {
      packages.${system}.default = pkgs.stdenv.mkDerivation {
        name = "test";
        src = ./.;
        buildInputs = [
          pkgs.llvmPackages_custom.clang-tools
          pkgs.spdlog
        ];

      };
    };
}

But it looks like this is not actually overriding the source like I want it to. Instead, it is just llvmPackages_git. I’ve also tried a few permutations of src vs monorepoSrc, override vs overrideAttrs, and llvmPackages_custom vs llvmPackages_custom.clang-tools with no success. I must be doing something wrong here. Can anyone tell me what the correct way to do this would be?

CC @Patryk27 as the maintainer of the clang-tools package. Do you know how I could do this? Or would someone else from the maintainers listed for clang-tools in the nixpkgs search know (I didn’t want to ping 8 people)?

Hi!

llvmPackages doesn’t have an argument called src, it’s monorepoSrc:

… so try doing monorepoSrc = /home/user/dev/llvm; :eyes:

Let me know if it works - if it still doesn’t, will try to figure it out.

Thanks for the quick reply. That sadly did not work (s/src = /monorepoSrc = ):

user@nixos ~/d/l/flake-test [1]> nix build .
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:37:12:
           36|
           37|   strict = derivationStrict drvAttrs;
             |            ^
           38|

       … while evaluating derivation 'test'
         whose name attribute is located at /nix/store/9x1a429wj6sy54bfr028820n5mgyvdri-source/pkgs/stdenv/generic/make-derivation.nix:482:13

       … while evaluating attribute 'buildInputs' of derivation 'test'
         at /nix/store/9x1a429wj6sy54bfr028820n5mgyvdri-source/pkgs/stdenv/generic/make-derivation.nix:537:13:
          536|             depsHostHost = elemAt (elemAt dependencies 1) 0;
          537|             buildInputs = elemAt (elemAt dependencies 1) 1;
             |             ^
          538|             depsTargetTarget = elemAt (elemAt dependencies 2) 0;

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: expected a set but found a path: «unknown»/home/user/dev/llvm

Okie, approach v2.0:

monorepoSrc = (fetchGit /home/user/dev/llvm) // {
  passthru = {
    owner = "";
    repo = "";
    rev = "";
  };
};

We can’t use a plain path, because LLVM expects for monorepoSrc to be a derivation that builds the source (using fetchGit is the easiest way if you happen to use a Git-based checkout of LLVM), and the seemingly random owner, repo and rev come from here:

… and are probably used to build some sort of VERSION="..." string later compiled into LLVM for debugging purposes, I guess; but it seems they are not validated whatsoever, so empty strings are good as any.

I think this might be ‘working’, as in getting the right source, but I had to change llvmPackages_git to llvmPackages_21 because it complained about the major version, but I am now stuck at

error: builder for '/nix/store/ds3s71kichv3c7p5zln6xpmflfmyxyms-llvm-21.1.0-rc2.drv' failed with exit code 3;
       last 25 log lines:
       > -- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY - Failed
       > -- Performing Test HAVE_CXX_FLAG_COVERAGE
       > -- Performing Test HAVE_CXX_FLAG_COVERAGE - Success
       > -- Compiling and running to test HAVE_GNU_POSIX_REGEX
       > -- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
       > -- Compiling and running to test HAVE_POSIX_REGEX
       > -- Performing Test HAVE_POSIX_REGEX -- success
       > -- Compiling and running to test HAVE_STEADY_CLOCK
       > -- Performing Test HAVE_STEADY_CLOCK -- success
       > -- Compiling and running to test HAVE_PTHREAD_AFFINITY
       > -- Performing Test HAVE_PTHREAD_AFFINITY -- success
       > -- Configuring done (8.9s)
       > -- Generating done (1.6s)
       > CMake Warning:
       >   Manually-specified variables were not used by the project:
       >
       >     CMAKE_EXPORT_NO_PACKAGE_REGISTRY
       >     CMAKE_POLICY_DEFAULT_CMP0025
       >     LLVM_ENABLE_TERMINFO
       >
       > 
       > -- Build files have been written to: /build/llvm-src-21.1.0-rc2/llvm/build
       > cmake: enabled parallel building
       > cmake: enabled parallel installing
       > mismatch in the minor version! we have version 21.1.0-rc2 and expected the minor version to be '1'; the source has '0' instead
       For full logs, run:
         nix log /nix/store/ds3s71kichv3c7p5zln6xpmflfmyxyms-llvm-21.1.0-rc2.drv

Is this what you mean with VERSION?
Setting version in override to e.g., "21.1" errors out.

Current flake
{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs =
    {
      self,
      nixpkgs,
    }:
    let
      system = "x86_64-linux";
      overlays = [
        (final: prev: {
          llvmPackages_custom = prev.llvmPackages_21.override (prev: {
            monorepoSrc = (fetchGit /home/user/dev/llvm) // {
              passthru = {
                owner = "";
                repo = "";
                rev = "";
              };
            };
            doCheck = false;
            dontUnpack = true;
          });
        })
      ];
      pkgs = import nixpkgs {
        inherit system overlays;
      };
    in
    {
      packages.${system}.default = pkgs.stdenv.mkDerivation {
        name = "test";
        src = ./.;
        buildInputs = [
          pkgs.llvmPackages_custom.clang-tools
        ];

      };
    };
}

How about version = "21.0.0";, then? :eyes:

That worked (I do get a build error that’s unrelated to my changes though, not sure what the issue would be)

llvm> [177/4787] Building IntrinsicsLoongArch.h...
llvm> [178/4787] Building RuntimeLibcalls.inc...
llvm> FAILED: include/llvm/IR/RuntimeLibcalls.inc /build/llvm-src-22.0.0-unstable-2025-07-28/llvm/build/include/llvm/IR/RuntimeLibcalls.inc
llvm> cd /build/llvm-src-22.0.0-unstable-2025-07-28/llvm/build/include/llvm/IR && /nix/store/29ff3xl4sij5jdm4qqs097bhb0pqnbx1-llvm-tblgen-22.0.0-unstable-2025-07-28/bin/llvm-tblgen -gen-runtime-libcalls -I/build/llvm-src-22.0.0-unstable-2025-07-28/llvm/include/llvm/IR -I/build/llvm-src-22.0.0-unstable-2025-07-28/ll
vm/build/include -I/build/llvm-src-22.0.0-unstable-2025-07-28/llvm/include /build/llvm-src-22.0.0-unstable-2025-07-28/llvm/include/llvm/IR/RuntimeLibcalls.td --write-if-changed -o RuntimeLibcalls.inc -d RuntimeLibcalls.inc.d && /nix/store/a3w3ka2d796ghlhf31il839c0658m5ih-cmake-3.31.7/bin/cmake -E cmake_transform_de
pfile Ninja gccdepfile /build/llvm-src-22.0.0-unstable-2025-07-28/llvm /build/llvm-src-22.0.0-unstable-2025-07-28/llvm/include/llvm/IR /build/llvm-src-22.0.0-unstable-2025-07-28/llvm/build /build/llvm-src-22.0.0-unstable-2025-07-28/llvm/build/include/llvm/IR /build/llvm-src-22.0.0-unstable-2025-07-28/llvm/build/inc
lude/llvm/IR/RuntimeLibcalls.inc.d /build/llvm-src-22.0.0-unstable-2025-07-28/llvm/build/CMakeFiles/d/6da87e6a2bfd7be83bc1ed2d012cbfb2896365068d40253aba2587d8f7fb6c0c.d
llvm> error: The class 'SystemRuntimeLibrary' is not defined
llvm>
llvm> [179/4787] Building IntrinsicsMips.h...
llvm> [180/4787] Building IntrinsicsHexagon.h...
llvm> [181/4787] Building IntrinsicsNVPTX.h...

I’ll try my best to figure it out (unless you have ideas).

Thanks to @Patryk27, here is the flake that almost works:

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs =
    {
      self,
      nixpkgs,
    }:
    let
      system = "x86_64-linux";
      overlays = [
        (final: prev: {
          llvmPackages_custom = prev.llvmPackages_git.override (prev: {
            monorepoSrc = (fetchGit /home/user/dev/llvm/) // {
              passthru = {
                owner = "";
                repo = "";
                rev = "";
              };
            };
            version = "21.0.0";
            doCheck = false;
            dontUnpack = true;
          });
        })
      ];
      pkgs = import nixpkgs {
        inherit system overlays;
      };
    in
    {
      packages.${system}.default = pkgs.stdenv.mkDerivation {
        name = "test";
        src = ./.;
        buildInputs = [
          pkgs.llvmPackages_custom.clang-tools
        ];

      };
    };
}