Skip to content

Instantly share code, notes, and snippets.

@schickling
Created August 18, 2024 09:01
Show Gist options
  • Save schickling/2c947b35a11d08b33c2411709a2de8c9 to your computer and use it in GitHub Desktop.
Save schickling/2c947b35a11d08b33c2411709a2de8c9 to your computer and use it in GitHub Desktop.
{ lib, stdenv, fetchurl, unzip }:
let
# https://docs.dagger.io/install
version = "0.12.5"; # Replace with the actual version you want to install
system = stdenv.hostPlatform.system;
# Map Nix system to Dagger's OS and architecture naming
systemMap = {
"x86_64-linux" = { os = "linux_amd64"; sha256 = ""; };
"aarch64-linux" = { os = "linux_arm64"; sha256 = ""; };
"x86_64-darwin" = { os = "darwin_amd64"; sha256 = ""; };
"aarch64-darwin" = { os = "darwin_arm64"; sha256 = "sha256-kE/7BL/xxRKR+rKpyjZF7IIPuwUNjjhzqUwoY0GjrFw="; };
};
selectedSystem = systemMap.${system} or (throw "Unsupported system: ${system}");
# Construct the filename based on version and system
filename = "dagger_v${version}_${selectedSystem.os}.tar.gz";
in
stdenv.mkDerivation rec {
pname = "dagger";
inherit version;
src = fetchurl {
url = "https://dl.dagger.io/dagger/releases/${version}/${filename}";
sha256 = selectedSystem.sha256;
};
nativeBuildInputs = [ unzip ];
unpackPhase = ''
if [[ "${filename}" == *.zip ]]; then
unzip $src
else
tar xzf $src
fi
'';
installPhase = ''
install -D dagger $out/bin/dagger
'';
postInstall = ''
# Generate shell completions
mkdir -p $out/share/bash-completion/completions
$out/bin/dagger completion bash > $out/share/bash-completion/completions/dagger
mkdir -p $out/share/zsh/site-functions
$out/bin/dagger completion zsh > $out/share/zsh/site-functions/_dagger
mkdir -p $out/share/fish/vendor_completions.d
$out/bin/dagger completion fish > $out/share/fish/vendor_completions.d/dagger.fish
'';
meta = with lib; {
description = "A portable devkit for CI/CD pipelines";
homepage = "https://dagger.io/";
license = licenses.asl20;
maintainers = with maintainers; [ /* Add maintainers here */ ];
platforms = builtins.attrNames systemMap;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment