Search code examples
nixnixos

Why do some official Nix Docker containers not have the `nixos-rebuild` command?


The following official Nix Docker containers don't have the nixos-rebuild command:

Is there something missing from these instances of NixOS?

nixos/nix:

$ docker run --tty --interactive 'nixos/nix'
bash-5.1# nixos-rebuild
bash: nixos-rebuild: command not found

nixpkgs/nix-unstable:

$ docker run --tty --interactive 'nixpkgs/nix-unstable'
bash-5.2# nixos-rebuild
bash: nixos-rebuild: command not found

Solution

  • Because nixos-rebuild is from Nixos and not Nix.

    The name of the docker image is a bit confusing as the parent/user is nixos in (nixos/nix).

    It's also why you wont' find a nixos related configuration.nix file either in the image (as asked here: Where is the Nixos configuration located for the nix image on dockerhub?).

    There seems to be some issues with running Nixos in a docker container according to GitHub issue: NixOS/nixpkgs: Running NixOS inside Docker #2878, so likely you'll need a VM instead if you want do some testing.


    However, you can build a Nixos configuration using the nix container. Something along the lines of:

    nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=configuration-iso.nix

    The above command builds an ISO from the specified configuration-iso.nix. And will dump the contents into a result/ directory from where the command is run.