0

我对 Nix 很陌生,我正在尝试创建一个非常简单的shell.nix脚本文件。

不幸的是,我需要一个旧包:mariadb-10.4.21. 在阅读和搜索了一下之后,我发现那个版本10.4.17(如果有确切的版本会很好,但我找不到它)在频道中nixos-20.09,但是当我这样做时

$ nix-shell --version
nix-shell (Nix) 2.5.1
$ cat shell.nix
let
  pkgs = import <nixpkgs> {};

  # git ls-remote https://github.com/nixos/nixpkgs nixos-20.09
  pkgs-20_09 = import (builtins.fetchGit {    
    name = "nixpks-20.09";    
    url = "https://github.com/nixos/nixpkgs";    
    ref = "refs/heads/nixos-20.09";    
    rev = "1c1f5649bb9c1b0d98637c8c365228f57126f361";    
  }) {};        
in    
  pkgs.stdenv.mkDerivation {    
    pname = "test";    
    version = "0.1.0";    
      
    buildInputs = [    
      pkgs-20_09.mariadb    
    ];    
  } 

$ nix-shell

它只是无限期地等待而不做任何事情。但如果我这样做

$ nix-shell -p mariadb -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/1c1f5649bb9c1b0d98637c8c365228f57126f361.tar.gz
[...]
/nix/store/yias2v8pm9pvfk79m65wdpcby4kiy91l-mariadb-server-10.4.17
[...]
copying path '/nix/store/yias2v8pm9pvfk79m65wdpcby4kiy91l-mariadb-server-10.4.17' from 'https://cache.nixos.org'...
[nix-shell:~/Playground]$ mariadb --version
mariadb  Ver 15.1 Distrib 10.4.17-MariaDB, for Linux (x86_64) using readline 5.1

它完美地工作。

我在脚本中做错了什么让它停止?

编辑:我通过运行获得了更多信息

$ nix-shell -vvv
[...]
did not find cache entry for '{"name":"nixpks-20.09","rev":"1c1f5649bb9c1b0d98637c8c365228f57126f361","type":"git"}'
did not find cache entry for '{"name":"nixpks-20.09","ref":"refs/heads/nixos-20.09","type":"git","url":"https://github.com/nixos/nixpkgs"}'
locking path '/home/test/.cache/nix/gitv3/17blyky0ja542rww32nj04jys1r9vnkg6gcfbj83drca9a862hwp.lock'
lock acquired on '/home/test/.cache/nix/gitv3/17blyky0ja542rww32nj04jys1r9vnkg6gcfbj83drca9a862hwp.lock.lock'
fetching Git repository 'https://github.com/nixos/nixpkgs'...

是我还是它似乎试图从两个不同的来源获取?据我了解所有三个url,rev并且ref是 git-fetching 所必需的,但看起来它是否正在拆分它们。

EDIT2:我一直在尝试fetchFromGitHub

pkgs-20_09 = import (pkgs.fetchFromGitHub {      
  name = "nixpks-20.09";      
  owner = "nixos";      
  repo = "nixpkgs";      
  rev = "1c1f5649bb9c1b0d98637c8c365228f57126f361";      
  sha256 = "0f2nvdijyxfgl5kwyb4465pppd5vkhqxddx6v40k2s0z9jfhj0xl";      
}) {};      

fetchTarball

pkgs-20_09 = import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/1c1f5649bb9c1b0d98637c8c365228f57126f361.tar.gz") {};

两者都工作得很好。我fetchFromGitHub将从现在开始使用,但现在为什么fetchGit不起作用会很有趣。

4

0 回答 0