NixOS:nixos-rebuild build-vm: Difference between revisions

From NixOS Wiki
imported>Korfuri
initialPassword makes the password immediately usable; previously, with initialHashedPassword the user would have needed to hash it and this wasn't indicated
imported>Oxalica
m Mention options to enlarge CPU count and memory size of the virtual machine
Line 18: Line 18:


https://discourse.nixos.org/t/default-login-and-password-for-nixos/4683/2
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 <code>virtualisation.cores</code> and <code>virtualisation.memorySize</code> to enlarge the CPU cores and memory size for the virtual machine. Note that due to [https://github.com/NixOS/nixpkgs/issues/59219 issue 59219], you need to import an extra module in order to use these options.
<syntaxhighlight lang="nix">
{
  imports = [ <nixpkgs/nixos/modules/virtualisation/qemu-vm.nix> ];
  virtualisation = {
    memorySize = 2048; # Use 2048MiB memory.
    cores = 4;        # Simulate 4 cores.
  };
}
</syntaxhighlight>

Revision as of 12:29, 13 September 2022

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

You will not be able to login to this virtual machine, as the passwords are not carried over to the virtual machine you build.

If you have a user called nixosvmtest for example, you can add

users.users.nixosvmtest.initialPassword = "test";

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.

{
  imports = [ <nixpkgs/nixos/modules/virtualisation/qemu-vm.nix> ];
  virtualisation = {
    memorySize = 2048; # Use 2048MiB memory.
    cores = 4;         # Simulate 4 cores.
  };
}