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 <dylan.johnston@cba.com.au>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Harry Miller 2026-07-06 22:39:37 -07:00 • committed by GitHub
commit 63bef27fe8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 96 additions and 66 deletions

View file

@ -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:

View file

@ -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; [

68
overlay.nix Normal file
View file

@ -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
'';
};
};
}

View file

@ -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;
}