diff --git a/nix/nixos-module/server/lxc-containers.nix b/nix/nixos-module/server/lxc-containers.nix index 748397f..0678e04 100644 --- a/nix/nixos-module/server/lxc-containers.nix +++ b/nix/nixos-module/server/lxc-containers.nix @@ -123,4 +123,22 @@ in }) { "lxc/common.conf".source = "${pkgs.lxc}/share/lxc/config/common.conf"; } (builtins.attrNames containers); + + systemd.targets.lxc-containers = { + wantedBy = [ "multi-user.target" ]; + wants = map (ctName: "lxc@${ctName}.service") (builtins.attrNames containers); + }; + systemd.services."lxc@" = { + description = "LXC container '%i'"; + wants = [ "systemd-networkd.service" ]; + serviceConfig = { + Type = "simple"; + ExecStart = "${pkgs.lxc}/bin/lxc-start -F -C -n %i"; + ExecStop = "${pkgs.lxc}/bin/lxc-stop -n %i"; + KillMode = "mixed"; + OOMPolicy = "kill"; + Restart = "always"; + RestartSec = "5s"; + }; + }; }