Skip to content

Nix flake で他環境へのワンコマンド配布対応 - #31

Merged
karimiku merged 2 commits into
mainfrom
feature/add-nix-flake
May 5, 2026
Merged

karimiku merged 2 commits into
mainfrom
feature/add-nix-flake

Conversation

@karimiku

@karimiku karimiku commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • flake.nix を追加し、Nix が入ってる環境であれば nix run github:karimiku/todo_cli だけで todo / tb / td をビルド・実行できるようにした
  • 配布の前提として LICENSE (MIT) を追加(無いと法的に他人がコピー不可で、nixpkgs にも載せられない)
  • nix build が生成する /result シンボリックリンクを .gitignore に追加

なぜ

Go製CLIの配布で「相手のマシンに即届ける」最短ルートとして、まず Nix flake から整備する。今後 GoReleaser + Homebrew tap を足せば配布範囲を広げられるが、第一歩として依存が無く決定論的に動く Nix を選択。

flake.nix の構成

  • buildGoModule で cmd/todo, cmd/tb, cmd/td を subPackages 指定でビルド
  • glebarez/sqlite が pure Go なので CGO_ENABLED=0
  • ldflags = [ "-s" "-w" ] でバイナリを strip
  • apps.{default,todo,tb,td} を公開(nix run .#tb 等で個別起動可能)
  • devShells.default に go / gopls / gotools / golangci-lint / gnumake

動作確認

ローカル (Determinate Nix 3.19.0, darwin) で確認済み:

  • nix build が成功し result/bin/{todo,tb,td} が生成される
  • nix run .#todo -- --help がヘルプを出力
  • nix run .#tb -- --help / nix run .#td -- --help も動作
  • バイナリサイズ 各 ~15MB(strip 効いてる)

Test plan

  • 別環境(Linux x86_64 など)で nix run github:karimiku/todo_cli/feature/add-nix-flake を試す
  • nix flake check がエラーなく通る
  • 既存の make build / make test / make ci が引き続き動作する

🤖 Generated with Claude Code

karimiku and others added 2 commits May 5, 2026 12:22
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
flake.nix を追加し、Nixを使う環境で `nix run github:kamiriku/todo_cli`
だけで todo / tb / td の3バイナリをビルド・実行できるようにした。

- buildGoModule で 3 binaries (todo, tb, td) をビルド
- apps エントリで `nix run .#todo` などを公開
- devShell に go / gopls / golangci-lint / gnumake を同梱
- /result symlink を .gitignore に追加

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@karimiku
karimiku merged commit b09d3e5 into main May 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant