diff --git a/source/tutorials/nixos/nixos-configuration-on-vm.md b/source/tutorials/nixos/nixos-configuration-on-vm.md index 134b5a5..afb9c1b 100644 --- a/source/tutorials/nixos/nixos-configuration-on-vm.md +++ b/source/tutorials/nixos/nixos-configuration-on-vm.md @@ -125,11 +125,9 @@ The complete `configuration.nix` file now looks like this: } ``` -## Creating a QEMU based virtual machine using a configuration +## Creating a QEMU based virtual machine from a NixOS configuration -A virtual machine is created with the `nix-build` command. - -To select `configuration.nix` in the working directory, specify the configuration file on the command line: +A NixOS virtual machine is created with the `nix-build` command: ```shell-session nix-build '' -A vm \ @@ -141,13 +139,19 @@ This command builds the attribute `vm` from the `nixos-22.11` release of NixOS,
Detailed explanation -The first optional argument of [`nix-build`](https://nixos.org/manual/nix/stable/command-ref/nix-build.html) is a path to the derivation to be built. -With `''` Nix is instructed to resolve the search path defined with the [`NIX_PATH` environment variable](https://nixos.org/manual/nix/stable/command-ref/env-common.html#env-NIX_PATH) or the [`-I` option](https://nixos.org/manual/nix/unstable/command-ref/opt-common.html#opt-I). -The virtual machine setup is provided by NixOS, which is part of the `nixpkgs` repository, therefore we use `''`. -The [`-A` option](https://nixos.org/manual/nix/stable/command-ref/opt-common.html#opt-attr) specifies the attribute to pick from the provided [Nix expression ``](search-path-tutorial). -To build the virtual machine, you choose the `vm` attribute as defined in [`nixos/default.nix`](https://github.com/NixOS/nixpkgs/blob/7c164f4bea71d74d98780ab7be4f9105630a2eba/nixos/default.nix#L19). -The [`-I` option](https://nixos.org/manual/nix/stable/command-ref/opt-common.html#opt-I) adds search paths. -Here we set `nixpkgs` to refer to a specific version of NixOS and to set `nix-config` to the `configuration.nix` file in the current directory. +- The positional argument to [`nix-build`](https://nixos.org/manual/nix/stable/command-ref/nix-build.html) is a path to the derivation to be built. + That path can be obtained from [a Nix expression that evaluates to a derivation](derivations). + + The virtual machine build helper is defined in NixOS, which is part of the [`nixpkgs` repository](https://github.com/NixOS/nixpkgs). + Therefore we use the [lookup path](search-path-tutorial) ``. + +- The [`-A` option](https://nixos.org/manual/nix/stable/command-ref/opt-common.html#opt-attr) specifies the attribute to pick from the provided Nix expression ``. + + To build the virtual machine, we choose the `vm` attribute as defined in [`nixos/default.nix`](https://github.com/NixOS/nixpkgs/blob/7c164f4bea71d74d98780ab7be4f9105630a2eba/nixos/default.nix#L19). + +- The [`-I` option](https://nixos.org/manual/nix/stable/command-ref/opt-common.html#opt-I) prepends entries to the search path. + + Here we set `nixpkgs` to refer to a [specific version of Nixpkgs](ref-pinning-nixpkgs) and set `nix-config` to the `configuration.nix` file in the current directory. :::{admonition} NixOS On NixOS the `$NIX_PATH` environment variable is usually set up automatically, and there is also [a convenience command for building virtual machines](https://nixos.org/manual/nixos/stable/#sec-changing-config).