Open aspiwack opened 3 years ago
With overlays, the last layer wins. In this case, that's the "customization layer" aka contents
layer, where /bin
is a symlink to
a store path.
It seems that contents
should be a function of the base image, at least conceptually. We'll probably want to do the merging in fakeroot.
contents
should be redesigned regardless: https://github.com/NixOS/nixpkgs/issues/94636#issuecomment-755246646
I marked this as stale due to inactivity. → More info
This issue is probably related #102962
I hit this problem because by fromImage
had a symlink bin -> usr/bin
. This comment on issue #240919 points out that normal directories are merged as you'd expect but symlinks are overwritten entirely.
I had trouble with the suggestions in the above issue and related discussion. Solution I have now is to just repair the symlinks at the beginning of my entrypoint script eg:
# fix clobbered symlinks from the base image
for f in /usr/bin/*; do /bin/ln -s $f /bin/$(/bin/basename $f) 2>/dev/null || true; done
for f in /usr/lib/*; do /bin/ln -s $f /lib/$(/bin/basename $f) 2>/dev/null || true; done
I needed to use the full path to ln & basename here (provided by nix coreutils) bc, before fixing the symlink to /usr/lib/x86_64-linux-gnu
, all base image binaries in /usr/bin/
were broken and earlier in my path than /bin
stuff.
Describe the bug
When adding packages in the
contents
attribute ofbuildLayeredImage
, the entire/bin
directory gets overwritten, effectively breaking the starting image if there is one.To Reproduce
Without
contents
default.nix
:Then
With
contents
Then
Expected behavior
The
hello
symlink should be added to/bin
without removing the existing content of the directory.Additional context/metadata
@LnL7 @roberth
Maintainer information: