Error: illegal path references in fixed-output derivation

I am building a cmake project and don’t know why this error occurs and how to solve it

(import <nixpkgs> {}).callPackage (
  {
    fetchFromGitHub,
    pkg-config,
    stdenv,
    lib,
    cmake,
    cacert,
    python3,
    ninja,
    ccache,
    nodejs_20,
  }:
    stdenv.mkDerivation (finalAttrs: rec {
      pname = "MaaFramework";
      version = "2.2.2";
      src = fetchFromGitHub {
        owner = "MaaXYZ";
        repo = finalAttrs.pname;
        rev = "ab0dcffc02650d722fed59eb5e6d994e3240c010";
        fetchSubmodules = true;
        sha256 = "sha256-zfjcK18u2qBD6eXf6wUTjBbEP35HT7jX5upl1OrUxaI=";
      };

      nativeBuildInputs = [
        pkg-config
        cmake
        python3
      ];
      # makeFlags = [
      #   "DMAADEPS_TRIPLET=maa-x64-linux"
      #   "DMAA_HASH_VERSION=2.2.2"
      #   "DBUILD_NODEJS_BINDING=ON"
      #   "PREFIX=${placeholder "out"}"
      # ];
      NIX_SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";

      preConfigure = ''
        python tools/maadeps-download.py x64-linux
      '';

      dontStrip = true;
      outputHashMode = "recursive";
      outputHashAlgo = "sha256";
      outputHash = lib.fakeHash;
    })
) {}

Well, why did you make it a fixed-output-derivation?

Because the python script downloads the binary file

I didn’t do that, why do you say that?

This makes it a fixed-output derivation. Remove these lines.
And if you need to access the network, ensure you do that within a fixed-output derivation that doesn’t download content with such path references (ideally you should use your own fetchers rather than using a python script that can execute arbitrary code with network access)

like deine a vairable to store which use fetchurl to get?

You may be interested in this nix issue I made about making this easier to debug:

and some of the stuff I linked from there. The most common causes of this error that I’m aware of are:

  • Cloning a git repo, which creates a bunch of sample hook scripts whose hashbangs directly reference your currently-installed bash (which is a nix store path, which is the disallowed thing). The main fix here is to wipe out any .git directories entirely if you don’t need them. (Note that fetchFromGitHub doesn’t clone the repo with git, it just downloads the requested revision as a tarball, so you don’t need to do anything there.)
  • The patch-shebangs step of the fixup phase in a normal derivation, which again replaces things like #!/bin/bash with store paths to your current bash version. The usual fix here is to set dontPatchShebangs = true; in your derivation, or even dontFixup = true; if you don’t need anything else from the fixup phase. I guess this might mean that your shebang lines in your scripts don’t work properly. Maybe you can manually patch them, or you can do something like have a fixed-output derivation that just downloads the stuff, and then another non-fixed-output derivation that does everything else, including patching the shebangs as appropriate.

thx,i works by this

{
  fetchurl,
  fetchFromGitHub,
  pkg-config,
  stdenv,
  lib,
  cmake,
  python3,
}: let
  maadepsdev = fetchurl {
    url = "https://github.com/MaaXYZ/MaaDeps/releases/download/v2.7.1/MaaDeps-x64-linux-devel.tar.xz";
    hash = "sha256-gneNVcaAmiXavMUgRBUnTajkgjQeOMnbQ9jDoghx+lY=";
  };
  maadepsruntime = fetchurl {
    url = "https://github.com/MaaXYZ/MaaDeps/releases/download/v2.7.1/MaaDeps-x64-linux-runtime.tar.xz";
    hash = "sha256-iz51FZKqPY8yYA7cilfqIH8W2Oyz33tH5qEOHNB0ny4=";
  };
in
  stdenv.mkDerivation rec {
    pname = "MaaFramework";
    version = "2.2.2";
    src = fetchFromGitHub {
      owner = "MaaXYZ";
      repo = pname;
      rev = "ab0dcffc02650d722fed59eb5e6d994e3240c010";
      fetchSubmodules = true;
      sha256 = "sha256-zfjcK18u2qBD6eXf6wUTjBbEP35HT7jX5upl1OrUxaI=";
    };

    nativeBuildInputs = [
      pkg-config
      cmake
      python3
    ];
    # makeFlags = [
    #   "DMAADEPS_TRIPLET=maa-x64-linux"
    #   "DMAA_HASH_VERSION=2.2.2"
    #   "DBUILD_NODEJS_BINDING=ON"
    #   "PREFIX=${placeholder "out"}"
    # ];

    preConfigure = ''
      mkdir -p 3rdparty/MaaDeps/tarball
      tar xf ${maadepsdev} -C 3rdparty/MaaDeps/
      tar xf ${maadepsruntime} -C 3rdparty/MaaDeps/
    '';
  }
1 Like