mirror of
https://github.com/srid/nixos-config.git
synced 2026-02-23 05:15:19 +08:00
Add incus container
This commit is contained in:
parent
11dc14ddfe
commit
a95f675a1f
3 changed files with 68 additions and 12 deletions
20
configurations/nixos/public-container/configuration.nix
Normal file
20
configurations/nixos/public-container/configuration.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{ flake, pkgs, ... }:
|
||||
|
||||
let
|
||||
inherit (flake) inputs;
|
||||
inherit (inputs) self;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
"${inputs.nixpkgs}/nixos/modules/virtualisation/lxc-container.nix"
|
||||
(self + /modules/nixos/shared/primary-as-admin.nix)
|
||||
];
|
||||
|
||||
nixpkgs.hostPlatform = "x86_64-linux";
|
||||
networking.firewall.enable = true;
|
||||
|
||||
# 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-container/default.nix
Normal file
19
configurations/nixos/public-container/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 ];
|
||||
};
|
||||
}
|
||||
|
|
@ -1,18 +1,35 @@
|
|||
{ inputs, ... }: {
|
||||
perSystem = { pkgs, ... }: {
|
||||
apps.incus-image-import.program = pkgs.writeShellApplication {
|
||||
name = "incus-image-import";
|
||||
text = ''
|
||||
NAME=$1
|
||||
perSystem = { pkgs, system, ... }: {
|
||||
apps = {
|
||||
incus-image-vm-import.program = pkgs.writeShellApplication {
|
||||
name = "incus-image-vm-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 "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"
|
||||
'';
|
||||
echo "Importing ... "
|
||||
set -x
|
||||
sudo incus image import --alias srid/"$NAME" "$METADATA"/*.tar.xz "$IMG"
|
||||
'';
|
||||
};
|
||||
|
||||
incus-image-container-import.program = pkgs.writeShellApplication {
|
||||
name = "incus-image-container-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.squashfs)/nixos-lxc-image-${system}.squashfs
|
||||
|
||||
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