Skip to content

Commit aed711f

Browse files
authored
Merge pull request #56 from datum-cloud/drewr/nix-flake
feat: Add nix support Nix flake for datumctl, enabling reproducible builds across multiple platforms and seamless integration into nix environments. * flake.nix with automated vendorHash updates * docs Benefits: - Reproducible builds across all supported platforms - Zero-dependency development environment setup via `nix develop` - Direct execution without installation via `nix run github:datum-cloud/datumctl` - Automated vendorHash maintenance via a GitHub Action - Cross-compilation support for all supported platforms from any platform - Works seamlessly on NixOS, nix-darwin, and any system with Nix installed
2 parents 20e3465 + e6a3b53 commit aed711f

File tree

8 files changed

+391
-1
lines changed

8 files changed

+391
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "nix-update-hash"
2+
on:
3+
push:
4+
paths:
5+
- 'go.mod'
6+
- 'go.sum'
7+
branches-ignore:
8+
- 'nix-update-hash/*'
9+
10+
jobs:
11+
update-hash:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v6
19+
20+
- name: Install Nix
21+
uses: cachix/install-nix-action@v30
22+
with:
23+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Install Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version-file: 'go.mod'
29+
30+
- name: Install Task
31+
uses: arduino/setup-task@v2
32+
33+
- name: Update Nix vendor hash
34+
run: task nix-update-hash
35+
36+
- name: Create Pull Request
37+
uses: peter-evans/create-pull-request@v7
38+
with:
39+
commit-message: 'chore(nix): Update vendorHash after Go dependency changes'
40+
title: 'chore(nix): Update vendorHash after Go dependency changes'
41+
body: |
42+
This PR automatically updates the vendorHash in `flake.nix` after changes to Go dependencies.
43+
44+
Triggered by changes to `go.mod` or `go.sum`.
45+
46+
🤖 Generated by GitHub Actions
47+
branch: nix-update-hash/${{ github.ref_name }}
48+
delete-branch: true

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# Ignore goreleaser output
22
dist/
3+
# Built binary
4+
/datumctl
5+
# Nix stuff
6+
/result

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Use `datumctl` to manage your Datum Cloud resources, authenticate securely, and
1919

2020
### Installation
2121

22-
See the [Installation Guide](./docs/user/installation.md) for detailed instructions, including Homebrew for macOS and pre-built binaries for all platforms.
22+
See the [Installation Guide](./docs/user/installation.md) for detailed instructions, including Homebrew for macOS, nix for Linux and macOS, and pre-built binaries for all platforms.
2323

2424
### Basic Usage
2525

Taskfile.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: '3'
2+
3+
tasks:
4+
default:
5+
desc: Show available tasks
6+
cmds:
7+
- task --list
8+
9+
nix-update-hash:
10+
desc: Automatically update the vendorHash in flake.nix after Go dependency changes
11+
cmds:
12+
- go run scripts/update-nix-hash.go
13+
14+
nix-build:
15+
desc: Build the project with Nix
16+
cmds:
17+
- nix build
18+
19+
nix-dev:
20+
desc: Enter the Nix development shell
21+
cmds:
22+
- nix develop
23+
24+
nix-fmt:
25+
desc: Format nix files
26+
cmds:
27+
- nix fmt
28+
29+
clean:
30+
desc: Remove build artifacts
31+
cmds:
32+
- rm -rf result result-*
33+
34+
nix-check:
35+
desc: Check flake syntax and run checks
36+
cmds:
37+
- nix flake check

docs/user/installation.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,34 @@ brew install datumctl
1818
brew upgrade datumctl
1919
```
2020

21+
## nix (Linux and macOS)
22+
23+
datumctl ships with a `flake.nix` so you don't have to install anything:
24+
25+
```
26+
# Pick latest from git
27+
nix run github:datum-cloud/datumctl
28+
29+
# Specify version
30+
nix run github:datum-cloud/datumctl/b044455d877b800812e4fd78e42429c1617c011b
31+
32+
# Run from local git clone
33+
nix run
34+
35+
# Start shell with all dependencies available
36+
nix develop --command zsh
37+
38+
# Build locally
39+
nix build
40+
41+
# ...or for specific platform
42+
nix build .#packages.x86_64-linux.default
43+
nix build .#packages.aarch64-linux.default
44+
```
45+
46+
You can, however, incorporate it into your home-manager build or other
47+
flake so that it's always available in your profile.
48+
2149
## Pre-built binaries (recommended)
2250

2351
The easiest way to install `datumctl` is by downloading the pre-built binary

flake.lock

Lines changed: 61 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: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
description = "datumctl - A CLI for interacting with Datum Cloud";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachSystem [
11+
"x86_64-linux"
12+
"aarch64-linux"
13+
"x86_64-darwin"
14+
"aarch64-darwin"
15+
] (system:
16+
let
17+
pkgs = import nixpkgs {
18+
inherit system;
19+
};
20+
21+
# Get version from git, fallback to "dev" if not in a git repo
22+
version =
23+
if (builtins.pathExists ./.git)
24+
then builtins.replaceStrings ["\n"] [""] (builtins.readFile (
25+
pkgs.runCommand "get-version" {} ''
26+
cd ${./.}
27+
${pkgs.git}/bin/git describe --tags --always --dirty 2>/dev/null > $out || echo "dev" > $out
28+
''
29+
))
30+
else "dev";
31+
32+
in
33+
{
34+
packages = {
35+
default = pkgs.buildGoModule {
36+
pname = "datumctl";
37+
inherit version;
38+
39+
src = ./.;
40+
41+
# Hash of Go module dependencies.
42+
# Update this after changing go.mod/go.sum:
43+
# task nix-update-hash
44+
vendorHash = "sha256-IZtck6ZsaIoEZLpukWHVbQAhfOsly0WO0OWO+6uRhgE=";
45+
46+
ldflags = [
47+
"-s"
48+
"-w"
49+
"-X main.version=${version}"
50+
];
51+
52+
meta = with pkgs.lib; {
53+
description = "A CLI for interacting with the Datum platform";
54+
homepage = "https://www.datum.net/docs/quickstart/datumctl/";
55+
license = licenses.asl20;
56+
maintainers = [ ];
57+
mainProgram = "datumctl";
58+
};
59+
};
60+
};
61+
62+
devShells.default = pkgs.mkShell {
63+
buildInputs = with pkgs; [
64+
go_1_25
65+
gopls
66+
gotools
67+
go-task
68+
go-tools
69+
git
70+
];
71+
72+
shellHook = ''
73+
echo "datumctl development environment"
74+
echo "Go version: $(go version)"
75+
'';
76+
};
77+
78+
formatter = pkgs.nixpkgs-fmt;
79+
}
80+
);
81+
}

0 commit comments

Comments
 (0)