-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build and Install Devbox via Nix Flake (#2308)
## Summary This adds a flake.nix to our repo for building and distributing Devbox. This will make it easier for developers who install Devbox with Nix to use pre-releases, and keep Devbox up-to-date on their system. This changes our workflow in a few small ways: 1. Whenever `go.mod` changes, we'll need to run `devbox run update-hash` to update the vendorHash for the flake. You can also run this script when you run `go mod tidy` 2. Releasing a new version will also require us to update the version number in the flake.nix. This should be done with a commit ("Bump version to x.y") that also gets tagged with the release number. 3. For debugging purposes, the flake will add the shortened commit hash to the version string. This also helps identify if a user built the binary from a flake. 4. I've added a test to `cli-tests` that will build the flake. I've confirmed that it will fail if the vendorHash is out of date or incorrect 5. We'll periodically need to run `nix flake update` to update the flake.lock file. ## How was it tested? 1. Ran `nix build .` in the Devbox repo, confirmed that the resulting build worked 2. Tested the Github Action by pushing an invalid vendorHash --------- Signed-off-by: John Lago <[email protected]> Co-authored-by: Greg Curtis <[email protected]>
- Loading branch information
Showing
7 changed files
with
175 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,16 @@ jobs: | |
- uses: actions/checkout@v4 | ||
- uses: crate-ci/[email protected] | ||
|
||
flake-test: | ||
name: Test Flake Build | ||
if: github.ref != 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: DeterminateSystems/nix-installer-action@main | ||
- run: nix build . | ||
- run: ./result/bin/devbox version | ||
|
||
golangci-lint: | ||
strategy: | ||
matrix: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,7 @@ __pycache__/ | |
# deployment | ||
.vercel | ||
.yarn | ||
|
||
# Nix | ||
vendor/ | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
description = "Instant, easy, predictable shells and containers"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
}; | ||
|
||
outputs = { self, nixpkgs, flake-utils }: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
|
||
lastTag = "0.13.2"; | ||
|
||
# Add the commit to the version string, in case someone builds from main | ||
getVersion = pkgs.lib.trivial.pipe self [ | ||
(x: "${lastTag}") | ||
(x: if (self ? revCount) | ||
then "${x}-${self.shortRev}" | ||
else "${x}-${self.dirtyShortRev}") | ||
]; | ||
|
||
# Run `devbox run update-flake` to update the vendorHash | ||
vendorHash = if builtins.pathExists ./vendor-hash | ||
then builtins.readFile ./vendor-hash | ||
else ""; | ||
|
||
buildGoModule = pkgs.buildGo123Module; | ||
|
||
in | ||
{ | ||
inherit self; | ||
packages.default = buildGoModule rec { | ||
pname = "devbox"; | ||
version = getVersion; | ||
|
||
src = ./.; | ||
|
||
inherit vendorHash; | ||
|
||
ldflags = [ | ||
"-s" | ||
"-w" | ||
"-X go.jetpack.io/devbox/internal/build.Version=${version}" | ||
]; | ||
|
||
# Disable tests if they require network access or are integration tests | ||
doCheck = false; | ||
|
||
nativeBuildInputs = [ pkgs.installShellFiles ]; | ||
|
||
postInstall = '' | ||
installShellCompletion --cmd devbox \ | ||
--bash <($out/bin/devbox completion bash) \ | ||
--fish <($out/bin/devbox completion fish) \ | ||
--zsh <($out/bin/devbox completion zsh) | ||
''; | ||
|
||
meta = with pkgs.lib; { | ||
description = "Instant, easy, and predictable development environments"; | ||
homepage = "https://www.jetify.com/devbox"; | ||
license = licenses.asl20; | ||
maintainers = with maintainers; [ lagoja ]; | ||
}; | ||
}; | ||
} | ||
); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sha256-rwmNzYzmZqNcNVV4GgqCVLT6ofIkblVCMJHLGwlhcGw= |