From 094f2b6c9d87da6348e2517936a3ad907c82d1cf Mon Sep 17 00:00:00 2001 From: Adam Stephens Date: Sat, 10 Aug 2024 12:40:16 -0400 Subject: nixos/incus: add incus-only vm and container images --- .../scripts/incus/incus-container-image-inner.nix | 34 +++++++++++++++ .../scripts/incus/incus-container-image.nix | 47 +++++++++++++++++++++ .../incus/incus-virtual-machine-image-inner.nix | 34 +++++++++++++++ .../scripts/incus/incus-virtual-machine-image.nix | 48 ++++++++++++++++++++++ nixos/maintainers/scripts/incus/nix.tpl | 12 ++++++ 5 files changed, 175 insertions(+) create mode 100644 nixos/maintainers/scripts/incus/incus-container-image-inner.nix create mode 100644 nixos/maintainers/scripts/incus/incus-container-image.nix create mode 100644 nixos/maintainers/scripts/incus/incus-virtual-machine-image-inner.nix create mode 100644 nixos/maintainers/scripts/incus/incus-virtual-machine-image.nix create mode 100644 nixos/maintainers/scripts/incus/nix.tpl (limited to 'nixos/maintainers/scripts') diff --git a/nixos/maintainers/scripts/incus/incus-container-image-inner.nix b/nixos/maintainers/scripts/incus/incus-container-image-inner.nix new file mode 100644 index 000000000000..68979306a610 --- /dev/null +++ b/nixos/maintainers/scripts/incus/incus-container-image-inner.nix @@ -0,0 +1,34 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ modulesPath, ... }: + +{ + imports = [ + # Include the default incus configuration. + "${modulesPath}/virtualisation/lxc-container.nix" + # Include the container-specific autogenerated configuration. + ./incus.nix + ]; + + networking = { + dhcpcd.enable = false; + useDHCP = false; + useHostResolvConf = false; + }; + + systemd.network = { + enable = true; + networks."50-eth0" = { + matchConfig.Name = "eth0"; + networkConfig = { + DHCP = "ipv4"; + IPv6AcceptRA = true; + }; + linkConfig.RequiredForOnline = "routable"; + }; + }; + + system.stateVersion = "@stateVersion@"; # Did you read the comment? +} diff --git a/nixos/maintainers/scripts/incus/incus-container-image.nix b/nixos/maintainers/scripts/incus/incus-container-image.nix new file mode 100644 index 000000000000..63b9353f7ee3 --- /dev/null +++ b/nixos/maintainers/scripts/incus/incus-container-image.nix @@ -0,0 +1,47 @@ +{ lib, pkgs, ... }: + +{ + imports = [ ../../../modules/virtualisation/lxc-container.nix ]; + + virtualisation.lxc.templates.nix = { + enable = true; + target = "/etc/nixos/incus.nix"; + template = ./nix.tpl; + when = [ + "create" + "copy" + ]; + }; + + # copy the config for nixos-rebuild + system.activationScripts.config = + let + config = pkgs.substituteAll { + src = ./incus-container-image-inner.nix; + stateVersion = lib.trivial.release; + }; + in + '' + if [ ! -e /etc/nixos/configuration.nix ]; then + install -m 0644 -D ${config} /etc/nixos/configuration.nix + fi + ''; + + networking = { + dhcpcd.enable = false; + useDHCP = false; + useHostResolvConf = false; + }; + + systemd.network = { + enable = true; + networks."50-eth0" = { + matchConfig.Name = "eth0"; + networkConfig = { + DHCP = "ipv4"; + IPv6AcceptRA = true; + }; + linkConfig.RequiredForOnline = "routable"; + }; + }; +} diff --git a/nixos/maintainers/scripts/incus/incus-virtual-machine-image-inner.nix b/nixos/maintainers/scripts/incus/incus-virtual-machine-image-inner.nix new file mode 100644 index 000000000000..cd176a38988f --- /dev/null +++ b/nixos/maintainers/scripts/incus/incus-virtual-machine-image-inner.nix @@ -0,0 +1,34 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ modulesPath, ... }: + +{ + imports = [ + # Include the default incus configuration. + "${modulesPath}/virtualisation/incus-virtual-machine.nix" + # Include the container-specific autogenerated configuration. + ./incus.nix + ]; + + networking = { + dhcpcd.enable = false; + useDHCP = false; + useHostResolvConf = false; + }; + + systemd.network = { + enable = true; + networks."50-enp5s0" = { + matchConfig.Name = "enp5s0"; + networkConfig = { + DHCP = "ipv4"; + IPv6AcceptRA = true; + }; + linkConfig.RequiredForOnline = "routable"; + }; + }; + + system.stateVersion = "@stateVersion@"; # Did you read the comment? +} diff --git a/nixos/maintainers/scripts/incus/incus-virtual-machine-image.nix b/nixos/maintainers/scripts/incus/incus-virtual-machine-image.nix new file mode 100644 index 000000000000..0742e7d75ac9 --- /dev/null +++ b/nixos/maintainers/scripts/incus/incus-virtual-machine-image.nix @@ -0,0 +1,48 @@ +{ lib, pkgs, ... }: + +{ + imports = [ ../../../modules/virtualisation/incus-virtual-machine.nix ]; + + virtualisation.lxc.templates.nix = { + enable = true; + target = "/etc/nixos/incus.nix"; + template = ./nix.tpl; + when = [ + "create" + "copy" + ]; + }; + + # copy the config for nixos-rebuild + system.activationScripts.config = + let + config = pkgs.substituteAll { + src = ./incus-virtual-machine-image-inner.nix; + stateVersion = lib.trivial.release; + }; + in + '' + if [ ! -e /etc/nixos/configuration.nix ]; then + install -m 0644 -D ${config} /etc/nixos/configuration.nix + fi + ''; + + # Network + networking = { + dhcpcd.enable = false; + useDHCP = false; + useHostResolvConf = false; + }; + + systemd.network = { + enable = true; + networks."50-enp5s0" = { + matchConfig.Name = "enp5s0"; + networkConfig = { + DHCP = "ipv4"; + IPv6AcceptRA = true; + }; + linkConfig.RequiredForOnline = "routable"; + }; + }; +} diff --git a/nixos/maintainers/scripts/incus/nix.tpl b/nixos/maintainers/scripts/incus/nix.tpl new file mode 100644 index 000000000000..38c2fc1ebffb --- /dev/null +++ b/nixos/maintainers/scripts/incus/nix.tpl @@ -0,0 +1,12 @@ +{ + lib, + config, + pkgs, + ... +}: + +# WARNING: THIS CONFIGURATION IS AUTOGENERATED AND WILL BE OVERWRITTEN AUTOMATICALLY + +{ + networking.hostName = "{{ container.name }}"; +} -- cgit 1.4.1