Add a straightforward way to determine if inside a nix3 shell
Motivation
I just want to have my Fish prompt tell me if I am in a Nix3 shell.
Context
See: #6677 #3862
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
- [ ] agreed on idea
- [ ] agreed on implementation strategy
- [ ] tests, as appropriate
- functional tests -
tests/**.sh - unit tests -
src/*/tests - integration tests -
tests/nixos/*
- functional tests -
- [ ] documentation in the manual
- [ ] documentation in the internal API docs
- [ ] code and comments are self-explanatory
- [ ] commit message explains why the change was made
- [ ] new feature or incompatible change: updated release notes
Priorities
Add :+1: to pull requests you find important.
Fixes #3862 #6677
This pull request has been in standby for a year. Any news?
It is Nix, so you can just apply this patch with an overlay:
https://git.sr.ht/~fd/nix-configs/tree/dea481544e44e1289d88f802f3eaa2cc23fdf63c/item/overlays/default.nix#L30
https://git.sr.ht/~fd/nix-configs/tree/dea481544e44e1289d88f802f3eaa2cc23fdf63c/item/nixos/common/default.nix#L124
Be sure to not name the modified package nix because it will then change the hashes for a bunch of Electron dependencies (and cause Chromium to compile from scratch, not fun).
As I was writing this blog post, I figured out the problem: electron depends on prefetch-npm-deps which in turn depends on nix itself. However, I had patched the Nix package to set an environment variable when running in a nix3 shell, so this broke the chain of dependencies and thus caused prefetch-npm-deps and everything that depended on it to recompile. What caused me to look into this was that I noticed that both jellyfin-media-player and prefetch-npm-deps were being recompiled on update. Going into my flake.nix and removing the overlays section caused Electron's hashes to match, so it was only a few minutes until I figured out that the Nix patches caused the issue. Renaming the Nix package to customnix and setting the nix.package setting to use customnix fixed everything. Commit which fixed the issue. ↩
Personally, to avoid having recompile nix I just make a wrapper:
nix.package =
pkgs.symlinkJoin
{
name = "nix-custom";
version = pkgs.nix.version;
paths = [
pkgs.nix
];
buildInputs = [pkgs.makeWrapper];
postBuild = ''
wrapProgram $out/bin/nix \
--run "[ \"\$1\" = \"shell\" ] \
&& export IN_NIX_SHELL=\"impure\" \
&& export name=\"shell\""
'';
};
Perhaps it's not the cleanest solution, but it gets the job done.
The fact that Lix has now added this common sense feature before Nix has (after a 15 month head start) is absurd.