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

fetchTree has inconsistent behavior between Linux and Darwin (libarchive behavior) #9290

Closed
bryanhonof opened this issue Nov 3, 2023 · 2 comments · Fixed by #9557
Closed
Assignees
Labels
bug fetching Networking with the outside (non-Nix) world, input locking

Comments

@bryanhonof
Copy link
Member

bryanhonof commented Nov 3, 2023

cc: @tomberek

Describe the bug

When Nix tries to fetch a git repository that contains a so called AppleDouble file, it'll filter out that file on Darwin machines, but it will copy them over on Linux machines. This results in a NAR hash mismatch.

Steps To Reproduce

  1. Create a git repository that contains a file—with some contents in it—that has a ._ (dot underscore) as a prefix
  2. Use builtins.fetchTree to fetch said repo on a Linux machine
  3. Observe the NAR hash
  4. Repeat steps 2 and 3 on a Linux machine
  5. Notice the NAR hashes are different, whilst everything else stays the same
$ uname
Darwin
$ nix --refresh eval --impure --expr 'builtins.fetchTree {type="github";owner="bryanhonof";repo="AppleDoubleNix";}'
{ lastModified = 1699021234; lastModifiedDate = "20231103142034"; narHash = "sha256-oeP6/ZIGPYSA/hYmaLRODYF2eWF8/PcOJH9QTVwXHoY="; outPath = "/nix/store/xqcn1zm02sl84z3f7ay6dixjyig449qg-source"; rev = "5acb60fa3290ff4eb6c3f62706cb71d06b0e4831"; shortRev = "5acb60f"; }
$ uname
Linux
$ nix --refresh eval --impure --expr 'builtins.fetchTree {type="github";owner="bryanhonof";repo="AppleDoubleNix";}'
{ lastModified = 1699021234; lastModifiedDate = "20231103142034"; narHash = "sha256-uqXwlm5CG+qFI56WG3ezrVJ8i9zlQSvZ5bn+oEM/1w0="; outPath = "/nix/store/qr25ihyhcvqwqlh8079p51yscgwrbs1w-source"; rev = "5acb60fa3290ff4eb6c3f62706cb71d06b0e4831"; shortRev = "5acb60f"; }

Expected behavior

The NAR hashes for source code should be the same, regardless of architecture.

nix-env --version output

nix-env (Nix) 2.15.1

Additional context

Priorities

Add 👍 to issues you find important.

@bryanhonof bryanhonof added the bug label Nov 3, 2023
@tomberek tomberek self-assigned this Nov 3, 2023
@roberth roberth added the fetching Networking with the outside (non-Nix) world, input locking label Nov 3, 2023
@tomberek
Copy link
Contributor

Possible fix:

diff --git a/src/libutil/tarfile.cc b/src/libutil/tarfile.cc
index 1733c791c..1ce42221f 100644
--- a/src/libutil/tarfile.cc
+++ b/src/libutil/tarfile.cc
@@ -53,6 +53,7 @@ TarArchive::TarArchive(Source & source, bool raw) : buffer(65536)
         archive_read_support_format_raw(archive);
         archive_read_support_format_empty(archive);
     }
+    archive_read_set_format_option(this->archive, NULL ,"mac-ext",NULL);
     check(archive_read_open(archive, (void *)this, callback_open, callback_read, callback_close), "Failed to open archive (%s)");
 }
 
@@ -63,6 +64,7 @@ TarArchive::TarArchive(const Path & path)
 
     archive_read_support_filter_all(archive);
     archive_read_support_format_all(archive);
+    archive_read_set_format_option(this->archive,NULL, "mac-ext",NULL);
     check(archive_read_open_filename(archive, path.c_str(), 16384), "failed to open archive: %s");
 }
 

@tomberek
Copy link
Contributor

Related: #9327 (comment)

bryanhonof added a commit to bryanhonof/nix that referenced this issue Dec 7, 2023
…y with AppleDouble files

AppleDouble files were extracted differently on macOS machines than on other
UNIX's.
Setting `archive_read_set_format_option(this->archive, NULL ,"mac-ext",NULL)`
fixes this problem, since it just ignores the AppleDouble filel and treats it as
a normal one.
This was a problem since it caused source archives to be different between macOS
and Linux.

Ref: NixOS#9290
bryanhonof added a commit to bryanhonof/nix that referenced this issue Dec 7, 2023
…y with AppleDouble files

AppleDouble files were extracted differently on macOS machines than on other
UNIX's.
Setting `archive_read_set_format_option(this->archive, NULL ,"mac-ext",NULL)`
fixes this problem, since it just ignores the AppleDouble filel and treats it as
a normal one.
This was a problem since it caused source archives to be different between macOS
and Linux.

Ref: NixOS#9290
bryanhonof added a commit to bryanhonof/nix that referenced this issue Dec 7, 2023
…y with AppleDouble files

AppleDouble files were extracted differently on macOS machines than on other
UNIX's.
Setting `archive_read_set_format_option(this->archive, NULL ,"mac-ext",NULL)`
fixes this problem, since it just ignores the AppleDouble file and treats it as
a normal one.
This was a problem since it caused source archives to be different between macOS
and Linux.

Ref: NixOS#9290
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fetching Networking with the outside (non-Nix) world, input locking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants