Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196{ description = "gitproxy — Gleam Git remote helper for AT Protocol PDS snapshots";
inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; systems.url = "github:nix-systems/default"; };
outputs = { self, nixpkgs, systems, ... }: let forEachSystem = nixpkgs.lib.genAttrs (import systems); in { packages = forEachSystem ( system: let pkgs = nixpkgs.legacyPackages.${system}; inherit (pkgs) lib;
gleamToml = lib.importTOML ./gleam.toml; manifestToml = lib.importTOML ./manifest.toml;
hexPackages = builtins.filter (p: p.source == "hex") manifestToml.packages;
packagesTOML = lib.concatStringsSep "\n" ( [ "[packages]" ] ++ map (p: "${p.name} = \"${p.version}\"") hexPackages );
# Self-contained store package: erlang-shipment + PATH wrappers. # No source checkout required at runtime. gitproxy = pkgs.stdenv.mkDerivation { pname = "gitproxy"; version = gleamToml.version;
src = lib.cleanSourceWith { src = ./.; filter = path: type: let base = baseNameOf path; in lib.cleanSourceFilter path type && base != "build" && base != "result" && base != ".direnv" && base != "erl_crash.dump"; };
nativeBuildInputs = [ pkgs.gleam pkgs.beamPackages.erlang pkgs.rebar3 pkgs.beamPackages.hex pkgs.rsync pkgs.makeWrapper ];
configurePhase = '' runHook preConfigure
mkdir -p build/packages cat <<EOF > build/packages/packages.toml ${packagesTOML} EOF
# Vendor Hex deps so the pure Nix build never hits the network. ${lib.concatMapStringsSep "\n" (p: '' rsync --chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -r ${ pkgs.fetchHex { pkg = p.name; version = p.version; sha256 = p.outer_checksum; } }/* build/packages/${p.name}/ '') hexPackages}
runHook postConfigure '';
buildPhase = '' runHook preBuild export REBAR_CACHE_DIR="$TMP/.rebar-cache" gleam export erlang-shipment runHook postBuild '';
installPhase = '' runHook preInstall
mkdir -p $out/{bin,lib/gitproxy} rsync --exclude=entrypoint.sh --exclude=entrypoint.ps1 \ -r build/erlang-shipment/* $out/lib/gitproxy/
# Bake -pa paths at install time (each ebin needs its own -pa). ebin_args=() for d in $out/lib/gitproxy/*/ebin; do ebin_args+=(-pa "$d") done
# Runtime wrapper: fixed store paths, works from any cwd. # GITPROXY_ROOT points at the app tree so appview finds priv/public. { echo "#!${pkgs.runtimeShell}" echo "set -eu" echo "export GITPROXY_ROOT=\"$out/lib/gitproxy/gitproxy\"" echo "exec ${pkgs.beamPackages.erlang}/bin/erl ''${ebin_args[*]} -eval \"gitproxy@@main:run(gitproxy)\" -noshell -extra \"\$@\"" } > $out/bin/gitproxy chmod +x $out/bin/gitproxy
# git is required for fast-export / fast-import in the remote helper. wrapProgram $out/bin/gitproxy \ --prefix PATH : ${lib.makeBinPath [ pkgs.git ]}
# Git looks for git-remote-<scheme> on PATH. ln -s gitproxy $out/bin/git-remote-atgit ln -s gitproxy $out/bin/git-remote-aproto
runHook postInstall '';
meta = { description = gleamToml.description; homepage = "https://tangled.org/nandi.uk/gitproxy"; license = lib.licenses.asl20; mainProgram = "gitproxy"; }; }; in { default = gitproxy; inherit gitproxy; } );
apps = forEachSystem (system: { default = { type = "app"; program = "${self.packages.${system}.gitproxy}/bin/gitproxy"; }; });
devShells = forEachSystem ( system: let pkgs = nixpkgs.legacyPackages.${system}; # Dev entrypoints: always run from the project root so git remote # helpers work when cwd is some other repo. gleamRun = pkgs.writeShellScript "gleam-run-gitproxy" '' set -eu root="''${GITPROXY_DEV_ROOT:-}" if [ -z "$root" ] || [ ! -f "$root/gleam.toml" ]; then echo "gitproxy: GITPROXY_DEV_ROOT not set (enter via nix develop from the repo)" >&2 exit 1 fi cd "$root" exec ${pkgs.gleam}/bin/gleam run -- "$@" ''; gitproxy-dev = pkgs.writeShellScriptBin "gitproxy" '' exec ${gleamRun} "$@" ''; git-remote-atgit-dev = pkgs.writeShellScriptBin "git-remote-atgit" '' exec ${gleamRun} "$@" ''; git-remote-aproto-dev = pkgs.writeShellScriptBin "git-remote-aproto" '' exec ${gleamRun} "$@" ''; in { default = pkgs.mkShell { packages = [ pkgs.gleam pkgs.beamPackages.erlang pkgs.beamPackages.rebar3 pkgs.git gitproxy-dev git-remote-atgit-dev git-remote-aproto-dev ]; shellHook = '' export GITPROXY_DEV_ROOT="$PWD" ''; }; } );
formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style); };}