3
0
Fork 0
forked from mirrors/nixpkgs

buildkite-agent: 2.1.13 -> 2.6.6

Build the package from source

Re-organise the module a bit to allow custom version of the package
This commit is contained in:
zimbatm 2017-10-20 18:16:05 +01:00 committed by Domen Kožar
parent 525e121626
commit 96b339fbc9
2 changed files with 65 additions and 36 deletions

View file

@ -9,9 +9,8 @@ let
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"
hooks-path="${cfg.package}/share/hooks"
build-path="${cfg.dataDir}"
'';
in
@ -20,6 +19,26 @@ in
services.buildkite-agent = {
enable = mkEnableOption "buildkite-agent";
package = mkOption {
default = pkgs.buildkite-agent;
defaultText = "pkgs.buildkite-agent";
description = "Which buildkite-agent derivation to use";
type = types.package;
};
dataDir = mkOption {
default = "/var/lib/buildkite-agent";
description = "The workdir for the agent";
type = types.str;
};
runtimePackages = mkOption {
default = [ pkgs.nix ];
defaultText = "[ pkgs.nix ]";
description = "Add programs to the buildkite-agent environment";
type = types.listOf types.package;
};
token = mkOption {
type = types.str;
description = ''
@ -62,27 +81,31 @@ in
config = mkIf config.services.buildkite-agent.enable {
users.extraUsers.buildkite-agent =
{ name = "buildkite-agent";
home = "/var/lib/buildkite-agent";
home = cfg.dataDir;
createHome = true;
description = "Buildkite agent user";
};
environment.systemPackages = [ pkgs.buildkite-agent ];
environment.systemPackages = [ cfg.package ];
systemd.services.buildkite-agent =
{ description = "Buildkite Agent";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
environment.HOME = "/var/lib/buildkite-agent";
path = cfg.runtimePackages;
environment = config.networking.proxy.envVars // {
HOME = cfg.dataDir;
NIX_REMOTE = "daemon";
};
preStart = ''
${pkgs.coreutils}/bin/mkdir -m 0700 -p /var/lib/buildkite-agent/.ssh
${pkgs.coreutils}/bin/mkdir -m 0700 -p ${cfg.dataDir}/.ssh
echo "${cfg.openssh.privateKey}" > /var/lib/buildkite-agent/.ssh/id_rsa
${pkgs.coreutils}/bin/chmod 600 /var/lib/buildkite-agent/.ssh/id_rsa
echo "${cfg.openssh.privateKey}" > ${cfg.dataDir}/.ssh/id_rsa
${pkgs.coreutils}/bin/chmod 600 ${cfg.dataDir}/.ssh/id_rsa
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
'';
echo "${cfg.openssh.publicKey}" > ${cfg.dataDir}/.ssh/id_rsa.pub
${pkgs.coreutils}/bin/chmod 600 ${cfg.dataDir}/.ssh/id_rsa.pub
'';
serviceConfig =
{ ExecStart = "${pkgs.buildkite-agent}/bin/buildkite-agent start --config ${configFile}";

View file

@ -1,32 +1,38 @@
{ stdenv, fetchurl, makeWrapper, coreutils, git, openssh, bash, gnused, gnugrep }:
stdenv.mkDerivation rec {
version = "2.1.13";
{ stdenv, buildGoPackage, fetchFromGitHub, makeWrapper, coreutils, git, openssh, bash, gnused, gnugrep }:
let
version = "2.6.6";
goPackagePath = "github.com/buildkite/agent";
in
buildGoPackage {
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 = "bd40c2ba37b3b54b875241a32b62190a4cf4c15e2513c573f1626a3ca35c8657";
inherit goPackagePath;
src = fetchFromGitHub {
owner = "buildkite";
repo = "agent";
rev = "v${version}";
sha256 = "0rpi63mfzlm39517l4xjcka3m4dnfjzwvpi0i1rpf1z2288cnkyx";
};
nativeBuildInputs = [ makeWrapper ];
sourceRoot = ".";
installPhase = ''
install -Dt "$out/bin/" buildkite-agent
mkdir -p $out/share
mv hooks bootstrap.sh $out/share/
postInstall = ''
# Install bootstrap.sh
mkdir -p $bin/libexec/buildkite-agent
cp $NIX_BUILD_TOP/go/src/${goPackagePath}/templates/bootstrap.sh $bin/libexec/buildkite-agent
sed -e "s|#!/bin/bash|#!${bash}/bin/bash|g" -i $bin/libexec/buildkite-agent/bootstrap.sh
# Fix binary name
mv $bin/bin/{agent,buildkite-agent}
# These are runtime dependencies
wrapProgram $bin/bin/buildkite-agent \
--prefix PATH : '${stdenv.lib.makeBinPath [ openssh git coreutils gnused gnugrep ]}' \
--set BUILDKITE_BOOTSTRAP_SCRIPT_PATH $bin/libexec/buildkite-agent/bootstrap.sh
'';
postFixup = ''
substituteInPlace $out/share/bootstrap.sh \
--replace "#!/bin/bash" "#!$(type -P bash)"
wrapProgram $out/bin/buildkite-agent \
--set PATH '"${stdenv.lib.makeBinPath [ openssh git coreutils gnused gnugrep ]}:$PATH"'
'';
meta = {
meta = with stdenv.lib; {
description = "Build runner for buildkite.com";
longDescription = ''
The buildkite-agent is a small, reliable, and cross-platform build runner
@ -36,8 +42,8 @@ stdenv.mkDerivation rec {
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;
license = licenses.mit;
maintainers = with maintainers; [ pawelpacana zimbatm ];
platforms = platforms.linux;
};
}