Copying symlink targets to $src

We have a repo with a subdirectory acting as the Cabal project. In this subdirectory lies the README.md but as a symlink targeting the one in repo root (i.e., ../README.md). I tried the following to forcefully copy over the target (so that it remains available to cabal builds).

+  36   projectDrv0 = haskellPackages.override {                                                                                                                          
+  37     overrides = self: super: with pkgs.haskell.lib; {                                                                                                               
+  38       summoner = overrideCabal (self.callCabal2nix "summoner" ./summoner-cli {}) (drv: {                                                                            
+  39         postUnpack = "cp --remove-destination ${./README.md} $src/README.md";                                                                                       
+  40                                                                                                                                                                     
+  41       });                                                                                                                                                                                                                                            
+  43     };                                                                                                                                                              
+  44   };   

But this does’t work:

cp: cannot remove '/nix/store/drzs7mzc03cjgs4q95maz0g1wcn8sv2d-summoner-cli/README.md': Permission denied

Is there no way to modify a source path in Nix?

$src is a separate derivation that contains the fetched sources. You’re trying to mutate something from that derivation.

The default unpackPhase will decompress/copy $src into the current directory, so your postUnpack should be modifying the current directory, not $src.

Though almost certainly you’ll need to make the path relative to $sourceRoot, so this might look like

postUnpack = "cp --remove-destination ${./README.md} $sourceRoot/README.md";
1 Like