Skip to content

Commit 9b5f915

Browse files
committed
Install Devbox via Flake
1 parent 68edd30 commit 9b5f915

File tree

7 files changed

+168
-23
lines changed

7 files changed

+168
-23
lines changed

.github/workflows/cli-tests.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ jobs:
7676
- uses: actions/checkout@v4
7777
- uses: crate-ci/[email protected]
7878

79+
flake-test:
80+
name: Test Flake Build
81+
if: github.ref != 'refs/heads/main'
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v4
85+
- uses: DeterminateSystems/nix-installer-action@main
86+
- run: nix build .
87+
7988
golangci-lint:
8089
strategy:
8190
matrix:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ __pycache__/
3838
# deployment
3939
.vercel
4040
.yarn
41+
42+
# Nix
43+
vendor/
44+
result

devbox.json

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,51 @@
11
{
2-
"name": "devbox",
2+
"name": "devbox",
33
"description": "Instant, easy, and predictable development environments",
44
"packages": {
5-
"go": "latest",
5+
"go": "latest",
66
"runx:golangci/golangci-lint": "latest",
7-
"runx:mvdan/gofumpt": "latest",
7+
"runx:mvdan/gofumpt": "latest",
8+
"github:nix-community/gomod2nix": ""
89
},
910
"env": {
1011
"GOENV": "off",
11-
"PATH": "$PATH:$PWD/dist",
12+
"PATH": "$PATH:$PWD/dist"
1213
},
1314
"shell": {
1415
"init_hook": [
1516
// Remove Go environment variables that might've been inherited from the
1617
// user's environment and could affect the build.
1718
"test -z $FISH_VERSION && \\",
1819
"unset CGO_ENABLED GO111MODULE GOARCH GOFLAGS GOMOD GOOS GOROOT GOTOOLCHAIN GOWORK || \\",
19-
"set --erase CGO_ENABLED GO111MODULE GOARCH GOFLAGS GOMOD GOOS GOROOT GOTOOLCHAIN GOWORK",
20+
"set --erase CGO_ENABLED GO111MODULE GOARCH GOFLAGS GOMOD GOOS GOROOT GOTOOLCHAIN GOWORK"
2021
],
2122
"scripts": {
2223
// Build devbox for the current platform
23-
"build": "go build -o dist/devbox ./cmd/devbox",
24+
"build": "go build -o dist/devbox ./cmd/devbox",
2425
"build-darwin-amd64": "GOOS=darwin GOARCH=amd64 go build -o dist/devbox-darwin-amd64 ./cmd/devbox",
2526
"build-darwin-arm64": "GOOS=darwin GOARCH=arm64 go build -o dist/devbox-darwin-arm64 ./cmd/devbox",
26-
"build-linux-amd64": "GOOS=linux GOARCH=amd64 go build -o dist/devbox-linux-amd64 ./cmd/devbox",
27-
"build-linux-arm64": "GOOS=linux GOARCH=arm64 go build -o dist/devbox-linux-arm64 ./cmd/devbox",
27+
"build-linux-amd64": "GOOS=linux GOARCH=amd64 go build -o dist/devbox-linux-amd64 ./cmd/devbox",
28+
"build-linux-arm64": "GOOS=linux GOARCH=arm64 go build -o dist/devbox-linux-arm64 ./cmd/devbox",
2829
"build-all": [
2930
"devbox run build-darwin-amd64",
3031
"devbox run build-darwin-arm64",
3132
"devbox run build-linux-amd64",
32-
"devbox run build-linux-arm64",
33+
"devbox run build-linux-arm64"
3334
],
3435
// Open VSCode
35-
"code": "code .",
36-
"lint": "golangci-lint run --timeout 5m && scripts/gofumpt.sh",
37-
"fmt": "scripts/gofumpt.sh",
38-
"test": "go test -race -cover ./...",
36+
"code": "code .",
37+
"lint": "golangci-lint run --timeout 5m && scripts/gofumpt.sh",
38+
"fmt": "scripts/gofumpt.sh",
39+
"test": "go test -race -cover ./...",
3940
"test-projects-only": "DEVBOX_RUN_PROJECT_TESTS=1 go test -v -timeout ${DEVBOX_GOLANG_TEST_TIMEOUT:-30m} ./... -run \"TestExamples|TestScriptsWithProjects\"",
40-
"update-examples": "devbox run build && go run testscripts/testrunner/updater/main.go",
41-
"tidy": "go mod tidy",
41+
"update-examples": "devbox run build && go run testscripts/testrunner/updater/main.go",
42+
"update-hash": [
43+
"go mod vendor",
44+
"hash=$(nix hash path vendor)",
45+
"echo \"$hash\" > vendor-hash",
46+
"rm -rf vendor"
47+
],
48+
"tidy": "go mod tidy",
4249

4350
// docker-testscripts runs the testscripts with Docker to exercise
4451
// Linux-specific tests. It invokes the test binary directly, so any extra
@@ -58,8 +65,8 @@
5865
"GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go test -c -o testscripts-linux-amd64",
5966
"GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go test -c -o testscripts-linux-arm64",
6067
"image=$(docker build --quiet --tag devbox-testscripts-ubuntu:noble --platform linux/amd64 .)",
61-
"docker run --rm --mount type=volume,src=devbox-testscripts-amd64,dst=/nix --platform linux/amd64 -e DEVBOX_RUN_FAILING_TESTS -e DEVBOX_RUN_PROJECT_TESTS -e DEVBOX_DEBUG $image \"$@\"",
62-
],
63-
},
64-
},
68+
"docker run --rm --mount type=volume,src=devbox-testscripts-amd64,dst=/nix --platform linux/amd64 -e DEVBOX_RUN_FAILING_TESTS -e DEVBOX_RUN_PROJECT_TESTS -e DEVBOX_DEBUG $image \"$@\""
69+
]
70+
}
71+
}
6572
}

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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
description = "Instant, easy, predictable shells and containers";
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.eachDefaultSystem (system:
11+
let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
14+
lastTag = "0.13.2";
15+
16+
getVersion = pkgs.lib.trivial.pipe self [
17+
(x: "${lastTag}")
18+
(x: if (self ? revCount)
19+
then "${x}-${self.shortRev}"
20+
else "${x}-${self.dirtyShortRev}")
21+
];
22+
23+
vendorHash = if builtins.pathExists ./vendor-hash
24+
then builtins.readFile ./vendor-hash
25+
else "";
26+
27+
buildGoModule = pkgs.buildGo123Module;
28+
29+
in
30+
{
31+
inherit self;
32+
packages.default = buildGoModule rec {
33+
pname = "devbox";
34+
version = getVersion;
35+
36+
src = ./.;
37+
38+
inherit vendorHash; # Let nix compute the vendor hash
39+
40+
ldflags = [
41+
"-s"
42+
"-w"
43+
"-X go.jetpack.io/devbox/internal/build.Version=${version}"
44+
];
45+
46+
# Disable tests if they require network access or are integration tests
47+
doCheck = false;
48+
49+
nativeBuildInputs = [ pkgs.installShellFiles ];
50+
51+
postInstall = ''
52+
installShellCompletion --cmd devbox \
53+
--bash <($out/bin/devbox completion bash) \
54+
--fish <($out/bin/devbox completion fish) \
55+
--zsh <($out/bin/devbox completion zsh)
56+
'';
57+
58+
meta = with pkgs.lib; {
59+
description = "Instant, easy, predictable shells and containers";
60+
homepage = "https://www.jetpack.io/devbox";
61+
license = licenses.asl20;
62+
maintainers = with maintainers; [ urandom lagoja ];
63+
};
64+
};
65+
}
66+
);
67+
}

go.sum

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

vendor-hash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sha256-rwmNzYzmZqNcNVV4GgqCVLT6ofIkblVCMJHLGwlhcGw=

0 commit comments

Comments
 (0)