Skip to content

Cachix leaves Nix DB broken inside Nix-Portable #475

@Kha

Description

@Kha

This is with Cachix 1.0.1 from Nixpkgs.

I'm experimenting with https://github.com/DavHau/nix-portable and trying to use cachix push from inside it. Even though the executable immediately exits because I forgot the auth token, it somehow modifies /nix/var/nix/db/db.sqlite, breaking any subsequent Nix invocations.

$ wget https://github.com/DavHau/nix-portable/releases/download/v009/nix-portable
$ chmod u+x nix-portable
$ ./nix-portable nix shell nixpkgs#cachix -c sh -c 'ls -l --full-time /nix/var/nix/db/db.sqlite; cachix push -j4 lean4 github:leanprover/lean4#Init; ls -l --full-time /nix/var/nix/db/db.sqlite'
Installing git. Disable this by specifying the git executable path with 'NP_GIT'
warning: cannot read flake registry '/home/sebastian/.config/nix/registry.json': error: opening file '/home/sebastian/.config/nix/registry.json': No such file or directory
-rw-r--r--    1 sebastia users      2498560 2022-12-17 16:46:38 +0000 /nix/var/nix/db/db.sqlite

Neither auth token nor signing key are present.

They are looked up via $CACHIX_AUTH_TOKEN and $CACHIX_SIGNING_KEY,
and if missing also looked up from ~/.config/cachix/cachix.dhall

Read https://mycache.cachix.org for instructions how to push to your binary cache.-rw-r--r--    1 sebastia users      2498560 2022-12-17 16:46:39 +0000 /nix/var/nix/db/db.sqlite
 $ ./nix-portable nix shell nixpkgs#cachix -c sh -c 'ls -l --full-time /nix/var/nix/db/db.sqlite; cachix push -j4 lean4 github:leanprover/lean4#Init; ls -l --full-time /nix/var/nix/db/db.sqlite'
error: executing SQLite statement 'pragma synchronous = normal': unable to open database file (in '/nix/var/nix/db/db.sqlite')

While this is a very fringe use case, it seems like this may point to a serious bug. From an strace log, it looks like the process exits while a thread is still modifying the DB?

...
[pid 2428400] pwrite64(41, "SQLite format 3\0\20\0\2\2\0@  \0\0\10\35\0\0\1\333"..., 4096, 0) = 4096
[pid 2428400] fdatasync(41)             = 0
[pid 2428400] close(42)                 = 0
[pid 2428400] unlink("/nix/var/nix/db/db.sqlite-journal") = 0
[pid 2428400] fcntl(41, F_SETLK, {l_type=F_RDLCK, l_whence=SEEK_SET, l_start=1073741826, l_len=510}) = 0
[pid 2428400] fcntl(41, F_SETLK, {l_type=F_UNLCK, l_whence=SEEK_SET, l_start=1073741824, l_len=2}) = 0
[pid 2428400] fcntl(41, F_SETLK, {l_type=F_UNLCK, l_whence=SEEK_SET, l_start=0, l_len=0}) = 0
[pid 2428400] mprotect(0x7fc278034000, 4096, PROT_READ|PROT_WRITE) = 0
[pid 2428400] mprotect(0x7fc278035000, 4096, PROT_READ|PROT_WRITE) = 0
[pid 2428400] mprotect(0x7fc278036000, 4096, PROT_READ|PROT_WRITE) = 0
[pid 2428400] mprotect(0x7fc278037000, 4096, PROT_READ|PROT_WRITE) = 0
[pid 2428400] mprotect(0x7fc278038000, 4096, PROT_READ|PROT_WRITE) = 0
[pid 2428400] mprotect(0x7fc278039000, 4096, PROT_READ|PROT_WRITE) = 0
[pid 2428400] mprotect(0x7fc27803a000, 4096, PROT_READ|PROT_WRITE) = 0
[pid 2428400] mprotect(0x7fc27803b000, 4096, PROT_READ|PROT_WRITE) = 0
[pid 2428400] mprotect(0x7fc27803c000, 4096, PROT_READ|PROT_WRITE) = 0
[pid 2428400] futex(0x7fc2a8000bfc, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY <unfinished ...>
[pid 2428384] <... read resumed>"\1\0\0\0\0\0\0\0", 8) = 8
[pid 2428384] close(5)                  = 0
[pid 2428384] rt_sigprocmask(SIG_BLOCK, ~[RT_1], NULL, 8) = 0
[pid 2428384] madvise(0x7fc2c4c65000, 8368128, MADV_DONTNEED) = 0
[pid 2428384] exit(0)                   = ?
[pid 2428384] +++ exited with 0 +++
[pid 2428383] <... futex resumed>)      = 0
[pid 2428383] munmap(0x7fc2c145e000, 8392704) = 0
[pid 2428383] rt_sigprocmask(SIG_BLOCK, [TTOU], [], 8) = 0
[pid 2428383] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 2428383] rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fc2c6d98bf0}, NULL, 8) = 0
[pid 2428383] rt_sigaction(SIGPIPE, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fc2c6d98bf0}, NULL, 8) = 0
[pid 2428383] rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fc2c6d98bf0}, NULL, 8) = 0
[pid 2428383] clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {tv_sec=0, tv_nsec=24453057}) = 0
[pid 2428383] exit_group(1)             = ?
[pid 2428400] <... futex resumed>)      = ?
[pid 2428400] +++ exited with 1 +++
+++ exited with 1 +++

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions