TvixStoreIO: fix import_path for non-directories

#356
Opened by flokli at 2023-12-12T21·17+00

Currently, TvixStoreIO's import_path method imports the specified path always using recursive/nar mode.

However, for plain files (like ${./foo.txt}, in case foo.txt is indeed a file, Nix uses the "plain" hash mode:

$ cd tvix
$ nix repl
nix-repl> "${./README.md}"
"/nix/store/mb35ispv85q88xbda9lf0by75md9p9i4-README.md"
$ stat /nix/store/mb35ispv85q88xbda9lf0by75md9p9i4-README.md
  File: /nix/store/mb35ispv85q88xbda9lf0by75md9p9i4-README.md
  Size: 4403      	Blocks: 16         IO Block: 4096   regular file
Device: 0,31	Inode: 68153808    Links: 1
Access: (0444/-r--r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-12-12 23:09:25.000000000 +0200
Modify: 1970-01-01 03:00:01.000000000 +0300
Change: 2023-12-12 23:09:25.316159996 +0200
 Birth: 2023-12-12 23:09:25.315160000 +0200

The path calculation function that's used here should be build_text_path, using the basename as name, the file contents as content and an empty list of references.

Not sure about symlinks, it seems they're not followed when it comes to content ingestion (the original target is preserved):

$ ln -s README.md README2.md
$ nix repl
nix-repl> "${./README2.md}"                                         
"/nix/store/c8p30v4q2yrp8swdv9g7qkblp546qn9b-README2.md"

$ stat /nix/store/c8p30v4q2yrp8swdv9g7qkblp546qn9b-README2.md
  File: /nix/store/c8p30v4q2yrp8swdv9g7qkblp546qn9b-README2.md -> README.md
  Size: 9         	Blocks: 8          IO Block: 4096   symbolic link
Device: 0,31	Inode: 68154127    Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-12-12 23:15:07.000000000 +0200
Modify: 1970-01-01 03:00:01.000000000 +0300
Change: 2023-12-12 23:15:07.382768506 +0200
 Birth: 2023-12-12 23:15:07.382768506 +0200
$ ls -la /nix/store/c8p30v4q2yrp8swdv9g7qkblp546qn9b-README2.md
lrwxrwxrwx 1 root root 9 Jan  1  1970 /nix/store/c8p30v4q2yrp8swdv9g7qkblp546qn9b-README2.md -> README.md

  1. I was wrong, it seems these paths are also NAR-based.

    I added a test for it in cl/10355, but there's nothing to fix here in tvix.

    flokli at 2023-12-13T10·11+00

  2. flokli closed this issue at 2023-12-13T10·11+00