Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,53 @@ To pin the version a repository uses, add it as a Go tool and run it with
go get -tool github.com/chaba-dev/rfdtool@latest
```

With Nix, run it with `nix run github:chaba-dev/rfdtool -- check`, or add
the flake's `packages.default` to a dev shell.
### With Nix

Run it once with `nix run github:chaba-dev/rfdtool -- check`, or install it
with `nix profile install github:chaba-dev/rfdtool`.

In an RFD repository with a flake, add rfdtool as an input and put the binary
in the dev shell, so `rfdtool` is on the path there and in CI's
`nix develop --command`. `flake.lock` pins the version; `nix flake update
rfdtool` moves it to the latest commit.

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
rfdtool = {
url = "github:chaba-dev/rfdtool";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{ nixpkgs, flake-utils, rfdtool, ... }:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
packages = [
rfdtool.packages.${system}.default
pkgs.git # for rfdtool check --base-ref, and authors in rfdtool new
];
};
}
);
}
```

A flake that builds its own nixpkgs can add `rfdtool.overlays.default` to its
overlays and use `pkgs.rfdtool` instead. Either way the package needs Go 1.26
(`go_1_26`) from that nixpkgs. It builds on Linux and Apple Silicon macOS;
current nixpkgs no longer supports Intel Macs.

`rfdtool --version` prints the commit a Nix build came from, or the module
version for `go install`.

To start a project, create the RFD directory and the first RFD:

Expand Down
54 changes: 38 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,57 @@
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };

# The Go release go.mod asks for, used to build and in the dev shell.
go = pkgs.go_1_26;
buildGoModule = pkgs.buildGoModule.override { inherit go; };

rfdtool = buildGoModule {
pname = "rfdtool";
let
# rfdtool built with the Go release go.mod asks for, from any nixpkgs
# that has it.
mkRfdtool =
pkgs:
let
version = self.shortRev or self.dirtyShortRev or "dev";
src = ./.;
buildGoModule = pkgs.buildGoModule.override { go = pkgs.go_1_26; };
in
buildGoModule {
pname = "rfdtool";
inherit version;
src = self;
# Update when go.mod or go.sum change: set it to pkgs.lib.fakeHash,
# run nix build, and copy the hash it reports.
vendorHash = "sha256-3+raHHPQE20lsZ09Kvljd9FVECCN9q7ZQlKk6KemRig=";
ldflags = [
"-s"
"-w"
"-X main.version=${version}"
];
# The tests read and write git repositories.
nativeCheckInputs = [ pkgs.git ];
meta.mainProgram = "rfdtool";
meta = {
description = "Check, link, start, and report on Requests for Discussion";
homepage = "https://github.com/chaba-dev/rfdtool";
mainProgram = "rfdtool";
};
};
in
{
# Adds pkgs.rfdtool, for flakes that build their own nixpkgs.
overlays.default = final: prev: { rfdtool = mkRfdtool final; };
}
// flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
go = pkgs.go_1_26;
rfdtool = mkRfdtool pkgs;
in
{
packages.default = rfdtool;

apps.default = flake-utils.lib.mkApp { drv = rfdtool; };
packages = {
inherit rfdtool;
default = rfdtool;
};

# nix flake check builds the package, which runs go test.
checks.default = rfdtool;

# For working on rfdtool itself, with the Go release go.mod asks for.
devShells.default = pkgs.mkShell {
packages = [
go
Expand Down
22 changes: 20 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,35 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime/debug"
"strings"

"github.com/urfave/cli/v3"

"github.com/chaba-dev/rfdtool/internal/rfd"
)

// version is set at build time with -ldflags "-X main.version=...", as the
// Nix flake does.
var version = ""

// buildVersion returns the version set at build time, or the module version
// go install records, such as v0.1.0.
func buildVersion() string {
if version != "" {
return version
}
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" {
return info.Main.Version
}
return "(devel)"
}

func main() {
cmd := &cli.Command{
Name: "rfdtool",
Usage: "tools for a project's Requests for Discussion",
Name: "rfdtool",
Version: buildVersion(),
Usage: "tools for a project's Requests for Discussion",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Expand Down
Loading