nix-output-monitor
nix-output-monitor copied to clipboard
Invoke `nix` on unsupported/unknown subcommands
I did alias nix=nom
, and was very pleased with my new nix build
experience. Then, I wanted to run nix repl
, and was frustrated that nom
does not "forward" this command to nix
transparently, i.e., it did not invoke nix repl
.
As long as you don't support all nix
subcommands, please consider to just invoke nix
: The command nom foobar
should invoke nix foobar
.
In the meantime, I'll be using this workaround via Home Manager:
pkgs.writeShellApplication {
name = "nix-nom";
text = ''
set -euo pipefail
if [ "$1" = "build" ] || [ "$1" = "shell" ] || [ "$1" = "develop" ]
then
${pkgs.nix-output-monitor}/bin/nom "''${@:1}"
else
${osConfig.nix.package}/bin/nix "''${@:1}"
fi
'';
}
(and alias nix=nix-nom
)
I have pondered this for quite a while and I certainly want a good solution for this. Sadly I see a huge footgun potential here. nom takes nix from the PATH. In your case with the alias you are actually fine, but imagine someone using a symlink nix -> nom, then nom will recusively call itself.
Ah, well. You actually don't set nix -> nom.
I agree that symlinking nix -> nom
is a no-go. Also, removing nix
from $PATH
is a no-go.
In some cases (nom [build|develop|shell]
) nom
will exec nix
anyway. I am asking that nom
also does this for any other subcommand.
Whether someone wants to alias nix=nom
is a different matter. I am not suggesting that nom
should do aliasing, but I am asking to really support aliasing. For me, when I read "drop in replacement" (like in your README) I expect a plain alias to work. And not just for a few subcommands, but for all of them. See e.g. mislav/hub where you have an alias git=hub
situation.
If I ever have a problem with the alias, I just remove it and run nix
directly.
Point taken. I had this on my radar anyway and will look into it.
@lorenzleutgeb you can have a look at my code in https://github.com/maralorn/nix-output-monitor/issues/108 to create your own aliases. It's not 100% battle-tested but it's a starting point.
Thanks @zeorin, that's super cool to see, but way too involved for me at the moment.