nixpkgs/nixos/modules/services/misc/ssm-agent.nix

48 lines
1.3 KiB
Nix
Raw Normal View History

2017-02-13 04:01:28 +00: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" ''
#!${pkgs.runtimeShell}
2017-02-13 04:01:28 +00:00
case "$1" in
-i) echo "nixos";;
-r) echo "${config.system.nixos.version}";;
2017-02-13 04:01:28 +00: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;
defaultText = "pkgs.ssm-agent";
2017-02-13 04:01:28 +00:00
};
};
config = mkIf cfg.enable {
systemd.services.ssm-agent = {
2020-06-26 11:15:08 +01:00
users.extraUsers.ssm-user = {};
2017-02-13 04:01:28 +00:00
inherit (cfg.package.meta) description;
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
2020-06-26 11:15:08 +01:00
path = [ fake-lsb-release pkgs.coreutils ];
2017-02-13 04:01:28 +00:00
serviceConfig = {
2020-06-26 11:15:08 +01:00
ExecStart = "${cfg.package}/bin/amazon-ssm-agent";
2017-02-13 04:01:28 +00:00
KillMode = "process";
Restart = "on-failure";
RestartSec = "15min";
};
};
};
}