Skip to content

Fix bug with using this project on flake builds of nontrivial packages#10

Open
farberbrodsky wants to merge 1 commit intodanielbarter:mainfrom
farberbrodsky:fix-access-to-build-inputs
Open

Fix bug with using this project on flake builds of nontrivial packages#10
farberbrodsky wants to merge 1 commit intodanielbarter:mainfrom
farberbrodsky:fix-access-to-build-inputs

Conversation

@farberbrodsky
Copy link
Copy Markdown

why and background

I was trying to use this project to make compile commands for a larger project that I wanted to get into, but it didn't work out of the box, given that I was determined to use a pure flake build. After seeing that hello from the example does work, I proceeded to something medium sized, jq. It didn't work either, and so I started debugging how the stdenv works and stuff. My work is not well documented but I am working in https://github.com/farberbrodsky/nix_mini_compile_commands_experiment .

reproduction

Anyways, to reproduce the error, try running nix build with the following flake.nix:

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
    mini-compile-commands = { url = "github:danielbarter/mini_compile_commands?rev=4009fccb4e5293aec133861aeb1e7e706607b5a4"; flake = false; };
  };

  outputs = { nixpkgs, mini-compile-commands, ... }:
    {
      packages = nixpkgs.lib.flip builtins.mapAttrs nixpkgs.legacyPackages (_system: pkgs:
        let
          mcc = (pkgs.callPackage mini-compile-commands {});
        in
          {
            default = (pkgs.jq.override {
              stdenv = mcc.wrap pkgs.stdenv;
            }).overrideAttrs (finalAttrs: previousAttrs: {
              buildInputs = (previousAttrs.buildInputs or []) ++ [ mcc.hook ];
            });
          }
      );
    };
}

You would get an error like:

/nix/store/0fqf34givcy8pz5ff4s8d9bvg08jmyqg-mini-compile-commands-hook/nix-support/setup-hook: line 9: kill: (740) - No such process

Which is actually because of:

/nix/store/0fqf34givcy8pz5ff4s8d9bvg08jmyqg-mini-compile-commands-hook/nix-support/setup-hook: line 2: mini_compile_commands_server.py: command not found

If you change mini-compile-commands's url to be github:farberbrodsky/mini_compile_commands?rev=c01dfacad0472ba805e472e155e72bc5f6d631f8, the bug is solved!

Note that if you want to see the compile_commands.json you actually need to run nix build ".#default.out" because the first output isn't called "out".

solution

change extraBuildInputs to extraNativeBuildInputs

bug analysis

looking around the comments in the stdenv's script, specifically the function activatePackage, it says that:

# Only dependencies whose host platform is guaranteed to match 
# build platform are included here. That would be `depsBuild*`,
# and legacy `nativeBuildInputs`, in general. .....

I think this is the cause and have not gone further in triaging this. But it really makes sense that this is a Native build input, as it is a part of running the compiler, not a part of any compiled program.

footnote

Really cool project, feels well designed in terms of the scope of the hook you added to nixpkgs. Let's hope that everything else works but I might have another pull request :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant