Skip to content

Commit 76bc23f

Browse files
committed
feat: add Nix flake packaging and install docs
Enable nix run/profile install for git-open and document the workflow for Nix users.
1 parent 4a9bf2f commit 76bc23f

4 files changed

Lines changed: 149 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ dist/
2626

2727
# windsurf rules
2828
.windsurfrules
29+
30+
# Nix build result symlink
31+
result

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@ chmod +x git-open
5757
sudo mv git-open /usr/local/bin/
5858
```
5959

60+
61+
### Nix
62+
63+
Using flakes (recommended):
64+
65+
```sh
66+
# one-shot run without installing
67+
nix run github:zhaochunqi/git-open
68+
69+
# install into your profile
70+
nix profile install github:zhaochunqi/git-open
71+
72+
# or pin a release tag
73+
nix profile install github:zhaochunqi/git-open/v2.4.2
74+
```
75+
76+
From a local checkout:
77+
78+
```sh
79+
nix build
80+
./result/bin/git-open version
81+
82+
# development shell with Go toolchain
83+
nix develop
84+
```
85+
6086
### mise with ubi
6187

6288
For users who prefer mise for version management:

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
description = "Open the web URL of the current Git repository in a browser";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
};
7+
8+
outputs =
9+
{ self, nixpkgs }:
10+
let
11+
systems = [
12+
"x86_64-linux"
13+
"aarch64-linux"
14+
"x86_64-darwin"
15+
"aarch64-darwin"
16+
];
17+
forAllSystems = nixpkgs.lib.genAttrs systems;
18+
19+
# Keep in sync with the latest release tag when packaging.
20+
packageVersion = "2.4.2";
21+
in
22+
{
23+
packages = forAllSystems (
24+
system:
25+
let
26+
pkgs = nixpkgs.legacyPackages.${system};
27+
commit = self.shortRev or self.dirtyShortRev or "dirty";
28+
in
29+
{
30+
default = self.packages.${system}.git-open;
31+
git-open = pkgs.buildGoModule {
32+
pname = "git-open";
33+
version = packageVersion;
34+
src = self;
35+
36+
# Bump this after changing go.mod / go.sum:
37+
# nix build 2>&1 | rg 'got:'
38+
vendorHash = "sha256-WaM79VI/0eSCj4t6Myji/WPrjRSUFfaQjHfqPXGULgM=";
39+
40+
# Needed by worktree-related tests in checkPhase.
41+
nativeBuildInputs = [ pkgs.git ];
42+
43+
ldflags = [
44+
"-s"
45+
"-w"
46+
"-X github.com/zhaochunqi/git-open/cmd.Version=${packageVersion}"
47+
"-X github.com/zhaochunqi/git-open/cmd.CommitHash=${commit}"
48+
"-X github.com/zhaochunqi/git-open/cmd.BuildDate=unknown"
49+
];
50+
51+
# ldflags inject release version, so skip tests that assert the
52+
# default "dev" values from source.
53+
checkFlags = [ "-skip=^Test_rootCmd_VersionFlag$" ];
54+
55+
meta = with pkgs.lib; {
56+
description = "Open the web URL of the Git repository";
57+
homepage = "https://github.com/zhaochunqi/git-open";
58+
changelog = "https://github.com/zhaochunqi/git-open/releases/tag/v${packageVersion}";
59+
license = licenses.mit;
60+
mainProgram = "git-open";
61+
platforms = platforms.unix ++ platforms.windows;
62+
};
63+
};
64+
}
65+
);
66+
67+
apps = forAllSystems (system: {
68+
default = {
69+
type = "app";
70+
program = "${self.packages.${system}.git-open}/bin/git-open";
71+
};
72+
});
73+
74+
devShells = forAllSystems (
75+
system:
76+
let
77+
pkgs = nixpkgs.legacyPackages.${system};
78+
in
79+
{
80+
default = pkgs.mkShell {
81+
packages = with pkgs; [
82+
go
83+
gopls
84+
gotools
85+
git
86+
];
87+
};
88+
}
89+
);
90+
91+
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
92+
};
93+
}

0 commit comments

Comments
 (0)