diff --git a/nix/lib/config/options.nix b/nix/lib/config/options.nix index aa2fc4d..197d9bc 100644 --- a/nix/lib/config/options.nix +++ b/nix/lib/config/options.nix @@ -138,6 +138,13 @@ let }; hostOpts = { name, ... }: { options = { + prebuilt = mkOption { + type = types.bool; + default = false; + description = '' + Include the container system in the server's `build-container` script. + ''; + }; role = mkOption { type = types.enum [ "ap" "switch" "server" "container" "client" ]; default = "client"; diff --git a/nix/nixos-module/server/lxc-containers.nix b/nix/nixos-module/server/lxc-containers.nix index 256306d..a973812 100644 --- a/nix/nixos-module/server/lxc-containers.nix +++ b/nix/nixos-module/server/lxc-containers.nix @@ -70,9 +70,27 @@ let mkdir -p /nix/var/nix/gcroots/lxc for c in $@; do - echo Building $c - nix build -o /nix/var/nix/gcroots/lxc/$c zentralwerk-network#$c-rootfs - SYSTEM=$(readlink /nix/var/nix/gcroots/lxc/$c) + unset SYSTEM + + case "$c" in + ${builtins.concatStringsSep "\n" ( + map (ctName: '' + ${ctName}) + echo Using prebuilt system for container $c + SYSTEM=${self.packages.x86_64-linux."${ctName}-rootfs"} + ;; + '') ( + builtins.attrNames ( + lib.filterAttrs (_: { prebuilt, ... }: prebuilt) + containers + )) + )} + *) + echo Building $c + nix build -o /nix/var/nix/gcroots/lxc/$c zentralwerk-network#$c-rootfs + SYSTEM=$(readlink /nix/var/nix/gcroots/lxc/$c) + ;; + esac echo Installing $c for d in \