NixOS:nixos-rebuild build-vm: Difference between revisions
imported>Reijix Updated filepaths according to style guide |
imported>ErnstderLage add parameter -I example |
||
Line 3: | Line 3: | ||
<code> | <code> | ||
nixos-rebuild build-vm | nixos-rebuild build-vm | ||
nixos-rebuild build-vm -I nixos-config=./configuration.nix -I nix_path='<nixpkgs/nixos>' --show-trace # e.g. to specify the environment variables | |||
</code> | </code> | ||
Revision as of 04:28, 6 July 2023
A virtual machine can be created , it will use your /etc/nixos/configuration.nix to make a 'clone' of your system. Useful for testing new configurations.
nixos-rebuild build-vm
nixos-rebuild build-vm -I nixos-config=./configuration.nix -I nix_path='<nixpkgs/nixos>' --show-trace # e.g. to specify the environment variables
You will not be able to login to this virtual machine, as the passwords are not carried over to the virtual machine you build.
You should have user nixosvmtest (isSystemUser or isNormalUser)
users.users.nixosvmtest.isSystemUser = true ;
users.users.nixosvmtest.initialPassword = "test";
If you have a user called nixosvmtest for example, you can add
users.users.nixosvmtest.group = "nixosvmtest";
users.groups.nixosvmtest = {};
to your /etc/nixos/configuration.nix
you should now be able to login and test your system with this user and password.
https://discourse.nixos.org/t/default-login-and-password-for-nixos/4683/2
By default, the virtual machine is configured to have 1 CPU and 1024MiB memory. It may be too small for testing with desktop environment enabled inside. You can set options virtualisation.cores
and virtualisation.memorySize
to enlarge the CPU cores and memory size for the virtual machine. Note that due to issue 59219, you need to import an extra module in order to use these options.
{
virtualisation.vmVariant = {
# following configuration is added only when building VM with build-vm
virtualisation = {
memorySize = 2048; # Use 2048MiB memory.
cores = 3;
};
};
}
or
{
imports = [ <nixpkgs/nixos/modules/virtualisation/qemu-vm.nix> ];
virtualisation = {
memorySize = 2048; # Use 2048MiB memory.
cores = 4; # Simulate 4 cores.
};
}
Troubleshooting
Still can't login after updating configuration
When running a virtual machine a file called $hostname.qcow2
is created in your current working directory. After changing your /etc/nixos/configuration.nix
delete this file, rebuild and then start the new virtual machine. Now you should be able to login.