Created
May 27, 2024 18:35
-
-
Save nh2/2fccf9ef5da3f868afb685e9031e126b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This `firefox-vm.nix` builds a simple NixOS VM with XFCE and Firefox inside. | |
# | |
# Build and run it with: | |
# | |
# nix-build '<nixpkgs/nixos>' -A vm -I nixos-config=./firefox-vm.nix | |
# result/bin/run-nixos-vm | |
# | |
# Log in as "root" with empty password. | |
# | |
# To delete the VM state (storage): | |
# | |
# rm nixos.qcow2 | |
{ config, pkgs, ... }: | |
{ | |
system.stateVersion = "23.11"; # NixOS version this was written for; you can bump it for newer NixOS | |
imports = [ | |
<nixpkgs/nixos/modules/virtualisation/qemu-vm.nix> # for `virtualisation.*` options to be available | |
]; | |
boot.loader.systemd-boot.enable = true; | |
boot.loader.efi.canTouchEfiVariables = true; | |
services.xserver = { | |
enable = true; | |
desktopManager = { | |
xterm.enable = false; | |
xfce.enable = true; | |
}; | |
displayManager.defaultSession = "xfce"; | |
}; | |
users.users.root = { | |
packages = with pkgs; [ vim ]; | |
# Changes in this only take effect after deleting the local VM state (`nixos.qcow2`). | |
hashedPassword = ""; # "" means passwordless login | |
}; | |
environment.systemPackages = with pkgs; [ | |
firefox | |
]; | |
virtualisation = { | |
# Changes in this only take effect after deleting the local VM state (`nixos.qcow2`). | |
diskSize = 50000; # MB | |
memorySize = 3000; # MB | |
writableStoreUseTmpfs = false; # otherwise adding stuff to the nix store consumes RAM | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment