Last active
October 28, 2025 15:21
-
-
Save FlakM/0535b8aa7efec56906c5ab5e32580adf to your computer and use it in GitHub Desktop.
Revisions
-
FlakM revised this gist
Apr 8, 2024 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -32,7 +32,8 @@ Did you know that it is rather easy to setup a VM to test your NixOs configurati { config, lib, pkgs, ... }: { # customize kernel version boot.kernelPackages = pkgs.linuxPackages_5_15; users.groups.admin = {}; users.users = { admin = { isNormalUser = true; -
FlakM renamed this gist
May 22, 2023 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ # Setting up qemu VM using nix flakes Did you know that it is rather easy to setup a VM to test your NixOs configuration? ## Create simple flake: ```nix -
FlakM revised this gist
May 22, 2023 . 1 changed file with 12 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,13 @@ ## Create simple flake: ```nix # flake.nix { inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; outputs = { self, nixpkgs, ... }: let system = "x86_64-linux"; in { # test is a hostname for our machine @@ -20,13 +19,12 @@ cat <<EOF > flake.nix }; }; } ``` ## Add your configuration ```nix # configuration.nix { config, lib, pkgs, ... }: { # customize kernel version boot.kernelPackages = pkgs.linuxPackages_5_15; @@ -61,7 +59,6 @@ cat <<EOF > configuration.nix system.stateVersion = "23.05"; } ``` ## Run a VM @@ -70,8 +67,14 @@ EOF git init # skip this step if you are inside already tracked repository git add . # flakes requires at least tracking the files nixos-rebuild build-vm --flake .#test # expose port 22 from guest export QEMU_NET_OPTS="hostfwd=tcp::2221-:22" result/bin/run-nixos-vm ``` ## Profit! ```bash # ssh onto the machine ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no admin@localhost -p 2221 ``` -
FlakM created this gist
May 22, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,77 @@ ## Create simple flake: ```bash cat <<EOF > flake.nix { inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; outputs = { self, nixpkgs, ... }@attrs: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; in { # test is a hostname for our machine nixosConfigurations.test = nixpkgs.lib.nixosSystem { inherit system; modules = [ ./configuration.nix ]; }; }; } EOF ``` ## Add your configuration ```bash cat <<EOF > configuration.nix { config, lib, pkgs, ... }: { # customize kernel version boot.kernelPackages = pkgs.linuxPackages_5_15; users.users = { admin = { isNormalUser = true; extraGroups = [ "wheel" ]; password = "admin"; group = "admin"; }; }; virtualisation.vmVariant = { # following configuration is added only when building VM with build-vm virtualisation = { memorySize = 2048; # Use 2048MiB memory. cores = 3; graphics = false; }; }; services.openssh = { enable = true; settings.PasswordAuthentication = true; }; networking.firewall.allowedTCPPorts = [ 22 ]; environment.systemPackages = with pkgs; [ htop ]; system.stateVersion = "23.05"; } EOF ``` ## Run a VM ```bash git init # skip this step if you are inside already tracked repository git add . # flakes requires at least tracking the files nixos-rebuild build-vm --flake .#test export QEMU_NET_OPTS="hostfwd=tcp::2221-:22" result/bin/run-nixos-vm ``` ## Profit!