From fcf3a42da243f9d967d61b2d6beb18449da5b963 Mon Sep 17 00:00:00 2001 From: John Lago <750845+Lagoja@users.noreply.github.com> Date: Sun, 29 Sep 2024 10:58:54 -0700 Subject: [PATCH] Fix flake rev issue (#2310) ## Summary Nix flake fails to build with: ```nix error: attribute 'dirtyShortRev' missing at /nix/store/m5mqwkz0ss2cav2c9663mx8vwsmvcas3-source/flake.nix:21:28: 20| then "${x}-${self.shortRev}" 21| else "${x}-${self.dirtyShortRev}") | ^ 22| ]; ``` This fixes the issue ## How was it tested? ``` nix build github:jetify-com/devbox/jl/fix-flake-rev ``` --- flake.nix | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index 2ed7a4d5f2f..7eac76384f1 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Instant, easy, predictable shells and containers"; + description = "Instant, easy, predictable dev environments"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; @@ -13,15 +13,14 @@ 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}") - ]; + revision = if (self ? shortRev) + then "${self.shortRev}" + else "${self.dirtyShortRev or "dirty"}"; - # Run `devbox run update-flake` to update the vendorHash + # Add the commit to the version string for flake builds + version = "${lastTag}-${revision}"; + + # Run `devbox run update-flake` to update the vendor-hash vendorHash = if builtins.pathExists ./vendor-hash then builtins.readFile ./vendor-hash else ""; @@ -31,18 +30,17 @@ in { inherit self; - packages.default = buildGoModule rec { + packages.default = buildGoModule { pname = "devbox"; - version = getVersion; + inherit version vendorHash; src = ./.; - inherit vendorHash; - ldflags = [ "-s" "-w" "-X go.jetpack.io/devbox/internal/build.Version=${version}" + "-X go.jetpack.io/devbox/internal/build.Commit=${revision}" ]; # Disable tests if they require network access or are integration tests