incus: Custom images (#78)

This commit is contained in:
Sridhar Ratnakumar 2025-01-21 18:50:01 -05:00 committed by GitHub
parent 5b25e3253d
commit 01cd095e0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 83 additions and 0 deletions

View file

@ -0,0 +1,19 @@
{ flake, pkgs, ... }:
let
inherit (flake) inputs;
inherit (inputs) self;
in
{
nixos-unified.sshTarget = "srid@hello";
imports = [
../public-vm/configuration.nix
];
networking.hostName = "hello";
environment.systemPackages = with pkgs; [
neovim
];
}

View file

@ -0,0 +1,27 @@
{ flake, pkgs, ... }:
let
inherit (flake) inputs;
inherit (inputs) self;
in
{
imports = [
"${inputs.nixpkgs}/nixos/modules/virtualisation/lxd-virtual-machine.nix"
(self + /modules/nixos/shared/primary-as-admin.nix)
];
nixpkgs.hostPlatform = "x86_64-linux";
services.openssh = {
enable = true;
settings.PasswordAuthentication = false;
};
networking.firewall = {
enable = true;
allowedTCPPorts = [ 22 ];
};
# Workaround the annoying `Failed to start Network Manager Wait Online` error on switch.
# https://github.com/NixOS/nixpkgs/issues/180175
systemd.services.NetworkManager-wait-online.enable = false;
system.stateVersion = "24.11";
}

View file

@ -0,0 +1,19 @@
{ pkgs, ... }:
{
imports = [
./configuration.nix
];
# Hello world service
services.nginx = {
enable = true;
# Return "Hello World" on / request
virtualHosts."_" = {
root = "${pkgs.writeTextDir "index.html" "Hello World"}";
};
};
networking.firewall = {
allowedTCPPorts = [ 80 ];
};
}

View file

@ -0,0 +1,18 @@
{ inputs, ... }: {
perSystem = { pkgs, ... }: {
apps.incus-image-import.program = pkgs.writeShellApplication {
name = "incus-image-import";
text = ''
NAME=$1
echo "Building image ... "
METADATA=$(nix build --no-link --print-out-paths ${inputs.self}#nixosConfigurations."$NAME".config.system.build.metadata)/tarball/
IMG=$(nix build --no-link --print-out-paths ${inputs.self}#nixosConfigurations."$NAME".config.system.build.qemuImage)/nixos.qcow2
echo "Importing ... "
set -x
sudo incus image import --alias srid/"$NAME" "$METADATA"/*.tar.xz "$IMG"
'';
};
};
}