基于我的读数(特别是维基和这篇博客文章),我想出了下面default.nix,我和加载nix-shell:
with import <nixpkgs> {};
let emacs =
emacsWithPackages (p : [ p.tuareg ]);
in
stdenv.mkDerivation rec {
name = "env";
src = ./.;
# Customizable development requirements
buildInputs = [
pkgconfig
ocaml
ocamlPackages.merlin
ocamlPackages.findlib
ocamlPackages.lablgtk
ocamlPackages.camlp5_transitional
ncurses
emacs
];
# Customizable development shell setup
shellHook = ''
export PATH=`pwd`/bin:$PATH
'';
}
Run Code Online (Sandbox Code Playgroud)
但它总是打印一个警告:
warning: dumping very large path (> 256 MiB); this may run out of memory
Run Code Online (Sandbox Code Playgroud)
并且需要很长时间才能加载(nix-shell启动后第一次呼叫约45 秒,后续呼叫约2秒).
这条消息是什么意思?当我在Google上查找它时,我发现了一些GitHub问题,但没有以一种易于理解的方式表达. …
我在NixOS 16.09上,我想使用目前仅在nixpkgs-unstable/nixos-unstable中的软件包.
使用nix-channel --add,我能够将nixpkgs-unstable添加到我的(用户)频道,并使用它来安装最新版本的某些软件包nix-env.
但是,据我所知,虽然nix-env依赖于用户定义的通道,但nix-shell取决于NIX_PATH环境变量,在我的情况下:
$ echo $NIX_PATH
nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels
Run Code Online (Sandbox Code Playgroud)
所以这清楚地表明了问题:nix-shell将使用系统范围的NixOS 16.09通道而不是用户定义的nixpkgs-unstable通道.
现在,我正在使用此解决方法:
nix-shell -I nixpkgs=~/.nix-defexpr/channels/nixpkgs
Run Code Online (Sandbox Code Playgroud)
它看起来不是很漂亮.这样做的推荐方法是什么?
它是否添加如下内容:
export NIX_PATH="nixpkgs=~/.nix-defexpr/channels/nixpkgs:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels"
Run Code Online (Sandbox Code Playgroud)
对我.profile?它看起来也不是很漂亮.
要调用使用一套解构一个尼克斯的功能,你需要用它传递了一套正是它需要,没有更多的按键也不能少:
nix-repl> ({ a }: a) { a = 4; b = 5; }
error: anonymous function at (string):1:2 called with unexpected argument ‘b’, at (string):1:1
Run Code Online (Sandbox Code Playgroud)
例外情况是函数的参数列表末尾包含省略号:
nix-repl> ({ a, ... }: a) { a = 4; b = 5; }
4
Run Code Online (Sandbox Code Playgroud)
但是,nixpkgs中的大多数包都包含一个default.nix包含未使用此省略号定义的函数的文件.然而,不管怎样,当你使用时callPackage,它设法调用这些函数并仅传递它们所需的参数.这是如何实现的?
我试图理解nix是如何工作的.为此,我尝试创建一个简单的环境来运行jupyter笔记本.
当我运行命令时:
nix-shell -p "\
with import <nixpkgs> {};\
python35.withPackages (ps: [\
ps.numpy\
ps.toolz\
ps.jupyter\
])\
"
Run Code Online (Sandbox Code Playgroud)
我得到了我的期望 - 在python和安装的所有软件包的环境中的shell,以及路径中可访问的所有预期命令:
[nix-shell:~/dev/hurricanes]$ which python
/nix/store/5scsbf8z3jnz8ardch86mhr8xcyc8jr2-python3-3.5.3-env/bin/python
[nix-shell:~/dev/hurricanes]$ which jupyter
/nix/store/5scsbf8z3jnz8ardch86mhr8xcyc8jr2-python3-3.5.3-env/bin/jupyter
[nix-shell:~/dev/hurricanes]$ jupyter notebook
[I 22:12:26.191 NotebookApp] Serving notebooks from local directory: /home/calsaverini/dev/hurricanes
[I 22:12:26.191 NotebookApp] 0 active kernels
[I 22:12:26.191 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=7424791f6788af34f4c2616490b84f0d18353a4d4e60b2b5
Run Code Online (Sandbox Code Playgroud)
因此,我创建了一个default.nix包含以下内容的单个文件的新文件夹:
with import <nixpkgs> {};
python35.withPackages (ps: [
ps.numpy
ps.toolz
ps.jupyter
])
Run Code Online (Sandbox Code Playgroud)
当我nix-shell在这个文件夹中运行时,似乎所有东西PATH都已安装但s未设置:
[nix-shell:~/dev/hurricanes]$ which python
/usr/bin/python
[nix-shell:~/dev/hurricanes]$ …Run Code Online (Sandbox Code Playgroud) 我已经成功安装了ghc nix-env -i ghc.
我现在想安装一个Haskell库,应该怎么做?例如turtle(https://hackage.haskell.org/package/turtle)库.
我已经运行nix-env -f "<nixpkgs>" -iA haskellPackages.turtle,但运行ghci和import Turtle失败:
Prelude> import Turtle
<no location info>: error:
Could not find module ‘Turtle’
It is not a module in the current program, or in any known package.
Run Code Online (Sandbox Code Playgroud)
产量ghc-pkg list:
/nix/store/fvf278s3lqsjv488ahhdi8jx6i0qzsr9-ghc-8.0.2/lib/ghc-8.0.2/package.conf.d
Cabal-1.24.2.0
array-0.5.1.1
base-4.9.1.0
binary-0.8.3.0
bytestring-0.10.8.1
containers-0.5.7.1
deepseq-1.4.2.0
directory-1.3.0.0
filepath-1.4.1.1
ghc-8.0.2
ghc-boot-8.0.2
ghc-boot-th-8.0.2
ghc-prim-0.5.0.0
ghci-8.0.2
haskeline-0.7.3.0
hoopl-3.10.2.1
hpc-0.6.0.3
integer-gmp-1.0.0.1
pretty-1.1.3.3
process-1.4.3.0
rts-1.0
template-haskell-2.11.1.0
terminfo-0.4.0.2
time-1.6.0.1
transformers-0.5.2.0
unix-2.7.2.1
xhtml-3000.2.1
Run Code Online (Sandbox Code Playgroud) 我最初是这样尝试的:
nix-shell -p "haskell.packages.ghc821.ghcWithPackages (p: with p; [text hspec lens])" -j4 --run 'ghc Main.hs -prof
Run Code Online (Sandbox Code Playgroud)
然后GHC告诉我
Main.hs:4:1: error:
Could not find module ‘Control.Lens’
Perhaps you haven't installed the profiling libraries for package ‘lens-4.15.4’?
Use -v to see a list of the files searched for.
Run Code Online (Sandbox Code Playgroud)
在网上搜索我发现了这个:https://github.com/NixOS/nixpkgs/issues/22340
所以我似乎无法从缓存中下载.但是没关系,如果至少我可以在本地构建配置文件变体.
我可以通过简单地修改给定的nix表达式以某种方式做到这-p一点吗?
然后在写这个问题的这一点上,我记得这个资源:https://github.com/NixOS/nixpkgs/blob/bd6ba7/pkgs/development/haskell-modules/lib.nix
我找到的地方enableLibraryProfiling.所以我尝试过:
nix-shell -p "haskell.packages.ghc821.ghcWithPackages (p: with p; [text hspec (haskell.lib.enableLibraryProfiling lens)])" -j4 --run 'ghc Main.hs -prof'
Run Code Online (Sandbox Code Playgroud)
这让我遇到了一个新错误:
src/Control/Lens/Internal/Getter.hs:26:1: error:
Could not find …Run Code Online (Sandbox Code Playgroud) 几周前我在我的机器上安装了nix软件包管理器(macOS 10.12.6 Sierra).
我想更新mylocal nixpkgs集合,使其与频道中的任何上游更新同步.我的理解是,这可以通过运行:nix-channel --update.但是当我运行它时,我得到以下输出:
unpacking channels...
created 0 symlinks in user environment
建议我的系统订阅的频道中没有更新任何表达式.如果我跑,nix-channel --list我没有看到列出的任何频道.默认情况下我的系统订阅了哪个频道?我应该期望它被列出吗?
nix-channel --update如果我修改了我订阅的频道或者我订阅了不稳定的频道,通常只会产生局部变化吗?
我正在尝试在NixOS上进行cython调试.我可以在nix-shell中轻松安装cython(为简单起见而选择),如下所示:
$ nix-shell -p 'python27.withPackages( p: [ p.cython ])'
$ cat /nix/store/s0w3phb2saixi0a9bzk8pjbczjaz8d7r-python-2.7.14-env/bin/python
#! /nix/store/jgw8hxx7wzkyhb2dr9hwsd9h2caaasdc-bash-4.4-p12/bin/bash -e
export PYTHONHOME="/nix/store/s0w3phb2saixi0a9bzk8pjbczjaz8d7r-python-2.7.14-env"
export PYTHONNOUSERSITE="true"
exec "/nix/store/i3bx1iw2d0i3vh9sa1nf92ynlrw324w8-python-2.7.14/bin/python" "${extraFlagsArray[@]}" "$@"
Run Code Online (Sandbox Code Playgroud)
然后我们做一个普通的nix-shell只是python,看看我们得到了什么版本的python.
[henry@bollum:~/Projects/eyeserver/nixshell]$ nix-shell -p 'python27'
$ which python
/nix/store/i3bx1iw2d0i3vh9sa1nf92ynlrw324w8-python-2.7.14/bin/python
# ^^^^^^^
# non-debug
Run Code Online (Sandbox Code Playgroud)
一切都很好 - 我们在两种情况下都获得了非调试python.如果我们gdb它,我们得到(没有找到调试符号).见最后一行.
$ gdb
/nix/store/i3bx1iw2d0i3vh9sa1nf92ynlrw324w8-python-2.7.14/bin/python
GNU gdb (GDB) 8.0.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the …Run Code Online (Sandbox Code Playgroud) 我无法理解Nix Pill 14。作者提供了makeOverridable,然后挑战用户将其集成callPackage。makeOverridable和default.nix提供如下,其中makeOverridable位于 文件 中lib.nix,callPackage位于 文件 中default.nix:
# file: lib.nix
rec {
makeOverridable = f: origArgs:
let
origRes = f origArgs;
in
origRes // { override = newArgs: makeOverridable f (origArgs // newArgs); };
}
Run Code Online (Sandbox Code Playgroud)
# file: default.nix
let
nixpkgs = import <nixpkgs> {};
allPkgs = nixpkgs // pkgs;
callPackage = path: overrides:
let f = import path;
in f ((builtins.intersectAttrs (builtins.functionArgs …Run Code Online (Sandbox Code Playgroud)