NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.53k stars 1.5k forks source link

nix-env writes everything to stderr instead of stdout #577

Closed knupfer closed 9 years ago

edolstra commented 9 years ago

Clearly not true:

$ nix-env -q | wc
     70      70    1064
knupfer commented 9 years ago

True for installing: $ nix-env -i hello | wc replacing old ‘hello-2.10’ installing ‘hello-2.10’ 0 0 0

edolstra commented 9 years ago

Yes, that's correct behaviour.

goodwillcoding commented 8 years ago

@edolstra @rbvermaa

Hi,

Why is something like this correct behaviour. I have the same issue with nix-collect-garbage, where only 1 line gets printed to stdout and the rest goes to stderr. This does not make much sense since there are no errors that happen during execution, the return of the run is 0

The reason I ask is because we run this part of automated processes and having to use tee and return code to cobble to together when there is an actual issue and when there is not one.

For example:

$ nix-collect-garbage --delete-old

stdout:

182 store paths deleted, 1.29 MiB freed

stderr

removing old generations of profile /nix/var/nix/profiles/per-user/user/profile
removing generation 16
removing generation 17
finding garbage collector roots...
deleting garbage...
deleting ‘/nix/store/qbssh84azvgsqah0j0gs5s54q22g0z54-mueval-env.drv’
deleting ‘/nix/store/gzn0cxixa67ffbs3z0l3492c1664j9rd-ghc-7.10.3.drv’
deleting ‘/nix/store/nh923lanvjbvj87v7nlm8v9w887wqj3v-lambdabot-trusted-5.0.2.1.drv’
deleting ‘/nix/store/clzhq069gkr34a6l9iz3md1r0p851ksv-oeis-0.3.6.drv’
...
deleting ‘/nix/store/zna3kkhrp7rjlri7x12sihr8r1gkf8y8-ansi-terminal-0.6.2.3.tar.gz.drv’
deleting ‘/nix/store/59aaxkfnmkqzzdsqj58rg38vlvlp1ya6-nix-prefetch-svn’
deleting ‘/nix/store/trash’
deleting unused links...
note: currently hard linking saves -0.00 MiB
goodwillcoding commented 8 years ago

Looking at the code I would say anything using lvlInfo should probably be going to stdout

vcunat commented 8 years ago

I believe that text showing progress is traditionally output into stderr.

goodwillcoding commented 8 years ago

@vcunat in that case why is that single message going to stdout? And if everything that is lvlInfo goes to stderr, what what should stdout be used for?

goodwillcoding commented 8 years ago

I mean I was taught that traditionally only errors go to stderr

vcunat commented 8 years ago

I don't know if the exact purpose is truly standardized somewhere in such a detail. If you look at git pull, for example, it does the same: stdout only gets Current branch foo is up to date. and the rest goes to sterr (what branches are being fetched, progress, etc.).

edolstra commented 8 years ago

The only stuff that goes to stdout is things with a more-or-less well defined format, i.e., things that can be processed easily by other programs/scripts. For instance, nix-store -r specifies that it prints the resulting store paths on stdout. So it's a bug that nix-collect-garbage prints anything on stdout.

vcunat commented 8 years ago

The current status seems reasonable to me. If anything might be useful to be processed by callers, that single line seems to contain the most useful information. (Perhaps not in very machine-friendly format, but still not too hard to parse.)