add defaultTemplate

This commit is contained in:
Julie B. 2021-07-04 20:50:02 +02:00
parent 84d66f158a
commit 4c4b9126fd
8 changed files with 87 additions and 20 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.direnv
result*
/template/flake.lock

View File

@ -34,6 +34,14 @@ second command.
[flakes]: https://nixos.wiki/wiki/Flakes
## Getting started
You base your flake on the template. Copy the `template/` directory from the
repository, or run:
```sh
nix flake new -t github:bbjubjub2494/miniguest
```
## Usage
Guest system configuration must be presented within a Nix flake, import the
@ -43,9 +51,7 @@ Guest system configuration must be presented within a Nix flake, import the
sudo miniguest install «flakePath»#«guestName»
```
The configuration will then be built and will appear under
`/etc/miniguests/«guestName»`. Refer to [this
template](templates/libvirt-kvm.xml) to create the corresponding libvirt
domain.
`/etc/miniguests/«guestName»`.
It is recommended to create at most one domain per configuration so that they
can all be rebuilt independently of each other.

View File

@ -11,6 +11,10 @@
overlay = final: prev: {
miniguest = final.callPackage ./miniguest { };
};
defaultTemplate = {
description = "Example guest configurations";
path = ./template;
};
} // simpleFlake {
inherit self nixpkgs;
name = "miniguest";

7
template/README.md Normal file
View File

@ -0,0 +1,7 @@
# My Miniguest guests
To create and start a VM, run
```sh
sudo miniguest install .#stateless
virsh create --console --autodestroy guests/stateless/domain.xml
```

18
template/flake.nix Normal file
View File

@ -0,0 +1,18 @@
{
description = "My Miniguest guests";
inputs = {
nixos.url = "nixpkgs/nixos-unstable";
miniguest.url = "github:bbjubjub2494/miniguest";
miniguest.inputs.nixpkgs.follows = "nixos";
};
outputs = { self, miniguest, nixos }:
with nixos.lib; {
nixosConfigurations = attrsets.genAttrs [ "stateless" ] (name:
nixosSystem {
system = "x86_64-linux";
modules = [ miniguest.nixosModules.miniguest (./guests + "/${name}") ];
});
};
}

View File

@ -0,0 +1,19 @@
{ modulesPath, ... }:
{
imports = [
(modulesPath + "/profiles/qemu-guest.nix")
];
# Use miniguest
boot.loader.grub.enable = false;
boot.miniguest.enable = true;
fileSystems."/" = {
device = "none";
fsType = "tmpfs";
options = [ "defaults" "mode=755" ];
};
users.users.root.hashedPassword = "";
}

View File

@ -0,0 +1,28 @@
<domain type="kvm">
<name>stateless-example-miniguest</name>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://nixos.org/nixos/unstable"/>
</libosinfo:libosinfo>
</metadata>
<os>
<type>hvm</type>
<kernel>/etc/miniguests/stateless/kernel</kernel>
<initrd>/etc/miniguests/stateless/initrd</initrd>
<cmdline>console=ttyS0</cmdline>
</os>
<memory unit="GiB">1</memory>
<devices>
<serial type="pty"/>
<filesystem type="mount" accessmode="squash">
<source dir="/nix/store"/>
<target dir="nix-store"/>
<readonly/>
</filesystem>
<filesystem type="mount" accessmode="squash">
<source dir="/etc/miniguests/stateless/boot"/>
<target dir="boot"/>
<readonly/>
</filesystem>
</devices>
</domain>

View File

@ -1,17 +0,0 @@
<domain type="kvm">
<name>@guestName@</name>
<os>
<kernel>@guestsDir@/@guestName@/kernel</kernel>
<initrd>@guestsDir@/@guestName@/initrd</initrd>
</os>
<filesystem type="mount" accessmode="squash">
<source dir="/nix/store"/>
<target dir="nix-store"/>
<readonly/>
</filesystem>
<filesystem type="mount" accessmode="squash">
<source dir="@guestsDir@/@guestName@/boot"/>
<target dir="boot"/>
<readonly/>
</filesystem>
</domain>