I have a script that needs to be run on brand new virtual machines, but it depends on Nix being present, and I don't want to manually install it every time.
1 Answers
Use the nixos.org installer with the
--yes
option.Examples:
Use the DeterminateSystems installer with the --no-confirm option.
NOTE
Not sure how to use this option withcurl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
but hoping to test it soon.
This script seemed to do the trick for me:
#!/usr/bin/env bash
curl -L https://nixos.org/nix/install | sh -s -- --daemon --yes
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
Testing whether Nix is available in subsequent commands
nix --version
CAVEAT
The Nix installer uses sudo
so a password will still have to be entered manually. (This is not an issue for me, as I'm just trying to save time, and not fully automate the process - at least for now. There are workarounds though on how to install Nix without root permissions.)
Where are the Nix installer options documented?
They aren't documented. A pull request is forthcoming, and this NixOS Discourse thread lists all available options until then. (Also, here's a skeleton of a man page draft for the installer.)

- 1,080