Skip to content

Commit 1f47fce

Browse files
committed
nix: package the CLI as a flake
Expose packages.default via buildGoModule so the binary can be installed with nix (`nix run github:sanketsudake/chrome-cdp-cli`) instead of only through the Homebrew cask. The build mirrors .goreleaser.yaml: subPackages cmd/chrome-cdp, CGO_ENABLED=0 and the same internal/cli.Version ldflag. The `version` string in flake.nix has to be bumped with each release tag, since a flake building `src = self` has no tag to read.
1 parent deee305 commit 1f47fce

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222
# npm installer shim: downloaded binary + local test deps
2323
/npm/bin/.bin/
2424
/npm/node_modules/
25+
26+
# nix build output
27+
/result

‎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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
description = "Drive your already-running local Chrome from the command line over CDP";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
6+
outputs =
7+
{ self, nixpkgs }:
8+
let
9+
# Keep in step with the release tag; goreleaser stamps the same string
10+
# into internal/cli from {{ .Version }}.
11+
version = "0.3.2";
12+
13+
systems = [
14+
"aarch64-darwin"
15+
"x86_64-darwin"
16+
"aarch64-linux"
17+
"x86_64-linux"
18+
];
19+
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
20+
in
21+
{
22+
packages = forAllSystems (pkgs: rec {
23+
chrome-cdp = pkgs.buildGoModule {
24+
pname = "chrome-cdp";
25+
inherit version;
26+
src = self;
27+
28+
vendorHash = "sha256-8f/eoBJZxQHsiUpUbbbw9NWiduRT+NCEEu90HVWN9vE=";
29+
30+
subPackages = [ "cmd/chrome-cdp" ];
31+
32+
# Matches the goreleaser build: pure Go, no cgo.
33+
env.CGO_ENABLED = 0;
34+
35+
ldflags = [
36+
"-s"
37+
"-w"
38+
"-X github.com/sanketsudake/chrome-cdp-cli/internal/cli.Version=${version}"
39+
];
40+
41+
meta = {
42+
description = "Drive your already-running local Chrome from the command line over CDP";
43+
homepage = "https://github.com/sanketsudake/chrome-cdp-cli";
44+
license = pkgs.lib.licenses.mit;
45+
mainProgram = "chrome-cdp";
46+
};
47+
};
48+
default = chrome-cdp;
49+
});
50+
51+
formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
52+
};
53+
}

0 commit comments

Comments
 (0)