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

File access time is not normalized when importing to store #8426

Open
infinisil opened this issue May 31, 2023 · 2 comments
Open

File access time is not normalized when importing to store #8426

infinisil opened this issue May 31, 2023 · 2 comments
Labels
bug store Issues and pull requests concerning the Nix store

Comments

@infinisil
Copy link
Member

infinisil commented May 31, 2023

Describe the bug

The file access time is not normalized when importing that file to the store, leading to a potential build-time impurity.

Steps To Reproduce

  1. Create a test file:

    touch test
    
  2. Create a default.nix file with these contents:

    (import <nixpkgs> {}).runCommand "test" {} ''
      ls --full-time --time=atime ${./test} > $out
    ''
  3. Build it and show the result, notice how the resulting access time is not normalized to unix epoch 1:

    $ nix-build
    this derivation will be built:
      /nix/store/zc8kj3fgb5rxij4kbx6p9ynlldig9kla-test.drv
    building '/nix/store/zc8kj3fgb5rxij4kbx6p9ynlldig9kla-test.drv'...
    /nix/store/gdzg99df8f8a6zpxxrzj2m7p439b09ln-test
    
    $ cat result
    -r--r--r-- 2 nobody nogroup 0 2023-05-31 19:01:19.000000000 +0000 /nix/store/vd14zxkay784callbkhnmd88qv3p2rip-test
    
    $ cp --copy-contents result before
    
  4. Remove the imported file from the Nix store (requires a workaround, see Cannot delete store path with no roots #6141)

    $ rm result
    
    $ nix-store --query --referrers-closure /nix/store/vd14zxkay784callbkhnmd88qv3p2rip-test | xargs nix-store --delete
    finding garbage collector roots...
    removing stale link from '/nix/var/nix/gcroots/auto/7rfrjpxmdf6qk5q4h20s8ikk9lnw3347' to '/home/tweagysil/test/time3/result'
    deleting '/nix/store/zc8kj3fgb5rxij4kbx6p9ynlldig9kla-test.drv'
    deleting '/nix/store/gdzg99df8f8a6zpxxrzj2m7p439b09ln-test'
    deleting '/nix/store/vd14zxkay784callbkhnmd88qv3p2rip-test'
    deleting unused links...
    note: currently hard linking saves 15891.46 MiB
    3 store paths deleted, 0.00 MiB freed
    
  5. Update the access time of the file:

    $ touch test
    
  6. Build it again and diff the result, noticing that the result is different:

    $ nix-build
    this derivation will be built:
      /nix/store/zc8kj3fgb5rxij4kbx6p9ynlldig9kla-test.drv
    building '/nix/store/zc8kj3fgb5rxij4kbx6p9ynlldig9kla-test.drv'...
    /nix/store/gdzg99df8f8a6zpxxrzj2m7p439b09ln-test
    
    $ diff before result
    1c1
    < -r--r--r-- 2 nobody nogroup 0 2023-05-31 19:04:54.000000000 +0000 /nix/store/vd14zxkay784callbkhnmd88qv3p2rip-test
    ---
    > -r--r--r-- 2 nobody nogroup 0 2023-05-31 19:06:44.000000000 +0000 /nix/store/vd14zxkay784callbkhnmd88qv3p2rip-test
    

    Notice also how the hash of the file (/nix/store/vd14zxkay784callbkhnmd88qv3p2rip-test) did not change between the two builds, but the access time did change.

Expected behavior

The access time should get normalized to unix epoch 1, the same as is done to the modification time (mtime) already.

Additional context

The change time (ctime) and birth time (on some filesystems) is also not normalized, but this can't reasonable be fixed.

This work is sponsored by Antithesis

Priorities

Add 👍 to issues you find important.

@infinisil infinisil added the bug label May 31, 2023
@roberth roberth added the store Issues and pull requests concerning the Nix store label May 31, 2023
@thufschmitt
Copy link
Member

I confirm it isn't. I suspect it's indeed a bug, but I'd like to get @edolstra's opinion as it could have been a deliberate tradeoff from the origins of Nix (also note that build outputs aren't normalized either, except for their mtime)

@roberth
Copy link
Member

roberth commented Jan 11, 2024

atime and GC

atime could be useful for informing what garbage to collect first, as a store's garbage is also a cache, and atime is a good indicator of relevance. Performance may or may not be a challenge for the atime for GC idea.

Related:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug store Issues and pull requests concerning the Nix store
Projects
None yet
Development

No branches or pull requests

3 participants