1

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.

toraritte
  • 1,018
  • 13
  • 22
  • [Thread on the NixOS Discourse.](https://discourse.nixos.org/t/how-to-run-the-nix-installer-silently-from-a-shell-script/25633) – toraritte Feb 20 '23 at 21:00

1 Answers1

1

Use the --yes option.

For example:

  • with the nix.dev version:

    curl -L https://nixos.org/nix/install | sh -s -- --daemon --yes
    
  • with the one on nixos.org

    sh <(curl -L https://nixos.org/nix/install) --daemon --yes
    

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.)

toraritte
  • 1,018
  • 13
  • 22