Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
105 lines (92 loc) · 3.7 KB
/
Copy pathflake.nix
File metadata and controls
105 lines (92 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
description = "gojo – a TUI for jj (Jujutsu VCS), in Go";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs = { self, nixpkgs }:
let
# Single source of truth for the version. goreleaser reads this too
# (see .goreleaser.yaml's before-hook, which verifies it matches the
# git tag), so bumping VERSION is the only place the version lives.
version = nixpkgs.lib.strings.trim (builtins.readFile ./VERSION);
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
in
{
packages = forAllSystems (pkgs:
{
default = pkgs.buildGoModule {
pname = "gojo";
inherit version;
src = self;
# Stamp the version into main.version, same as goreleaser does,
# so `gojo --version` matches the VERSION file.
ldflags = [ "-s -w" "-X main.version=${version}" ];
# proxyVendor uses `go mod download` (full module zips) instead of
# `go mod vendor`. Vendoring prunes to the build platform's
# imports, so its hash differs across GOOS/GOARCH; proxyVendor
# yields one vendorHash that's stable across all `systems` above.
proxyVendor = true;
# Hash of the downloaded Go modules. When go.sum changes, run
# `nix build` once and replace this with the "got:" value.
# Stable across systems thanks to proxyVendor above.
vendorHash = "sha256-vLHrJumGeHctjkHOBdQj7bL/kVbdSuCYK1mSW651AZ0=";
nativeBuildInputs = [ pkgs.makeWrapper ];
postInstall = ''
wrapProgram $out/bin/gojo \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.codex ]}
ln -s gojo $out/bin/gj
# Expose login as well as making Codex available to `nix run`.
ln -s ${pkgs.codex}/bin/codex $out/bin/codex
# Theme files: gojo looks for share/gojo/themes next to bin/.
mkdir -p $out/share/gojo/themes
cp themes/*.toml $out/share/gojo/themes/
'';
meta = with pkgs.lib; {
description = "Fullscreen terminal UI for jj (Jujutsu VCS)";
mainProgram = "gojo";
license = licenses.mit;
};
};
}
);
apps = forAllSystems (pkgs: {
default = {
type = "app";
program = "${self.packages.${pkgs.system}.default}/bin/gojo";
};
# Version bump helper: `nix run .#bump -- [major|minor|patch|X.Y.Z]`
# (no arg = patch). Run from the repo root: it rewrites VERSION,
# then `nix build .#default` and patches vendorHash on mismatch.
bump = {
type = "app";
program = "${pkgs.writeShellApplication {
name = "gojo-bump";
runtimeInputs = [ pkgs.go ];
text = ''
if [ ! -f VERSION ] || [ ! -f flake.nix ]; then
echo "gojo-bump: run from the gojo repo root" >&2
exit 1
fi
# bump.go is referenced from the flake source (no rebuild of the
# script itself into the store needed); writes land in the CWD.
exec go run ${./scripts/bump.go} "$@"
'';
}}/bin/gojo-bump";
};
});
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
go
gopls
go-tools
codex
];
shellHook = ''
echo "gojo dev shell – $(go version)"
'';
};
});
};
}