summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-02-07 12:44:40 +0530
committersinanmohd <sinan@sinanmohd.com>2024-02-07 13:20:03 +0530
commit08a6d64d9d71489196838ee63ae52a92f0147508 (patch)
treec534946fb8a3b29acafe687047f9cab8908481c4
parent467dc80d65f33cd1d5d2515c84c9ad0297151315 (diff)
lia/lxc: init
-rw-r--r--hosts/lia/configuration.nix1
-rw-r--r--hosts/lia/modules/lxc.nix41
2 files changed, 42 insertions, 0 deletions
diff --git a/hosts/lia/configuration.nix b/hosts/lia/configuration.nix
index 1b5a926..37ae805 100644
--- a/hosts/lia/configuration.nix
+++ b/hosts/lia/configuration.nix
@@ -6,6 +6,7 @@
../../common.nix
./modules/network
./modules/users.nix
+ ./modules/lxc.nix
];
}
diff --git a/hosts/lia/modules/lxc.nix b/hosts/lia/modules/lxc.nix
new file mode 100644
index 0000000..259c316
--- /dev/null
+++ b/hosts/lia/modules/lxc.nix
@@ -0,0 +1,41 @@
+{ pkgs, ... }: let
+ container = {
+ name = "ubu";
+ distro = "ubuntu";
+ release = "jammy";
+ };
+
+ bridge = "lan";
+in {
+ virtualisation.lxc.enable = true;
+
+ environment.systemPackages = with pkgs; [ wget ];
+ systemd.services."lxc-${container.name}-provision" = {
+ description = "auto provision ${container.name} lxc container";
+ wantedBy = [ "multi-user.target" ];
+ after = [ "network-online.target" ];
+ wants = [ "network-online.target" ];
+ stopIfChanged = false;
+
+ serviceConfig = {
+ Type = "oneshot";
+ RemainAfterExit = true;
+ };
+
+ path = with pkgs; [ wget lxc util-linux gnutar xz gawk ];
+ script = ''
+ if ! lxc-ls | grep -q ${container.name}; then
+ lxc-create -n ${container.name} -t download -- \
+ --arch amd64 \
+ --release ${container.release} \
+ --dist ${container.distro}
+
+ sed 's/lxcbr0/${bridge}/g' -i /var/lib/lxc/${container.name}/config
+ fi
+
+ lxc-start -n ${container.name}
+ '';
+
+ preStop = "lxc-stop --name ${container.name}";
+ };
+}