* nixos module included * install compiled binary * only one platform now * limited config options * relies on providing ssh keys for agentwip/yesman
parent
02a1408d9c
commit
d2b58dd39a
@ -0,0 +1,100 @@ |
||||
{ config, lib, pkgs, ... }: |
||||
|
||||
with lib; |
||||
|
||||
let |
||||
cfg = config.services.buildkite-agent; |
||||
configFile = pkgs.writeText "buildkite-agent.cfg" |
||||
'' |
||||
token="${cfg.token}" |
||||
name="${cfg.name}" |
||||
meta-data="${cfg.meta-data}" |
||||
hooks-path="${pkgs.buildkite-agent}/share/hooks" |
||||
build-path="/var/lib/buildkite-agent/builds" |
||||
bootstrap-script="${pkgs.buildkite-agent}/share/bootstrap.sh" |
||||
''; |
||||
in |
||||
|
||||
{ |
||||
options = { |
||||
services.buildkite-agent = { |
||||
enable = mkEnableOption "buildkite-agent"; |
||||
|
||||
token = mkOption { |
||||
type = types.str; |
||||
description = '' |
||||
The token from your Buildkite "Agents" page. |
||||
''; |
||||
}; |
||||
|
||||
name = mkOption { |
||||
type = types.str; |
||||
description = '' |
||||
The name of the agent. |
||||
''; |
||||
}; |
||||
|
||||
meta-data = mkOption { |
||||
type = types.str; |
||||
default = ""; |
||||
description = '' |
||||
Meta data for the agent. |
||||
''; |
||||
}; |
||||
|
||||
openssh = |
||||
{ privateKey = mkOption { |
||||
type = types.str; |
||||
description = '' |
||||
Private agent key. |
||||
''; |
||||
}; |
||||
publicKey = mkOption { |
||||
type = types.str; |
||||
description = '' |
||||
Public agent key. |
||||
''; |
||||
}; |
||||
}; |
||||
}; |
||||
}; |
||||
|
||||
config = mkIf config.services.buildkite-agent.enable { |
||||
users.extraUsers.buildkite-agent = |
||||
{ name = "buildkite-agent"; |
||||
home = "/var/lib/buildkite-agent"; |
||||
createHome = true; |
||||
description = "Buildkite agent user"; |
||||
}; |
||||
|
||||
environment.systemPackages = [ pkgs.buildkite-agent ]; |
||||
|
||||
systemd.services.buildkite-agent = |
||||
{ description = "Buildkite Agent"; |
||||
wantedBy = [ "multi-user.target" ]; |
||||
after = [ "network.target" ]; |
||||
environment.HOME = "/var/lib/buildkite-agent"; |
||||
preStart = '' |
||||
${pkgs.coreutils}/bin/mkdir -m 0700 -p /var/lib/buildkite-agent/.ssh |
||||
|
||||
if ! [ -f /var/lib/buildkite-agent/.ssh/id_rsa ]; then |
||||
echo "${cfg.openssh.privateKey}" > /var/lib/buildkite-agent/.ssh/id_rsa |
||||
${pkgs.coreutils}/bin/chmod 600 /var/lib/buildkite-agent/.ssh/id_rsa |
||||
fi |
||||
|
||||
if ! [ -f /var/lib/buildkite-agent/.ssh/id_rsa.pub ]; then |
||||
echo "${cfg.openssh.publicKey}" > /var/lib/buildkite-agent/.ssh/id_rsa.pub |
||||
${pkgs.coreutils}/bin/chmod 600 /var/lib/buildkite-agent/.ssh/id_rsa.pub |
||||
fi |
||||
''; |
||||
|
||||
serviceConfig = |
||||
{ ExecStart = "${pkgs.buildkite-agent}/bin/buildkite-agent start --config ${configFile}"; |
||||
User = "buildkite-agent"; |
||||
RestartSec = 5; |
||||
Restart = "on-failure"; |
||||
TimeoutSec = 10; |
||||
}; |
||||
}; |
||||
}; |
||||
} |
@ -0,0 +1,43 @@ |
||||
{ stdenv, fetchurl, makeWrapper, coreutils, git, openssh, bash, gnused, gnugrep }: |
||||
|
||||
stdenv.mkDerivation rec { |
||||
version = "2.1.8"; |
||||
name = "buildkite-agent-${version}"; |
||||
dontBuild = true; |
||||
|
||||
src = fetchurl { |
||||
url = "https://github.com/buildkite/agent/releases/download/v${version}/buildkite-agent-linux-386-${version}.tar.gz"; |
||||
sha256 = "f54ca7da4379180700f5038779a7cbb1cef31d49f4a06c42702d68c34387c242"; |
||||
}; |
||||
|
||||
nativeBuildInputs = [ makeWrapper ]; |
||||
sourceRoot = "."; |
||||
installPhase = '' |
||||
install -Dt "$out/bin/" buildkite-agent |
||||
|
||||
mkdir -p $out/share |
||||
mv hooks bootstrap.sh $out/share/ |
||||
''; |
||||
|
||||
postFixup = '' |
||||
substituteInPlace $out/share/bootstrap.sh \ |
||||
--replace "#!/bin/bash" "#!$(type -P bash)" |
||||
wrapProgram $out/bin/buildkite-agent \ |
||||
--set PATH '"${openssh}/bin/:${git}/bin:${coreutils}/bin:${gnused}/bin:${gnugrep}/bin:$PATH"' |
||||
''; |
||||
|
||||
meta = { |
||||
description = "Build runner for buildkite.com"; |
||||
longDescription = '' |
||||
The buildkite-agent is a small, reliable, and cross-platform build runner |
||||
that makes it easy to run automated builds on your own infrastructure. |
||||
It’s main responsibilities are polling buildkite.com for work, running |
||||
build jobs, reporting back the status code and output log of the job, |
||||
and uploading the job's artifacts. |
||||
''; |
||||
homepage = https://buildkite.com/docs/agent; |
||||
license = stdenv.lib.licenses.mit; |
||||
maintainers = [ stdenv.lib.maintainers.pawelpacana ]; |
||||
platforms = stdenv.lib.platforms.linux; |
||||
}; |
||||
} |
Loading…
Reference in new issue