diff --git a/flake.nix b/flake.nix index ff788cc..a2bb9c4 100755 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,11 @@ url = "gitlab:simple-nixos-mailserver/nixos-mailserver"; inputs.nixpkgs.follows = "nixpkgs"; }; + + microvm = { + url = "github:astro/microvm.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { @@ -30,6 +35,10 @@ nixpkgs, ... } @ inputs: let + lib = import ./lib { + inherit nixpkgs; + inherit self; + }; system = "x86_64-linux"; pkgs = import nixpkgs {inherit system;}; in { @@ -41,10 +50,12 @@ inputs.agenix.nixosModules.default inputs.home-manager.nixosModules.default inputs.simple-nixos-mailserver.nixosModule + inputs.microvm.nixosModules.microvm + {microvm.hyprvisor = "qemu";} ]; in { server-vm = nixpkgs.lib.nixosSystem { - specialArgs = {inherit inputs;}; + specialArgs = {inherit inputs lib;}; modules = [ (import ./disko.nix { @@ -65,7 +76,7 @@ }; server = nixpkgs.lib.nixosSystem { - specialArgs = {inherit inputs;}; + specialArgs = {inherit inputs lib;}; modules = [ (import ./disko.nix { diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..98141c1 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,29 @@ +{ + self, + nixpkgs, + ... +}: +nixpkgs.lib.extend ( + _final: prev: let + inherit (prev) mkIf; + in { + extensions = { + createvm = { + name, + system ? nixpkgs.system, + config, + }: {microvm, ...}: { + imports = [microvm.host]; + microvm.vms.${name} = { + pkgs = import nixpkgs {inherit system;}; + inherit config; + # Host build-time reference to where the MicroVM NixOS is defined + # under nixosConfigurations + flake = self; + # Specify from where to let `microvm -u` update later on + updateFlake = "git+file:///etc/nixos"; + }; + }; + }; + } +)