NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.5k stars 1.5k forks source link

Prevent NIX_SHOW_STATS_PATH from being overwritten #6058

Open PAI5REECHO opened 2 years ago

PAI5REECHO commented 2 years ago

Describe the bug

NIX_SHOW_STATS_PATH is overwritten even if a statistics file already exists at the given path. This can be problematic when profiling certain nix tools such as nixops that invoke multiple instances of nix in quick succession. You're only able to have a stats file for the latest invocation of nix in these scenarios, and all previous invocations have their stats file overwritten.

Steps To Reproduce

  1. Profile a nixops deployment with NIX_SHOW_STATS=1 & NIX_SHOW_STATS_PATH=stats.json
  2. Observe the file is overwritten multiple times:
    
    $ inotifywait -m ./stats.json                          
    Setting up watches.
    Watches established.
    ./ OPEN 
    ./ ACCESS 
    ./ CLOSE_NOWRITE,CLOSE 
    ./ OPEN 
    ./ ACCESS 
    ./ CLOSE_NOWRITE,CLOSE 
    ./ MODIFY 
    ./ OPEN 
    ./ MODIFY 
    ./ CLOSE_WRITE,CLOSE 
    ./ OPEN 
    ./ ACCESS 
    ./ CLOSE_NOWRITE,CLOSE 
    ./ MODIFY 
    ./ OPEN 
    ./ MODIFY 
    ./ CLOSE_WRITE,CLOSE 
    ./ OPEN 
    ./ ACCESS 
    ./ CLOSE_NOWRITE,CLOSE

...



**Expected behavior**

`nix` should perhaps append a random discriminator to the file name to prevent collision similar to many profiling tools that randomize dump file names.

**`nix-env --version` output** `nix-env (Nix) 2.5.0pre20211206_d1aaa7e`
PAI5REECHO commented 2 years ago

Bad bot