nixos/containers: Restart systemd-nspawn@ unit when .nspawn file changes

This commit is contained in:
Jack O'Sullivan 2022-04-04 18:15:55 +01:00
parent be3173c63c
commit 0a5d9a809b

View File

@ -1,7 +1,8 @@
{ lib, pkgs, options, config, systems, ... }: { lib, pkgs, options, config, systems, ... }:
let let
inherit (builtins) attrNames attrValues mapAttrs all; inherit (builtins) attrNames attrValues all hashString toJSON;
inherit (lib) groupBy' flatten mapAttrsToList optionalString optional concatMapStringsSep filterAttrs mkOption mkDefault mkIf mkMerge mkAliasDefinitions mkVMOverride mkAfter; inherit (lib)
groupBy' mapAttrsToList optionalString optional concatMapStringsSep filterAttrs mkOption mkDefault mkIf mkMerge;
inherit (lib.my) mkOpt' mkBoolOpt' attrsToNVList; inherit (lib.my) mkOpt' mkBoolOpt' attrsToNVList;
cfg = config.my.containers; cfg = config.my.containers;
@ -169,6 +170,9 @@ in
services."systemd-nspawn@${n}" = { services."systemd-nspawn@${n}" = {
# systemd.nspawn units can't set the root directory directly, but /run/machines/${n} is one of the search paths # 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}"; environment.root = "/run/machines/${n}";
restartTriggers = [
(''${n}.nspawn:${hashString "sha256" (toJSON config.systemd.nspawn."${n}")}'')
];
preStart = preStart =
let let
sysProfile = "${ctrProfiles n}/system"; sysProfile = "${ctrProfiles n}/system";