nix --version 2>/dev/null prints out extra context that is not printed when running nix --version #620

Closed
opened 2025-01-08 21:11:37 +00:00 by jade · 5 comments
Owner

So, running nix --version outputs abbreviated version information. I thought this was on purpose, and it is weird that nix-store --version or so will output extra useful diagnostic information, and I meant to file a bug to make nix --version do it too since it's nice.

However, I had the following interaction with lix today, and it is surely a bug:

 » nix --version
nix (Lix, like Nix) 2.92.0-dev-pre20250108-37e8904

 » nix --version 2>/dev/null
nix (Lix, like Nix) 2.92.0-dev-pre20250108-37e8904
System type: aarch64-darwin
Additional system types: x86_64-darwin
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /Users/jade/.config/nix/nix.conf:/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/la7xwrdi7h429qsaw7inbbpgscvyazfc-lix-2.92.0-dev-pre20250108-37e8904/share

 » nix-store --version
nix-store (Lix, like Nix) 2.92.0-dev-pre20250108-37e8904
System type: aarch64-darwin
Additional system types: x86_64-darwin
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /Users/jade/.config/nix/nix.conf:/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/la7xwrdi7h429qsaw7inbbpgscvyazfc-lix-2.92.0-dev-pre20250108-37e8904/share

That is, whether the extra information is printed depends on interactivity status or something because piping stderr to /dev/null causes the additional data to appear. What?!

This should be fixed to always show it. See also: #230

So, running `nix --version` outputs abbreviated version information. I thought this was on purpose, and it *is* weird that `nix-store --version` or so will output extra useful diagnostic information, and I meant to file a bug to make `nix --version` do it too since it's nice. However, I had the following interaction with lix today, and it is surely a bug: ``` » nix --version nix (Lix, like Nix) 2.92.0-dev-pre20250108-37e8904 » nix --version 2>/dev/null nix (Lix, like Nix) 2.92.0-dev-pre20250108-37e8904 System type: aarch64-darwin Additional system types: x86_64-darwin Features: gc, signed-caches System configuration file: /etc/nix/nix.conf User configuration files: /Users/jade/.config/nix/nix.conf:/etc/xdg/nix/nix.conf Store directory: /nix/store State directory: /nix/var/nix Data directory: /nix/store/la7xwrdi7h429qsaw7inbbpgscvyazfc-lix-2.92.0-dev-pre20250108-37e8904/share » nix-store --version nix-store (Lix, like Nix) 2.92.0-dev-pre20250108-37e8904 System type: aarch64-darwin Additional system types: x86_64-darwin Features: gc, signed-caches System configuration file: /etc/nix/nix.conf User configuration files: /Users/jade/.config/nix/nix.conf:/etc/xdg/nix/nix.conf Store directory: /nix/store State directory: /nix/var/nix Data directory: /nix/store/la7xwrdi7h429qsaw7inbbpgscvyazfc-lix-2.92.0-dev-pre20250108-37e8904/share ``` That is, *whether the extra information is printed depends on interactivity status or something* because piping stderr to /dev/null causes the additional data to appear. **What?!** This should be fixed to always show it. See also: https://git.lix.systems/lix-project/lix/issues/230
Member

Allô ! 👋

I made --version spit some debug infos.

When you don't pipe stderr to /dev/null you get the following:

❯ result/bin/nix --version
nix (Lix, like Nix) 2.92.0-devpre20250116_dirty
verbosity: 2
lvlInfo (default log level): 3

And when you pipe stderr to /dev/null, you get the following:

❯ result/bin/nix --version 2>/dev/null
nix (Lix, like Nix) 2.92.0-devpre20250116_dirty
verbosity: 3
lvlInfo (default log level): 3
System type: x86_64-linux
Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux, x86_64-v4-linux
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /home/goldman/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/goldman/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/goldman/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/goldman/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/8ylzk73xhlwivnmvdakpbaa10vkzqfwk-lix-2.92.0-devpre20250116_dirty/share

In lix/libutil/logging.cc:121, the default verbosity level seems to be defined as lvlInfo, and in the printVersion function there's the following check:

    if (verbosity > lvlNotice) {
        Strings cfg;
#if HAVE_BOEHMGC
        cfg.push_back("gc");
#endif
        cfg.push_back("signed-caches");
        std::cout << "System type: " << settings.thisSystem << "\n";
        std::cout << "Additional system types: " << concatStringsSep(", ", settings.extraPlatforms.get()) << "\n";
        std::cout << "Features: " << concatStringsSep(", ", cfg) << "\n";
        std::cout << "System configuration file: " << settings.nixConfDir + "/nix.conf" << "\n";
        std::cout << "User configuration files: " <<
            concatStringsSep(":", settings.nixUserConfFiles)
            << "\n";
        std::cout << "Store directory: " << settings.nixStore << "\n";
        std::cout << "State directory: " << settings.nixStateDir << "\n";
        std::cout << "Data directory: " << settings.nixDataDir << "\n";
    }

My first idea would be to simply remove the log level check in printVersion, because I don't think it's bad to have this information even if the log level is set to lvlError.

For the root cause, it seems to be due to the following lines in lix/nix/main.cc:

    // FIXME: stop messing about with log verbosity depending on if it is interactive use
    if (isatty(STDERR_FILENO)) {
        verbosity = lvlNotice;
    } else {
        verbosity = lvlInfo;
    }

But if I comment those lines, it breaks functional/flakes/show.sh:113 test related to nix flake show, and I'm not experience / skilled enough with flake and lix development / tests to quickly fix this.

Allô ! 👋 I made `--version` spit some debug infos. When you don't pipe `stderr` to `/dev/null` you get the following: ``` ❯ result/bin/nix --version nix (Lix, like Nix) 2.92.0-devpre20250116_dirty verbosity: 2 lvlInfo (default log level): 3 ``` And when you pipe `stderr` to `/dev/null`, you get the following: ``` ❯ result/bin/nix --version 2>/dev/null nix (Lix, like Nix) 2.92.0-devpre20250116_dirty verbosity: 3 lvlInfo (default log level): 3 System type: x86_64-linux Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux, x86_64-v4-linux Features: gc, signed-caches System configuration file: /etc/nix/nix.conf User configuration files: /home/goldman/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/goldman/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/goldman/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/goldman/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf Store directory: /nix/store State directory: /nix/var/nix Data directory: /nix/store/8ylzk73xhlwivnmvdakpbaa10vkzqfwk-lix-2.92.0-devpre20250116_dirty/share ``` In `lix/libutil/logging.cc:121`, the default verbosity level seems to be defined as `lvlInfo`, and in the `printVersion` function there's the following check: ```cpp if (verbosity > lvlNotice) { Strings cfg; #if HAVE_BOEHMGC cfg.push_back("gc"); #endif cfg.push_back("signed-caches"); std::cout << "System type: " << settings.thisSystem << "\n"; std::cout << "Additional system types: " << concatStringsSep(", ", settings.extraPlatforms.get()) << "\n"; std::cout << "Features: " << concatStringsSep(", ", cfg) << "\n"; std::cout << "System configuration file: " << settings.nixConfDir + "/nix.conf" << "\n"; std::cout << "User configuration files: " << concatStringsSep(":", settings.nixUserConfFiles) << "\n"; std::cout << "Store directory: " << settings.nixStore << "\n"; std::cout << "State directory: " << settings.nixStateDir << "\n"; std::cout << "Data directory: " << settings.nixDataDir << "\n"; } ``` My first idea would be to simply remove the log level check in `printVersion`, because I don't think it's bad to have this information even if the log level is set to `lvlError`. For the root cause, it seems to be due to the following lines in `lix/nix/main.cc`: ```cpp // FIXME: stop messing about with log verbosity depending on if it is interactive use if (isatty(STDERR_FILENO)) { verbosity = lvlNotice; } else { verbosity = lvlInfo; } ``` But if I comment those lines, it breaks `functional/flakes/show.sh:113` test related to `nix flake show`, and I'm not experience / skilled enough with flake and lix development / tests to quickly fix this.
Author
Owner

#230 related maybe to the debug info in --version

Here's the reasons that we haven't removed that logging stuff pending more work being done to actually fix it:

https://git.lix.systems/lix-project/lix/issues/230 related maybe to the debug info in --version Here's the reasons that we haven't removed that logging stuff pending more work being done to actually fix it: - https://git.lix.systems/lix-project/lix/issues/362 - https://git.lix.systems/lix-project/lix/issues/367
Author
Owner

I think the practical thing to do is to delete the verbosity check in --version itself and do the other bits separately since that stuff is already printed in nix-env --version and similar. Let me check if nixpkgs is misusing it somewhere that might cause regressions.

I think the practical thing to do is to delete the verbosity check in `--version` itself and do the other bits separately since that stuff is already printed in `nix-env --version` and similar. Let me check if nixpkgs is misusing it somewhere that might cause regressions.
Author
Owner

alright there's no obvious foolish stuff in nixpkgs, and besides, the only place they appear to do call it at all is without a tty attached, which won't have a behaviour change anyway. should be ok.

alright there's no obvious foolish stuff in nixpkgs, and besides, the only place they appear to do call it at all is without a tty attached, which won't have a behaviour change anyway. should be ok.
Member

This issue was mentioned on Gerrit on the following CLs:

  • commit message in cl/2365 ("libmain: always print all information when calling nix --version")
<!-- GERRIT_LINKBOT: {"cls": [{"backlink": "https://gerrit.lix.systems/c/lix/+/2365", "number": 2365, "kind": "commit message"}], "cl_meta": {"2365": {"change_title": "libmain: always print all information when calling `nix --version`"}}} --> This issue was mentioned on Gerrit on the following CLs: * commit message in [cl/2365](https://gerrit.lix.systems/c/lix/+/2365) ("libmain: always print all information when calling `nix --version`")
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#620
No description provided.