NixOS / nix-pills

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pill 7.2: declare -xp shows no ouput in nix repl

willbush opened this issue · comments

7.2. Using a script as a builder

The above pill references output made by declare -xp in the nix repl. However, I'm not getting any. The following shows my output:

> cat builder.sh
declare -xp
echo foo > $out
> nix repl
Welcome to Nix version 2.2. Type :? for help.

nix-repl> :l <nixpkgs>
Added 9889 variables.

nix-repl> "${bash}"
"/nix/store/vs6d2fjkl4kb3jb7rwibsd76k9v2n4xy-bash-4.4-p23"

nix-repl> d = derivation { name = "foo"; builder = "${bash}/bin/bash"; args = [ ./builder.sh ]; system = builtins.currentSystem; }

nix-repl> :b d

this derivation produced the following outputs:
  out -> /nix/store/1vx0mr2ahappwh04m4af3q18llhrr48x-foo

nix-repl>

version info:

>cat /etc/issue; uname -r

<<< Welcome to NixOS 19.03pre166987.bc41317e243 (\m) - \l >>>

Run `nixos-help` for the NixOS manual.

4.19.16
> nix --version
nix (Nix) 2.2

For what it's worth, nix-store -r <derivation path> does show the debugging output, so I ended up using that instead.

Thanks for the question. I found some notes about the logs in the nix manual. They are (normally) stored in /nix/var/log. You can you nix-store --read-log to see them.

nix-store --read-log /nix/store /nix/store/i76pr1cz0za3i9r6xq518bqqvd2raspw-foo.drv

or

nix-store --read-log /nix/store /nix/store/gczb4qrag22harvv693wwnflqy7lx5pb-foo

I agree that nix-store --read-log should be mentioned in this pill, and it would be nice if there were repl commands for showing derivations and logs.

... and here is a way to do it without typing the hash explicitly:

$ nix build --file ./pill7.nix
$ nix-store --read-log result

declare -x HOME="/homeless-shelter"
declare -x NIX_BUILD_CORES="4"
declare -x NIX_BUILD_TOP="/build"
declare -x NIX_LOG_FD="2"
declare -x NIX_STORE="/nix/store"
declare -x OLDPWD
declare -x PATH="/path-not-set"
declare -x PWD="/build"
declare -x SHLVL="1"
declare -x TEMP="/build"
declare -x TEMPDIR="/build"
declare -x TMP="/build"
declare -x TMPDIR="/build"
declare -x builder="/nix/store/l6h4ya0wzb4b8mr0y58k2gh2nhfql4sn-bash-4.4-p23/bin/bash"
declare -x coreutils="/nix/store/kx56d14p0qm2awn0qrqrv4rb8xdhvhpi-coreutils-8.31"
declare -x name="foo"
declare -x out="/nix/store/zc0g804ydw8z4y8wj0vqjb86525ah1j8-foo"
declare -x system="x86_64-linux"

Digging deeper nix log also exists.

Assuming default.nix is in the current directory, then:

nix build
nix log ./result

will show the log (but nix log result will not).

Unfortunately, it doesn't seem like nix build has any option to show the log as it builds. Or does someone know a way? It seems like showing the log as it builds would be a useful developer option for the nix command and the repl.

Here is an issue that talks about the behavior of nix log:

NixOS/nix#2066

I also bumped into this issue. It should be stated that the debug output is not printed (or a way to get the debug output) in the main text of the nix pill.

I've created a pull request to add that nix-store --read-log can be used to see the builder logs.

#174

It becomes visible when running nix -L repl.

It becomes visible when running nix -L repl.

Which version of Nix are you running?

$ nix -L repl
Welcome to Nix version 2.3.16. Type :? for help.

$ nix -L repl
Welcome to Nix version 2.3.16. Type :? for help.

nix-repl> :l <nixpkgs>                                                                                 Added 15438 variables.      

nix-repl> d = derivation { name = "foo"; builder = "${bash}/bin/bash"; args = [ ./builder.sh ]; system = builtins.currentSystem; }

nix-repl> :b d                                                                                         
this derivation produced the following outputs:
  out -> /nix/store/i6xkvhaj58nr0s0038x32h42g7nx1fjk-foo

nix-repl> 

oh, it's 2.5.0pre...

Meanwhile, one can execute :log d after the build to see the log output :)

+1 for $ nix repl -L