Linux NixOsHyperV

Overview

Another try at NixOs using Hyper-V.

Hyper-V

Create a new VM CPU : 4 RAM : 4 Gb Hard disk : 50Gb

Stop VM, and go back to the VM settings. In Security, disable Enable Secure Boot. Start the VM and follow up Zorin installation.

Installation

Generate the system configuration file :

1
nixos-generate-config --root /mnt

Rebuild after updating the configuration :

1
nixos-rebuild switch

Custom Config files

I am using Alacritty, which uses a config file (~/alacritty/alacritty.toml) and I would like the configuration to be done when I am building the station.

The best way I have found is to use home-manager and to make it copy the config file :

	{ config, pkgs, lib, ... }:

let
  home-manager = builtins.fetchTarball https://github.com/nix-community/home-manager/archive/release-24.11.tar.gz;
in
{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      (import "${home-manager}/nixos")
    ];

    ...

  # user configs
  home-manager.users.myuser = { pkgs, ... }: {
    home.packages = [ pkgs.atool pkgs.httpie ];
	
    home.file."alacritty/alacritty.toml".source = ./alacritty.toml;
    ...
  }
 }

bash customization

To launch FastFetch when opening a new bash add the following in the home.manager block :

1
2
3
4
5
6
	 programs.bash = {
		 enable = true;
		 bashrcExtra = ''
		   fastfetch
		 '';
	  };

Maintenance

Each configuration built, will generate a new generation. That list of generation is hown in the boot menu and it s allowing us to come back to a previous version if needed.

The Generations are in the /nix folders.

1
2
ls /nix
ls /nix/var/nix/profiles

The ’nixos-rebuild’ command can list the generations too

1
nixos-rebuild list-generations

It is possible to remove some generations

1
nix-env -p /nix/var/nix/profiles/system --delete-generations 3 4 5 6 7

The command nix-collect-garbage can be used to recover the disk space associated to those generations.

1
nix-collect-garbage

To update the boot menu to reflect the list of generations, rebuild the OS.

1
nixos-rebuild switch

To clean up alder generation use the following command :

Conclusion

NixOs is a true blessing, making it possible to rebuild any machine with most of the configuration exactly as I like it to be. The only part I keep doing manually is related to the security requirements, like setting ssh keys, etc…

References