grace/tpb
Tee your Paste Board
git clone https://git.gae.moe/grace/tpb
bd32f9c
main
1{ 2pkgs ? import <nixpkgs> { } , 3artifactDir , 4htmlDir , 5} : 6 7let 8version = "0.1.4" ; 9 10src = pkgs . lib . fileset . toSource { 11root = ./. ; 12fileset = pkgs . lib . fileset . unions [ 13./build.zig 14./build.zig.zon 15./src 16./LICENSE 17] ; 18} ; 19 20isDarwin = pkgs . stdenv . hostPlatform . isDarwin ; 21 22appleSdk = 23if isDarwin then 24pkgs . apple-sdk 25else 26let 27sdk = 28( import <nixpkgs> { 29config = pkgs . config // { 30allowUnsupportedSystem = true ; 31} ; 32}) . apple-sdk . override 33{ enableBootstrap = true ; } ; 34in 35sdk . overrideAttrs ( old : { 36postBuild = ( old . postBuild or "" ) + '' 37for header in ${ pkgs . lib . getDev pkgs . cups } /include/*; do 38ln -sf "$header" "usr/include/$(basename "$header")" 39done 40'' ; 41}) ; 42 43sdkRoot = " ${ appleSdk } /Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" ; 44 45targets = { 46x86_64-linux-musl = "tpb-linux-x86_64" ; 47aarch64-linux-musl = "tpb-linux-aarch64" ; 48x86_64-macos = "tpb-macos-x86_64" ; 49aarch64-macos = "tpb-macos-aarch64" ; 50} ; 51 52binaries = pkgs . stdenv . mkDerivation { 53pname = "tpb-static-binaries" ; 54inherit version src ; 55 56nativeBuildInputs = [ pkgs . zig_0_17 ] ; 57 58dontConfigure = true ; 59doCheck = false ; 60dontFixup = true ; 61 62buildPhase = '' 63runHook preBuild 64export ZIG_GLOBAL_CACHE_DIR=" $TMPDIR /zig-global-cache" 65export ZIG_LOCAL_CACHE_DIR=" $TMPDIR /zig-local-cache" 66${ pkgs . lib . concatMapStrings ( target : '' 67zig build \ 68-Dtarget= ${ target } \ 69-Doptimize=safe \ 70--prefix zig-out/ ${ target } \ 71${ pkgs . lib . optionalString ( pkgs . lib . hasSuffix "-macos" target ) ''-Dsdk=" ${ sdkRoot } "'' } 72'' ) ( builtins . attrNames targets ) } 73runHook postBuild 74'' ; 75 76installPhase = '' 77runHook preInstall 78mkdir -p$out 79${ pkgs . lib . concatMapStrings ( target : '' 80cp zig-out/ ${ target } /bin/tpb $out/ ${ targets . ${ target }} 81'' ) ( builtins . attrNames targets ) } 82runHook postInstall 83'' ; 84} ; 85in 86pkgs . writeShellScriptBin "deploy" '' 87set -euo pipefail 88 89mkdir -p${ pkgs . lib . escapeShellArg artifactDir } 90mkdir -p${ pkgs . lib . escapeShellArg htmlDir } 91 92${ pkgs . rsync } /bin/rsync -a --delete\ 93${ binaries } /\ 94${ pkgs . lib . escapeShellArg ( artifactDir + "/" ) } 95''