Nix print-dev-env command shows some assinments to readonly variables

I think this topic is related to this PR: Ignore readonly variables used in ZSH for `nix print-dev-env` by ryanong · Pull Request #6800 · NixOS/nix · GitHub

Not only Zsh, but Bash v5 also comes with the bash variables such as EPOCHREALTIME. The thing is, assignments to those variables makes no sense AFAIK. However, the results of the nix print-dev-env command shows assignment to those variables.

Like this:

EPOCHREALTIME='1660270372.326628'
EPOCHSECONDS='1660270372'

Is this intended behavior? How can I avoid these assignments if I want? Or shoud I send a PR?

Cheers.

Bash variables manual

I’m 99% sure these are set for reproducibility purposes. Without them, two builds may use different timestamps for things, which would mean that the outputs aren’t the same bit-for-bit. nix print dev-env will show them because it’s part of the env.

Mildly surprised at this though. It may be a fallback for when certain namespaces aren’t available?

Looking at the manual entry, setting them only does something useful if they’re unset first. If that doesn’t happen I’d send a PR making these actually meaningful.

Is there any reason you want to disable this behavior? You could sed it out of the output before evaling it.

Thanks for the reply!

Looking at the manual entry, setting them only does something useful if they’re unset first.

You’re right. It looks like if you unset first, then you can assign to them. So if someone use the variable this way in their environment, this behavior might be necessary for reproducibility.

Is there any reason you want to disable this behavior?

Actually it turns out one of the shell script library I use does readonly EPOCHREALTIME at the startup of the bash interactive shell. Thus, when I do nix develop, I get a warning like bash: EPOCHREALTIME: readonly variable. It’s just a warning, so I can simply ignore that, but it bothers me a bit.

So I’m actually having trouble with nix develop and I can’t simply sed it out since I’m not literary sourcing nix print-dev-env in this case.

Do you know how to do this for nix develop? (Maybe I can use --ignore-environment and --keep flags for that but it seems a lot of work to specify everything I want to keep and I’d like to know if there is an easier way.)

Is this part of your personal bashrc or of the dev environment itself? If the former, do you really need that check? Can you just patch it out downstream? If the latter, you should be able to either patch it out as well, or source it after those vars have been set.

Making nix develop behave differently is a bit tricky, I think, and possibly not recommended, even for something as small as this.

It’s part of my personal bashrc and the library called ble.sh which replaces bash’s GNU Readline and provides better auto-completion and syntax highlighting for bash.

From what I’ve seen of the library code, I guess the readonly check isn’t really necessary. So I’m gonna try to patch them.

Thanks!

I made a patch and it works so far. It might help other Nix users who use ble.sh so I leave it here.

Note: target revision is ble.sh, version 0.4.0-nightly+a22e145 (noarch)

1 Like

By the way, this has recently been packaged in nixpkgs: https://github.com/NixOS/nixpkgs/pull/181963

There’s apparently a home-manager module in the works, too: [home-manager] What options should be made configurable in home-manager? · Issue #216 · akinomyoga/ble.sh · GitHub

Probably worth keeping an eye on - no need to package it yourself, and perhaps you can help fix this problem upstream before anyone else sees it :slight_smile:

Thanks for letting me know, but actually I know both of them. :slight_smile: I’ve even submitted a PR for the package in nixpkgs. blesh: unstable-2022-07-24 -> unstable-2022-07-29, refactor by tars0x9752 · Pull Request #185866 · NixOS/nixpkgs · GitHub

I could send another PR for the nix develop patch here, but my previous PR has not received any response yet, so I’m just waiting to see how it goes.

1 Like