user3416536
user3416536

Reputation: 1469

Using nix-store --restore to install sources

I'm trying to install mythtv on nixOS. mythtv uses Qt which uses tremor from xiph.org . git.xiph.org is currently unresponsive, so the install fails. Using nix show-derivation on the relevant .drv file, I see

{
  "/nix/store/srhlr1v02a1gkp1ld1hrjzda0kfjcjkf-tremor-562307a.drv": {
    "outputs": {
      "out": {
        "path": "/nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a",
        "hashAlgo": "r:sha256",
        "hash": "f80ffaf1dc452061c4a2e7566ccec5f8ec1496ef2894857ed42f3ef7097e0754"
      }
    },
    "inputSrcs": [
      "/nix/store/jr7l8xyyanakpqr954rvj58lyqal1vfb-builder.sh",
      "/nix/store/m9n5a7g5nb7jglcs9i58ycrkmn998wrp-nix-prefetch-git"
    ],
    ...
    "env": {
      ...
      "url": "https://git.xiph.org/tremor.git"
    }
  }
}

So I looked for, and succesfully found, this in cache.nixos.org:

$ curl cache.nixos.org/aq8d6qgp55w0g9xdb81cys9b3l95d7hb.narinfo
StorePath: /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a
URL: nar/0jm68cws51814dm7gks62vj7a8zrdhwv2x364kq78wbkkqh58maa.nar.xz
Compression: xz
FileHash: sha256:0jm68cws51814dm7gks62vj7a8zrdhwv2x364kq78wbkkqh58maa
FileSize: 109380
NarHash: sha256:0m07gq4zfgigsiz8b518xyb19v7qqp76qmp7lb262825vkqzl3zq
NarSize: 588216
References: 
Deriver: cr4d6v24rchmkv26mvzlzrr23z7a5ghb-tremor-562307a.drv
Sig: cache.nixos.org-1:rb9+9oe3LMRlh8TbLuZ7nhMaPIc5fwrAhG4tXtBLAgd7EGBoS2jk6BgYzSRI49MgwdPgAKTtzM3W0Wj0jGojDQ==

Then, I downloaded the narchive: curl -O cache.nixos.org/nar/0jm68cws51814dm7gks62vj7a8zrdhwv2x364kq78wbkkqh58maa.nar.xz and attempted to restore it: nix-store --restore /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a < <(xzdec 0jm68cws51814dm7gks62vj7a8zrdhwv2x364kq78wbkkqh58maa.nar.xz).

This fails initially because the directory exists:

$ nix-store --restore /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a < <(xzdec 0jm68cws51814dm7gks62vj7a8zrdhwv2x364kq78wbkkqh58maa.nar.xz)
error: creating directory '/nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a': File exists
$ ls -ld /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a
drwxr-xr-x 3 nixbld10 nixbld 18 Jun  8 20:57 /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a
$ ls -l /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a
total 0

So I delete it, and try again:

$ nix-store --delete /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a
finding garbage collector roots...
removing stale link from '/nix/var/nix/gcroots/auto/f9ldmvya8mix2j52cwsl8h0rqvjycjjy' to '/tmp/martyn/nixos-rebuild.didhrl/nix.drv'
removing stale link from '/nix/var/nix/gcroots/auto/qs606yn37b7irq7jmkvj0ld9wjv36fma' to '/tmp/martyn/nixos-rebuild.didhrl/nix'
deleting '/nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a'
deleting '/nix/store/trash'
deleting unused links...
note: currently hard linking saves 0.00 MiB
1 store paths deleted, 0.07 MiB freed
$ nix-store --restore /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a < <(xzdec 0jm68cws51814dm7gks62vj7a8zrdhwv2x364kq78wbkkqh58maa.nar.xz)
error: creating directory '/nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a': Permission denied

I find that "permission denied" to be a bit odd - I have normal rights to install, indeed to delete (above)...

But it's okay, I can do this with sudo: ```$ sudo nix-store --restore /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a < <(xzdec 0jm68cws51814dm7gks62vj7a8zrdhwv2x364kq78wbkkqh58maa.nar.xz)


    $ ls -ld /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a
    drwxr-xr-x 5 root root 4096 Jun  9 07:27 /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a
    $ ls -l !$ | head
    $ ls -l /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a | head
    total 496
    -rw-r--r-- 1 root root   6534 Jun  9 07:27 asm_arm.h
    -rwxr-xr-x 1 root root   3657 Jun  9 07:27 autogen.sh
    -rw-r--r-- 1 root root   4639 Jun  9 07:27 backends.h
    -rw-r--r-- 1 root root  14547 Jun  9 07:27 block.c
    -rw-r--r-- 1 root root   1109 Jun  9 07:27 block.h
    -rw-r--r-- 1 root root    467 Jun  9 07:27 CHANGELOG
    -rw-r--r-- 1 root root  10765 Jun  9 07:27 codebook.c
    -rw-r--r-- 1 root root   4078 Jun  9 07:27 codebook.h
    -rw-r--r-- 1 root root   3084 Jun  9 07:27 codec_internal.h

Better still, the hash looks good:

    $ nix-hash /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a --type sha256
    f80ffaf1dc452061c4a2e7566ccec5f8ec1496ef2894857ed42f3ef7097e0754

I notice that a lock file remains, so I delete that:

Along the way, I noticed that after the restore, the lock file remains:

    $ ls -l /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a.lock 
    -rw------- 1 root root 0 May 27 08:15 /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a.lock
    $ nix-store --delete !$
    $ nix-store --delete /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a.lock
    finding garbage collector roots...
    deleting '/nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a.lock'
    deleting '/nix/store/trash'
    deleting unused links...
    note: currently hard linking saves 0.00 MiB
    1 store paths deleted, 0.00 MiB freed

So I should be all set?  It seems not:

    $ nix-env -i /nix/store/srhlr1v02a1gkp1ld1hrjzda0kfjcjkf-tremor-562307a.drv
    installing 'tremor-562307a.drv'
    these derivations will be built:
      /nix/store/srhlr1v02a1gkp1ld1hrjzda0kfjcjkf-tremor-562307a.drv
    building '/nix/store/srhlr1v02a1gkp1ld1hrjzda0kfjcjkf-tremor-562307a.drv'...
    exporting https://git.xiph.org/tremor.git (rev 562307a4a7082e24553f3d2c55dab397a17c4b4f) into /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a
    Initialized empty Git repository in /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a/.git/

I am baffled why nix is rebuilding a store path that is extant and has the requested hash.

I tried repairing the path, to see if maybe the database needed updating in some way:

$ nix-store --repair-path /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a
error: you don't have sufficient rights to use this command
$ sudo nix-store --repair-path /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a
error: path '/nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a' is not valid
$ nix-hash /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a --type sha256
f80ffaf1dc452061c4a2e7566ccec5f8ec1496ef2894857ed42f3ef7097e0754

So that 'path ... is not valid' is alarming, but still, it's present with a good hash, so I don't understand why it's supposedly not valid, nor why nix insists on rebuilding it.

Upvotes: 1

Views: 966

Answers (1)

Robert Hensing
Robert Hensing

Reputation: 7389

Maybe you have a negative narinfo cache entry or maybe the derivation prefers a local build. You could try

nix-store --delete /nix/store/srhlr1v02a1gkp1ld1hrjzda0kfjcjkf-tremor-562307a.drv
nix-store --realise --option narinfo-cache-negative-ttl 0 -vvvvv  /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a

Upvotes: 1

Related Questions