mirror of
https://github.com/srid/nixos-config.git
synced 2026-04-08 19:55:56 +08:00
incus: Custom images (#78)
This commit is contained in:
parent
5b25e3253d
commit
01cd095e0e
4 changed files with 83 additions and 0 deletions
19
configurations/nixos/hello/default.nix
Normal file
19
configurations/nixos/hello/default.nix
Normal 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
|
||||
];
|
||||
}
|
||||
27
configurations/nixos/public-vm/configuration.nix
Normal file
27
configurations/nixos/public-vm/configuration.nix
Normal 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";
|
||||
}
|
||||
19
configurations/nixos/public-vm/default.nix
Normal file
19
configurations/nixos/public-vm/default.nix
Normal 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 ];
|
||||
};
|
||||
}
|
||||
18
modules/flake-parts/incus-image.nix
Normal file
18
modules/flake-parts/incus-image.nix
Normal 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"
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue