Permission denied inside nix build?

When I build the following


 o = pkgs.runCommand "gdAddonsDir"{
    paths = with pkgs.inputs; [ #all flake inputs
      gdBlenderShort
      gdSpritePreview
      gdGizmo3D
      gdAllTrack
      (pkgs.fetchzip {
        url = "https://github.com/Terapixel-Games/spacemouse-godot/releases/download/v0.1.0/spacemouse-godot-linux-template_release-x86_64.zip";
        hash = "sha256-7YPPq6NeJl4Lg3WiNArXV5n5x82K/QiAmKWol3vk7b4=";
      })
      (pkgs.fetchzip {
        url = "https://github.com/vaner-org/viewpad/releases/download/1.0/viewpad-1.0.zip";
        hash = "sha256-T8dDAIw9StYWVjZ2JJZWgLMLQXUF0r4BmfuCgK9zvSw=";
      })
      gdAPRefact
      gdBlender
      gdFaveDock
      gdEyesee
      gdResWrangle
      gdAutoLay
      gdInsTabs
      #         gdi18n
      gdMass
      gdModBake
      gdAuto
      gdPasteImg
      gdProcMode
      gdScatter
      gdSheet
      gdAnimSheet
      gdExtHelper
      gdSceneMesh
      gdMesh2Col
      gdVarEdit
      gdTileCp
      gdExtraSnaps
      gdGambare
      gdCC
      gdDist
      gdTodo
      gdTimeTraker
      gdMeshLib
      gdCsgTk
      gdAssets
      gdAssetMan
      gdNodeCp
      gdShaderView
    ];
  }''
    mkdir $out
    for p in $paths; do
      cat $p/*.gd
      cp -r $p/* $out
    done
  '';

I get `cp: cannot create directory ‘/nix/store/py0yn95izb9wvlwxcshfpsfx3bfva
0n0-gdAddonsDir/addons/AnimatedSpritePreviewer’: Permission denied`

If I remove the flake inputs from the above derivation it work. How do I make it work with the flake inputs?

Try adding --no-preserve=mode to cp.

Folders in the nix store have the mode 0555 which prevents writing (creating files/folders within it), cp preserves this by default which causes the permission error.

that is not the fix. Again something wed flakes is happening because if I remove the flake inputs from the build it work correctly

Could you add || ls -l $out/addons to the end of the cp command?