Flake extensions for defining vms

This commit is contained in:
Snorre 2025-03-04 12:52:38 +01:00
parent dae8ffd3c2
commit 5575532464
2 changed files with 42 additions and 2 deletions

View file

@ -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 {

29
lib/default.nix Normal file
View file

@ -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";
};
};
};
}
)