2013-09-09 16:09:46 +00:00
|
|
|
|
nix-repl
|
|
|
|
|
========
|
|
|
|
|
|
|
|
|
|
`nix-repl` is a simple read–eval–print loop (REPL) for the Nix package
|
|
|
|
|
manager.
|
|
|
|
|
|
|
|
|
|
Installation
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
Assuming you have Nix installed, just do
|
|
|
|
|
|
2013-09-09 16:11:47 +00:00
|
|
|
|
$ git clone https://github.com/edolstra/nix-repl.git
|
|
|
|
|
$ cd nix-repl
|
|
|
|
|
$ nix-env -f . -i nix-repl
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
|
|
|
|
Example
|
|
|
|
|
-------
|
|
|
|
|
|
|
|
|
|
Here is a typical `nix-repl` session:
|
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
$ nix-repl
|
|
|
|
|
Welcome to Nix version 1.6pre3215_2c1ecf8. Type :? for help.
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> 3 * 4
|
|
|
|
|
12
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> :l <nixpkgs>
|
|
|
|
|
Added 3337 variables.
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> lib.range 1 5
|
|
|
|
|
[ 1 2 3 4 5 ]
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> :a lib
|
|
|
|
|
Added 299 variables.
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> range 1 5
|
|
|
|
|
[ 1 2 3 4 5 ]
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> xs = range 1 5
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> map (x: x * x) xs
|
|
|
|
|
[ 1 4 9 16 25 ]
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> :l <nixos>
|
|
|
|
|
Added 7 variables.
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> config.services.dhcpd
|
|
|
|
|
{ configFile = null; enable = false; extraConfig = ""; interfaces = [ ... ]; machines = [ ... ]; }
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> :p config.services.dhcpd
|
|
|
|
|
{ configFile = null; enable = false; extraConfig = ""; interfaces = [ "eth0" ]; machines = [ ]; }
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> config.fileSystems
|
|
|
|
|
{ "/" = { ... }; "/boot" = { ... }; }
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> mapAttrsToList (n: v: v.device) config.fileSystems
|
|
|
|
|
[ "/dev/disk/by-label/nixos" "/dev/disk/by-label/boot" ]
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> :b libjson
|
|
|
|
|
these derivations will be built:
|
|
|
|
|
/nix/store/h910xqb36pysxcxkayb1zkr1zcvvk1zy-libjson_7.6.1.zip.drv
|
|
|
|
|
/nix/store/iv0rdx08di0fg704zyxklkvdz6i96lm8-libjson-7.6.1.drv
|
|
|
|
|
...
|
|
|
|
|
this derivation produced the following outputs:
|
|
|
|
|
out -> /nix/store/ys6bvgfia81rjwqxjlgkwnx6jhsml8h9-libjson-7.6.1
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> :t makeFontsConf
|
|
|
|
|
a function
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> :b makeFontsConf { fontDirectories = [ "${freefont_ttf}/share/fonts/truetype" ]; }
|
|
|
|
|
...
|
|
|
|
|
this derivation produced the following outputs:
|
|
|
|
|
out -> /nix/store/jkw848xj0gkbhmvxi0hwpnhzn2716v3c-fonts.conf
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> :s pan
|
|
|
|
|
# Builds dependencies of the ‘pan’ derivation, then starts a shell
|
|
|
|
|
# in which the environment variables of the derivation are set
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
[nix-shell:/tmp/nix-repl]$ echo $src
|
|
|
|
|
/nix/store/0ibx15r02nnkwiclmfbpzrzjm2y204fh-pan-0.139.tar.bz2
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
[nix-shell:/tmp/nix-repl]$ exit
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl>
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
|
|
|
|
Tab completion works on variables in scope and on attribute sets. For
|
|
|
|
|
example:
|
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
$ nix-repl '<nixpkgs>' '<nixos>'
|
|
|
|
|
Welcome to Nix version 1.6pre3215_2c1ecf8. Type :? for help.
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> thunder<TAB> => thunderbird
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> <TAB>
|
|
|
|
|
Display all 3634 possibilities? (y or n)
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> lib<TAB>
|
|
|
|
|
Display all 291 possibilities? (y or n)
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> xorg.libX<TAB>
|
|
|
|
|
xorg.libXdamage xorg.libXdmcp
|
2013-09-09 16:09:46 +00:00
|
|
|
|
|
2013-09-09 16:10:57 +00:00
|
|
|
|
nix-repl> config.networking.use<TAB>
|
|
|
|
|
config.networking.useDHCP config.networking.usePredictableInterfaceNames
|