nix-pills icon indicating copy to clipboard operation
nix-pills copied to clipboard

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

Open willbush opened this issue 5 years ago • 11 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

willbush avatar Feb 08 '19 06:02 willbush

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

philipstears avatar Sep 29 '19 17:09 philipstears

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.

acarrico avatar Dec 05 '19 14:12 acarrico

... 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"

acarrico avatar Dec 05 '19 14:12 acarrico

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:

https://github.com/NixOS/nix/issues/2066

acarrico avatar Dec 05 '19 17:12 acarrico

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.

dschrempf avatar Jan 25 '21 12:01 dschrempf

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

https://github.com/NixOS/nix-pills/pull/174

nielsegberts avatar Jul 10 '21 14:07 nielsegberts

It becomes visible when running nix -L repl.

tfc avatar Dec 02 '21 21:12 tfc

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> 

paulmattei avatar Jan 03 '22 17:01 paulmattei

oh, it's 2.5.0pre...

tfc avatar Jan 03 '22 17:01 tfc

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

m0ar avatar Aug 23 '22 11:08 m0ar

+1 for $ nix repl -L

trofi avatar Aug 23 '22 18:08 trofi