Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Readonly nix store mount still allows for reflinks #5513

Open
Atemu opened this issue Nov 7, 2021 · 9 comments
Open

Test: Readonly nix store mount still allows for reflinks #5513

Atemu opened this issue Nov 7, 2021 · 9 comments
Labels

Comments

@Atemu
Copy link
Member

Atemu commented Nov 7, 2021

N.B.from @Ericson2314: Author says bug is fixed elsewhere, but we should still have an integration test to ensure this doesn't regress.


Describe the bug

A clear and concise description of what the bug is.

If you have a problem with a specific package or NixOS,
you probably want to file an issue at https://github.com/NixOS/nixpkgs/issues.

Steps To Reproduce

  1. Have a reflink capable fs like btrfs
  2. Have your $TMPDIR in the same mount as /nix so that things can theoretically be reflinked (i.e. TMPDIR=/nix/var/nix/tmp/ where /nix is a sinlgle mount)
  3. Try to copy a large file from the build dir to $out with cp --reflink=always for efficiency
  4. Invalid cross-device link

Expected behavior

A clear and concise description of what you expected to happen.

You should be able to reflink copy to the Nix store and back; its immutability should be achieved without a separate mount.

nix-env --version output

Additional context

Add any other context about the problem here.

Not being able to reflink across multiple mounts of the same FS is a kernel VFS limitation that is unlikely to be fixed any time soon.

The immutable xattr could be a good candidate. I kind of wonder why it wasn't chosen in the first place.

@Atemu Atemu added the bug label Nov 7, 2021
@thufschmitt
Copy link
Member

The immutable xattr could be a good candidate. I kind of wonder why it wasn't chosen in the first place.

Maybe that’s also possible with xattrs, but one very compelling argument for a read-only bind-mount is that thanks to mount namespaces we can remount the store rw inside the Nix process when needed, while keeping it read-only for the rest of the system.

@edolstra
Copy link
Member

edolstra commented Nov 8, 2021

We used to set the immutable bit but we got rid of it because it caused problems (b9c2b4d).

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/use-of-shallow-copy-reflinks-on-btrfs-xfs-zfs/24430/15

@stale stale bot removed the stale label Jan 6, 2023
@Atemu
Copy link
Member Author

Atemu commented Mar 9, 2023

At least for btrfs, this has been fixed in Linux. Modern kernels can now reflink across VFS boundaries as long as it's the same filesystem.

@Atemu Atemu closed this as not planned Won't fix, can't repro, duplicate, stale Mar 9, 2023
@Ericson2314 Ericson2314 reopened this Mar 9, 2023
@Ericson2314
Copy link
Member

@Atemu I am reopening this issue because even if no code changes are needed on Nix's side anymore, it would still be very nice to have a NixOS VM Integration test ensuring this works.

@Ericson2314 Ericson2314 changed the title Readonly nix store mount breaks reflinks Test: Readonly nix store mount still allows for reflinks Mar 9, 2023
@Kha
Copy link
Contributor

Kha commented Mar 10, 2023

In case anyone else is curious, the fix apparently landed in Linux 5.18

@Ericson2314
Copy link
Member

@Kha Thanks. Do you have a link to any sort of release notes? Or something else you read?

@Ericson2314
Copy link
Member

Thanks @Atemu. So yeah, would I love to see is a basic NixOS test reproducing this, and linking the above mailing list message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants