From 63bef27fe89335d41f0b7c7a24f2f61cd469fc7e Mon Sep 17 00:00:00 2001 From: Harry Miller Date: Mon, 6 Jul 2026 22:39:37 -0700 Subject: [PATCH] feat(nix): expose packages as an overlay for downstream override (#3910) Restructure the nix packaging so downstream consumers can use the standard `callPackage` `.override` pattern (e.g. swap vendorHash, buildGoModule, or other inputs) and consume beads with their own nixpkgs version: final: prev: { beads-unwrapped = prev.beads-unwrapped.override (prevArgs: { buildGoModule = args: prevArgs.buildGoModule (args // { vendorHash = "..."; }); }); } Changes: - Add overlay.nix exposing `beads-unwrapped` (the buildGoModule output) and `beads` (the wrapper with shell completions baked in plus per-shell completion passthru attrs). - default.nix: drop the `self` flake-ref input and use `src = ./.;` so the package is consumable via the overlay outside the flake context. - flake.nix: expose `overlays.default` and apply the overlay to the nixpkgs instance used for `packages` / `devShells`. - packages.nix: thin wrapper that pulls outputs from the overlayed package set. - nix-build CI: include overlay.nix and packages.nix in the path filter so overlay-only changes still trigger builds. This is a focused overlay-only follow-up to #3422 against current main (post-#3491). The ICU / version / env-var rearrangements from the original PR are intentionally omitted because they no longer apply: ICU is gone (`gms_pure_go`), `proxyVendor = true` is in place, and the env plumbing has been reshaped upstream. Co-authored-by: Dylan Johnston Co-authored-by: Cursor Co-authored-by: matt wilkie Co-authored-by: Claude Fable 5 --- .github/workflows/nix-build.yml | 4 ++ flake.nix | 26 ++++++++----- overlay.nix | 68 +++++++++++++++++++++++++++++++++ packages.nix | 62 ++++-------------------------- 4 files changed, 95 insertions(+), 65 deletions(-) create mode 100644 overlay.nix diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index 6d4253a59..03e618655 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -8,6 +8,8 @@ on: - 'default.nix' - 'flake.nix' - 'flake.lock' + - 'overlay.nix' + - 'packages.nix' push: branches: [main] paths: @@ -16,6 +18,8 @@ on: - 'default.nix' - 'flake.nix' - 'flake.lock' + - 'overlay.nix' + - 'packages.nix' workflow_dispatch: env: diff --git a/flake.nix b/flake.nix index a4ff663c4..6d93dc07a 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,7 @@ { self, nixpkgs, + ... }: let systems = [ @@ -18,22 +19,27 @@ "x86_64-linux" ]; + overlay = import ./overlay.nix self; + forAllSystems = f: nixpkgs.lib.genAttrs systems ( system: - f { - pkgs = import nixpkgs { + f ( + import nixpkgs { inherit system; - }; - inherit system self; - } + overlays = [ overlay ]; + } + ) ); - in rec { - packages = forAllSystems (args: import ./packages.nix args); + in + { + overlays.default = overlay; - apps = forAllSystems ( - { self, system, ... }: + packages = forAllSystems (import ./packages.nix); + + apps = nixpkgs.lib.genAttrs systems ( + system: rec { bd = { type = "app"; @@ -44,7 +50,7 @@ ); devShells = forAllSystems ( - { pkgs, ... }: + pkgs: { default = pkgs.mkShell { buildInputs = with pkgs; [ diff --git a/overlay.nix b/overlay.nix new file mode 100644 index 000000000..d929e3bed --- /dev/null +++ b/overlay.nix @@ -0,0 +1,68 @@ +# Curried on the flake's `self` so default.nix's `src = self;` keeps working +# outside the `pkgs.callPackage` auto-argument machinery (callPackage cannot +# supply a flake output on its own). flake.nix applies this as +# `import ./overlay.nix self`. +self: final: prev: { + # Unwrapped Go build of the bd binary. Exposed so downstream consumers can + # override inputs (vendorHash, buildGoModule, etc.) via the standard + # callPackage `.override` pattern, e.g. + # + # final: prev: { + # beads-unwrapped = prev.beads-unwrapped.override (prevArgs: { + # buildGoModule = args: + # prevArgs.buildGoModule (args // { vendorHash = "..."; }); + # }); + # } + beads-unwrapped = final.callPackage ./default.nix { + inherit self; + buildGoModule = final.buildGo126Module; + }; + + # Wrap the unwrapped binary with shell completions and a `beads` alias. + beads = final.stdenv.mkDerivation { + pname = "beads"; + version = final.beads-unwrapped.version; + + phases = [ "installPhase" ]; + + env.BD_DISABLE_METRICS = "1"; + env.BD_DISABLE_EVENT_FLUSH = "1"; + + installPhase = '' + mkdir -p $out/bin + cp ${final.beads-unwrapped}/bin/bd $out/bin/bd + + # Create 'beads' alias symlink + ln -s bd $out/bin/beads + + # Generate shell completions + mkdir -p $out/share/fish/vendor_completions.d + mkdir -p $out/share/bash-completion/completions + mkdir -p $out/share/zsh/site-functions + + $out/bin/bd completion fish > $out/share/fish/vendor_completions.d/bd.fish + $out/bin/bd completion bash > $out/share/bash-completion/completions/bd + $out/bin/bd completion zsh > $out/share/zsh/site-functions/_bd + ''; + + meta = final.beads-unwrapped.meta; + + passthru = { + # Per-shell completion outputs for users who only want one shell. + fish-completions = final.runCommand "bd-fish-completions" { } '' + mkdir -p $out/share/fish/vendor_completions.d + ln -s ${final.beads}/share/fish/vendor_completions.d/bd.fish $out/share/fish/vendor_completions.d/bd.fish + ''; + + bash-completions = final.runCommand "bd-bash-completions" { } '' + mkdir -p $out/share/bash-completion/completions + ln -s ${final.beads}/share/bash-completion/completions/bd $out/share/bash-completion/completions/bd + ''; + + zsh-completions = final.runCommand "bd-zsh-completions" { } '' + mkdir -p $out/share/zsh/site-functions + ln -s ${final.beads}/share/zsh/site-functions/_bd $out/share/zsh/site-functions/_bd + ''; + }; + }; +} diff --git a/packages.nix b/packages.nix index 3e1cad2c8..c9c0d68b7 100644 --- a/packages.nix +++ b/packages.nix @@ -1,57 +1,9 @@ -{ pkgs, self, ... }: -let - bdBase = pkgs.callPackage ./default.nix { - inherit self; - buildGoModule = pkgs.buildGo126Module; - }; +pkgs: { + default = pkgs.beads; + bd = pkgs.beads; - # Wrap the base package with shell completions baked in - bd = pkgs.stdenv.mkDerivation { - pname = "beads"; - version = bdBase.version; - - phases = [ "installPhase" ]; - - env.BD_DISABLE_METRICS = "1"; - env.BD_DISABLE_EVENT_FLUSH = "1"; - - installPhase = '' - mkdir -p $out/bin - cp ${bdBase}/bin/bd $out/bin/bd - - # Create 'beads' alias symlink - ln -s bd $out/bin/beads - - # Generate shell completions - mkdir -p $out/share/fish/vendor_completions.d - mkdir -p $out/share/bash-completion/completions - mkdir -p $out/share/zsh/site-functions - - $out/bin/bd completion fish > $out/share/fish/vendor_completions.d/bd.fish - $out/bin/bd completion bash > $out/share/bash-completion/completions/bd - $out/bin/bd completion zsh > $out/share/zsh/site-functions/_bd - ''; - - meta = bdBase.meta; - }; - default = bd; -in -{ - inherit default bd; - - # Separate completion packages for users who only want specific shells - fish-completions = pkgs.runCommand "bd-fish-completions" { } '' - mkdir -p $out/share/fish/vendor_completions.d - ln -s ${bd}/share/fish/vendor_completions.d/bd.fish $out/share/fish/vendor_completions.d/bd.fish - ''; - - bash-completions = pkgs.runCommand "bd-bash-completions" { } '' - mkdir -p $out/share/bash-completion/completions - ln -s ${bd}/share/bash-completion/completions/bd $out/share/bash-completion/completions/bd - ''; - - zsh-completions = pkgs.runCommand "bd-zsh-completions" { } '' - mkdir -p $out/share/zsh/site-functions - ln -s ${bd}/share/zsh/site-functions/_bd $out/share/zsh/site-functions/_bd - ''; + # Separate completion packages for users who only want specific shells. + fish-completions = pkgs.beads.passthru.fish-completions; + bash-completions = pkgs.beads.passthru.bash-completions; + zsh-completions = pkgs.beads.passthru.zsh-completions; }