From 0a5d9a809b105c273ad80e94bd8a1b3f106d4b09 Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Mon, 4 Apr 2022 18:15:55 +0100 Subject: [PATCH] nixos/containers: Restart systemd-nspawn@ unit when .nspawn file changes --- nixos/modules/containers.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nixos/modules/containers.nix b/nixos/modules/containers.nix index 1157d10..e989c0e 100644 --- a/nixos/modules/containers.nix +++ b/nixos/modules/containers.nix @@ -1,7 +1,8 @@ { lib, pkgs, options, config, systems, ... }: let - inherit (builtins) attrNames attrValues mapAttrs all; - inherit (lib) groupBy' flatten mapAttrsToList optionalString optional concatMapStringsSep filterAttrs mkOption mkDefault mkIf mkMerge mkAliasDefinitions mkVMOverride mkAfter; + inherit (builtins) attrNames attrValues all hashString toJSON; + inherit (lib) + groupBy' mapAttrsToList optionalString optional concatMapStringsSep filterAttrs mkOption mkDefault mkIf mkMerge; inherit (lib.my) mkOpt' mkBoolOpt' attrsToNVList; cfg = config.my.containers; @@ -169,6 +170,9 @@ in services."systemd-nspawn@${n}" = { # systemd.nspawn units can't set the root directory directly, but /run/machines/${n} is one of the search paths environment.root = "/run/machines/${n}"; + restartTriggers = [ + (''${n}.nspawn:${hashString "sha256" (toJSON config.systemd.nspawn."${n}")}'') + ]; preStart = let sysProfile = "${ctrProfiles n}/system";