UnpackPhase: operation not permitted

TL;DR: Trying to write a Flake to build (parts of) LLVM from Scratch, but the unpackPhase gives me “changing permissions of […]: Operation not permitted”

So I’m trying to write a Flake (my first one) to build MLIR, which is part of the LLVM project, from scratch. For that, I trial-and-errored my way through nix-shell environments until I got one in which I could build the project. I wrapped the resulting derivation into the official flake.nix C-template (below) and tried to build the derivation (which will maybe work or not, we’ll see). But already during the unpackPhase, the nix build errors when trying to change permissions of the files in the source directory:

error: builder for '/nix/store/v9r7hk3714iznjl6r107cmyvmnn6jdw1-mlir-19700101.drv' failed with exit code 1;
       last 10 log lines:
       > chmod: changing permissions of '/nix/store/8r56m359c1mfvigba7kv47ax9qmc7w7i-source/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h': Operation not permitted

Could someone please help me to find the issue so I can fix it?


PS: I’m aware of this post but I don’t see how this would be applicable here as the underlying issues seem different.

The flake.nix:

  description = "Custom-Built MLIR";
  # Nixpkgs / NixOS version to use.
  inputs.nixpkgs.url = "nixpkgs/nixos-22.11";

  outputs = { self, nixpkgs }:

      # to work with older version of flakes
      lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
      # Generate a user-friendly version number.
      version = builtins.substring 0 8 lastModifiedDate;
      # System types to support.
      supportedSystems = [ "x86_64-linux" ]; #"x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
      # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
      # Nixpkgs instantiated for supported system types.
      nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; });


      # A Nixpkgs overlay.
      overlay = final: prev: {
        mlir = with final; stdenv.mkDerivation rec {
          name = "mlir-${version}";
          src = fetchFromGitHub {
            owner = "llvm";
            repo = "llvm-project";
            rev = "49caf7012170422afa84868598063818f9344228";
            sha256 = "sha256-j+ladpx8NfJGszj17oRkgvb4U2race+2DTKLtRZGeUM=";

          sourceRoot = "${src}/llvm";

          nativeBuildInputs = [
          propagatedBuildInputs = [ ncurses zlib ];

          cmakeFlags = [
            # Debug for debug builds
            # inst will be our installation prefix
            "-DCMAKE_INSTALL_PREFIX=../inst" # I know, this has to be patched still
            # change this to enable the projects you need
            # this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need
            # Using clang and lld speeds up the build, we recomment adding:
            # CCache can drastically speed up further rebuilds, try adding:
            # libxml2 needs to be disabled because the LLVM build system ignores its .la
            # file and doesn't link zlib as well.
            # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812


      # Provide some binary packages for selected system types.
      packages = forAllSystems (system:
          inherit (nixpkgsFor.${system}) mlir;

      # The default package for 'nix build'. This makes sense if the
      # flake provides only one package or there is a clear "main"
      # package.
      defaultPackage = forAllSystems (system: self.packages.${system}.mlir);

      # A NixOS module, if applicable (e.g. if the package provides a system service).
      nixosModules.mlir =
        { pkgs, ... }:
          nixpkgs.overlays = [ self.overlay ];
          environment.systemPackages = [ pkgs.mlir ];

1 Like

This should be: sourceRoot = "source/llvm";

The source root is used after the source has been copied to the build’s working directory, so it shouldn’t refer to the source in the nix store again.


Thank you, that was the problem! I was confused there because of how the source root was defined in other expressions I looked at.

1 Like