nixos-config/modules/nixos/services/comin.nix

62 lines
1.5 KiB
Nix

{
config,
inputs,
pkgs,
lib,
...
}:
let
cfg = config.custom.services.comin;
postDeploymentScript =
pkgs.writeShellApplication {
name = "comin-post-deployment";
runtimeInputs = [ pkgs.git ];
text = ''
if [[ "$COMIN_STATUS" != "done" ]]; then
echo "Deployment not successful (status: $COMIN_STATUS), skipping branch update"
exit 0
fi
token=$(cat "''${CREDENTIALS_DIRECTORY}/git-push-token")
repo_url="https://x-access-token:$token@github.com/SebastianStork/nixos-config.git"
git push --force "$repo_url" "$COMIN_GIT_SHA:refs/heads/deployed/$COMIN_HOSTNAME"
echo "Updated deployed/$COMIN_HOSTNAME to $COMIN_GIT_SHA"
'';
}
|> lib.getExe;
in
{
imports = [ inputs.comin.nixosModules.comin ];
options.custom.services.comin = {
enable = lib.mkEnableOption "";
metricsPort = lib.mkOption {
type = lib.types.port;
default = 4243;
};
};
config = lib.mkIf cfg.enable {
sops.secrets."git/push-token" = { };
systemd.services.comin.serviceConfig.LoadCredential = "git-push-token:${
config.sops.secrets."git/push-token".path
}";
services.comin = {
enable = true;
remotes = lib.singleton {
name = "origin";
url = "https://github.com/SebastianStork/nixos-config.git";
branches.main.name = "deploy";
};
exporter = {
listen_address = "127.0.0.1";
port = cfg.metricsPort;
};
postDeploymentCommand = postDeploymentScript;
};
};
}