2017-02-13 05:01:28 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.ssm-agent;
|
|
|
|
|
|
|
|
# The SSM agent doesn't pay attention to our /etc/os-release yet, and the lsb-release tool
|
|
|
|
# in nixpkgs doesn't seem to work properly on NixOS, so let's just fake the two fields SSM
|
|
|
|
# looks for. See https://github.com/aws/amazon-ssm-agent/issues/38 for upstream fix.
|
|
|
|
fake-lsb-release = pkgs.writeScriptBin "lsb_release" ''
|
2018-03-01 20:38:53 +01:00
|
|
|
#!${pkgs.runtimeShell}
|
2017-02-13 05:01:28 +01:00
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
-i) echo "nixos";;
|
2017-04-01 02:00:00 +02:00
|
|
|
-r) echo "${config.system.nixos.version}";;
|
2017-02-13 05:01:28 +01:00
|
|
|
esac
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
options.services.ssm-agent = {
|
|
|
|
enable = mkEnableOption "AWS SSM agent";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = "The SSM agent package to use";
|
|
|
|
default = pkgs.ssm-agent;
|
2017-03-07 14:01:50 +01:00
|
|
|
defaultText = "pkgs.ssm-agent";
|
2017-02-13 05:01:28 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.ssm-agent = {
|
|
|
|
inherit (cfg.package.meta) description;
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
path = [ fake-lsb-release ];
|
|
|
|
serviceConfig = {
|
2020-04-28 03:50:34 +02:00
|
|
|
ExecStart = "${cfg.package}/bin/agent";
|
2017-02-13 05:01:28 +01:00
|
|
|
KillMode = "process";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "15min";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|