about summary refs log tree commit diff
path: root/nixos/maintainers/scripts
diff options
context:
space:
mode:
authorAdam Stephens2024-08-10 12:40:16 -0400
committerAdam Stephens2024-08-10 13:23:36 -0400
commit094f2b6c9d87da6348e2517936a3ad907c82d1cf (patch)
treedb02a5f7ef5c5891c2f346ccfd5981fb145de21f /nixos/maintainers/scripts
parent293c17926d47fb66e8a01267c2e698ab40dc53a6 (diff)
nixos/incus: add incus-only vm and container images
Diffstat (limited to 'nixos/maintainers/scripts')
-rw-r--r--nixos/maintainers/scripts/incus/incus-container-image-inner.nix34
-rw-r--r--nixos/maintainers/scripts/incus/incus-container-image.nix47
-rw-r--r--nixos/maintainers/scripts/incus/incus-virtual-machine-image-inner.nix34
-rw-r--r--nixos/maintainers/scripts/incus/incus-virtual-machine-image.nix48
-rw-r--r--nixos/maintainers/scripts/incus/nix.tpl12
5 files changed, 175 insertions, 0 deletions
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 }}";
+}