Skip to content

Commit 3356114

Browse files
authored
Symlinks in materialized cause permissions err (#650)
1 parent f4b1272 commit 3356114

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

lib/materialize.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ let
7777
if materialized != null && !__pathExists materialized
7878
then ''
7979
echo "Materialized nix used for ${name} is missing. To fix run :" >> $ERR
80-
echo " cp -r ${calculateNoHash} ${toString materialized}" >> $ERR
80+
echo " cp -Lr ${calculateNoHash} ${toString materialized}" >> $ERR
8181
echo " chmod -R +w ${toString materialized}" >> $ERR
8282
cat $ERR
8383
false
@@ -91,7 +91,7 @@ let
9191
diff -ru ${materialized} ${calculateNoHash} || true
9292
echo "Materialized nix used for ${name} incorrect. To fix run :" >> $ERR
9393
echo " rm -rf ${toString materialized}" >> $ERR
94-
echo " cp -r ${calculateNoHash} ${toString materialized}" >> $ERR
94+
echo " cp -Lr ${calculateNoHash} ${toString materialized}" >> $ERR
9595
echo " chmod -R +w ${toString materialized}" >> $ERR
9696
fi
9797
'')
@@ -100,7 +100,7 @@ let
100100
cat $ERR
101101
false
102102
else
103-
cp -r ${unchecked} $out
103+
cp -Lr ${unchecked} $out
104104
# Make sure output files can be removed from the sandbox
105105
chmod -R +w $out
106106
fi
@@ -114,18 +114,18 @@ let
114114
};
115115
calculateNoHash = derivation;
116116
calculateUseHash =
117-
# Use `cp -r` here to get rid of symlinks so we know the result
117+
# Use `cp -Lr` here to get rid of symlinks so we know the result
118118
# can be safely materialized (no symlinks to the store).
119119
runCommand name hashArgs ''
120-
cp -r ${derivation} $out
120+
cp -Lr ${derivation} $out
121121
# Make sure output files can be removed from the sandbox
122122
chmod -R +w $out
123123
'';
124124
calculateUseMaterialized =
125125
assert materialized != null;
126126
assert __pathExists materialized;
127127
runCommand name (pkgs.lib.optionalAttrs (sha256 == null) hashArgs) ''
128-
cp -r ${materialized} $out
128+
cp -Lr ${materialized} $out
129129
# Make sure output files can be removed from the sandbox
130130
chmod -R +w $out
131131
'';

overlays/ghc-packages.nix

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ let
2222

2323
# Combines multiple derivations into one to make them
2424
# easier to materialize.
25-
combineFiles = name: ext: files: final.linkFarm name
26-
(final.lib.mapAttrsToList (name: path: {
27-
name = name + ext;
28-
inherit path;
29-
}) files);
25+
# Using `cp -Lr` here follows the symlinks and prevents
26+
# `access to path is forbidden in restricted mode`
27+
# errors on hydra when the materialized files are not present.
28+
combineFiles = name: ext: files:
29+
let links = final.linkFarm name
30+
(final.lib.mapAttrsToList (name: path: {
31+
name = name + ext;
32+
inherit path;
33+
}) files);
34+
in final.evalPackages.runCommand "${name}${ext}" {} ''
35+
cp -Lr ${links} $out
36+
'';
3037

3138
# Combine the all the boot package nix files for a given ghc
3239
# into a single derivation and materialize it.

0 commit comments

Comments
 (0)