【问题标题】:Using nix-store --restore to install sources使用 nix-store --restore 安装源
【发布时间】:2020-06-09 07:41:17
【问题描述】:

我正在尝试在 nixOS 上安装神话电视。 mytv 使用 Qt,它使用来自 xiph.org 的震颤。 git.xiph.org 当前没有响应,因此安装失败。在相关的.drv 文件上使用nix show-derivation,我明白了

{
  "/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"
    }
  }
}

所以我在 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==

然后,我下载了存档:curl -O cache.nixos.org/nar/0jm68cws51814dm7gks62vj7a8zrdhwv2x364kq78wbkkqh58maa.nar.xz 并尝试恢复它:nix-store --restore /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a < <(xzdec 0jm68cws51814dm7gks62vj7a8zrdhwv2x364kq78wbkkqh58maa.nar.xz)

最初失败是因为目录存在:

$ 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

所以我删除它,然后再试一次:

$ 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

我发现“权限被拒绝”有点奇怪 - 我有正常的安装权限,实际上是删除(上)...

不过没关系,我可以用 sudo 来做到这一点:```$ sudo nix-store --restore /nix/store/aq8d6qgp55w0g9xdb81cys9b3l95d7hb-tremor-562307a $ 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.

【问题讨论】:

    标签: nix nixos


    【解决方案1】:

    也许你有一个负面的 narinfo 缓存条目,或者派生更喜欢本地构建。你可以试试

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

    【讨论】:

    • 谢谢,我试过了。唉,它根本不会改变行为。您提到了 narinfo 缓存条目和派生偏好:有没有办法我可以直接看到这些?我查看了 show-derivation 的输出,但都看不到。
    • 缓存作为sqlite数据库驻留在~/.cachix/nix/中,一个在您的家中,一个在root的家中,用于nix守护进程。两者都可以使用,它们被视为实现细节。
    • 明白是实现细节;谢谢。
    猜你喜欢
    • 2018-06-08
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 2020-03-28
    相关资源
    最近更新 更多