Flake extensions for defining vms
This commit is contained in:
parent
dae8ffd3c2
commit
5575532464
15
flake.nix
15
flake.nix
|
@ -23,6 +23,11 @@
|
||||||
url = "gitlab:simple-nixos-mailserver/nixos-mailserver";
|
url = "gitlab:simple-nixos-mailserver/nixos-mailserver";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
microvm = {
|
||||||
|
url = "github:astro/microvm.nix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
|
@ -30,6 +35,10 @@
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
...
|
...
|
||||||
} @ inputs: let
|
} @ inputs: let
|
||||||
|
lib = import ./lib {
|
||||||
|
inherit nixpkgs;
|
||||||
|
inherit self;
|
||||||
|
};
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = import nixpkgs {inherit system;};
|
pkgs = import nixpkgs {inherit system;};
|
||||||
in {
|
in {
|
||||||
|
@ -41,10 +50,12 @@
|
||||||
inputs.agenix.nixosModules.default
|
inputs.agenix.nixosModules.default
|
||||||
inputs.home-manager.nixosModules.default
|
inputs.home-manager.nixosModules.default
|
||||||
inputs.simple-nixos-mailserver.nixosModule
|
inputs.simple-nixos-mailserver.nixosModule
|
||||||
|
inputs.microvm.nixosModules.microvm
|
||||||
|
{microvm.hyprvisor = "qemu";}
|
||||||
];
|
];
|
||||||
in {
|
in {
|
||||||
server-vm = nixpkgs.lib.nixosSystem {
|
server-vm = nixpkgs.lib.nixosSystem {
|
||||||
specialArgs = {inherit inputs;};
|
specialArgs = {inherit inputs lib;};
|
||||||
modules =
|
modules =
|
||||||
[
|
[
|
||||||
(import ./disko.nix {
|
(import ./disko.nix {
|
||||||
|
@ -65,7 +76,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
server = nixpkgs.lib.nixosSystem {
|
server = nixpkgs.lib.nixosSystem {
|
||||||
specialArgs = {inherit inputs;};
|
specialArgs = {inherit inputs lib;};
|
||||||
modules =
|
modules =
|
||||||
[
|
[
|
||||||
(import ./disko.nix {
|
(import ./disko.nix {
|
||||||
|
|
29
lib/default.nix
Normal file
29
lib/default.nix
Normal 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";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
Loading…
Reference in a new issue