nixos/ssm-agent: conf files written to /etc

ssm-agent expects files in /etc/amazon/ssm. The pkg substitutes a location in
the nix store for those default files, but if we ever want to adjust this
configuration on NixOS, we'd need the ability to modify that file.

This change to the nixos module writes copies of the default files from the nix
store to /etc/amazon/ssm. Future versions can add config, but right now this
would allow users to at least write out a text value to
environment.etc."amazon/ssm/amazon-ssm-agent.json".text to provide
their own config.
This commit is contained in:
Joe DeVivo 2021-05-08 16:03:38 -07:00 committed by Cole Helbling
parent 27b4fd19ed
commit bf92d0ec37
2 changed files with 15 additions and 7 deletions

View file

@ -22,8 +22,8 @@ in {
package = mkOption { package = mkOption {
type = types.path; type = types.path;
description = "The SSM agent package to use"; description = "The SSM agent package to use";
default = pkgs.ssm-agent; default = pkgs.ssm-agent.override { overrideEtc = false; };
defaultText = "pkgs.ssm-agent"; defaultText = "pkgs.ssm-agent.override { overrideEtc = false; }";
}; };
}; };
@ -37,8 +37,10 @@ in {
serviceConfig = { serviceConfig = {
ExecStart = "${cfg.package}/bin/amazon-ssm-agent"; ExecStart = "${cfg.package}/bin/amazon-ssm-agent";
KillMode = "process"; KillMode = "process";
Restart = "on-failure"; # We want this restating pretty frequently. It could be our only means
RestartSec = "15min"; # of accessing the instance.
Restart = "always";
RestartSec = "1min";
}; };
}; };
@ -62,5 +64,10 @@ in {
isNormalUser = true; isNormalUser = true;
group = "ssm-user"; group = "ssm-user";
}; };
environment.etc."amazon/ssm/seelog.xml".source = "${cfg.package}/seelog.xml.template";
environment.etc."amazon/ssm/amazon-ssm-agent.json".source = "${cfg.package}/etc/amazon/ssm/amazon-ssm-agent.json.template";
}; };
} }

View file

@ -8,6 +8,7 @@
, dmidecode , dmidecode
, util-linux , util-linux
, bashInteractive , bashInteractive
, overrideEtc ? true
}: }:
let let
@ -63,10 +64,10 @@ buildGoPackage rec {
substituteInPlace agent/session/shell/shell_unix.go \ substituteInPlace agent/session/shell/shell_unix.go \
--replace '"script"' '"${util-linux}/bin/script"' --replace '"script"' '"${util-linux}/bin/script"'
substituteInPlace agent/appconfig/constants_unix.go \
--replace '"/etc/amazon/ssm/"' '"${placeholder "out"}/etc/amazon/ssm/"'
echo "${version}" > VERSION echo "${version}" > VERSION
'' + lib.optionalString overrideEtc ''
substituteInPlace agent/appconfig/constants_unix.go \
--replace '"/etc/amazon/ssm/"' '"${placeholder "out"}/etc/amazon/ssm/"'
''; '';
preBuild = '' preBuild = ''