From ebda6c57eb0b079d4b7d009c7fdeea8dad78e7f0 Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Fri, 25 Oct 2024 10:39:57 +0200 Subject: [PATCH] pinwheel: Add `pants` for `work` --- hosts/pinwheel/modules/work/default.nix | 1 + hosts/pinwheel/modules/work/pants.nix | 69 +++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 hosts/pinwheel/modules/work/pants.nix diff --git a/hosts/pinwheel/modules/work/default.nix b/hosts/pinwheel/modules/work/default.nix index ad6b8e9..3c2299b 100644 --- a/hosts/pinwheel/modules/work/default.nix +++ b/hosts/pinwheel/modules/work/default.nix @@ -17,6 +17,7 @@ in }; home.packages = [ + # (pkgs.callPackage ./pants.nix { inherit (pkgs) system; }) (pkgs.callPackage ./syb-cli.nix { }) (pkgs.jetbrains.plugins.addPlugins pkgs.jetbrains.idea-ultimate [ "ideavim" ]) diff --git a/hosts/pinwheel/modules/work/pants.nix b/hosts/pinwheel/modules/work/pants.nix new file mode 100644 index 0000000..d27744c --- /dev/null +++ b/hosts/pinwheel/modules/work/pants.nix @@ -0,0 +1,69 @@ +{ + system, + pkgs, + lib, + ... +}: +let + version = "0.12.0"; + + if_let = v: p: if lib.attrsets.matchAttrs p v then v else null; + match = + v: l: builtins.elemAt (lib.lists.findFirst (x: (if_let v (builtins.elemAt x 0)) != null) null l) 1; + + package = match { platform = system; } [ + [ + { platform = "aarch64-linux"; } + { + url = "https://github.com/pantsbuild/scie-pants/releases/download/v${version}/scie-pants-linux-aarch64"; + hash = lib.fakeSha256; + } + ] + [ + { platform = "x86_64-linux"; } + { + url = "https://github.com/pantsbuild/scie-pants/releases/download/v${version}/scie-pants-linux-x86_64"; + hash = "sha256-9PjgobndxVqDTYGtw1HESrtzwzH2qE9zFwR26xtwZrM="; + } + ] + [ + { platform = "aarch64-darwin"; } + { + url = "https://github.com/pantsbuild/scie-pants/releases/download/v${version}/scie-pants-macos-aarch64"; + hash = "sha256-1Ha8GAOl7mWVunGKf7INMjar+jnLXaDEPStqE+kK3D4="; + } + ] + ]; + + unpatched = pkgs.stdenv.mkDerivation { + name = "scie-pants"; + version = version; + sourceRoot = "."; + phases = [ + "installPhase" + "patchPhase" + ]; + + src = pkgs.fetchurl package; + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + cp $src $out/bin/pants + chmod +x $out/bin/pants + + runHook postInstall + ''; + }; + + patched = pkgs.buildFHSEnv { + name = "pants"; + targetPackages = [ pkgs.python39 ]; + runScript = "${unpatched}/bin/pants"; + profile = '' + export NIX_SSL_CERT_FILE="/etc/ssl/certs/ca-certificates.crt" + export SSL_CERT_FILE="/etc/ssl/certs/ca-bundle.crt" + ''; + }; +in +if pkgs.stdenv.isDarwin then unpatched else patched