Skip to content

Commit

Permalink
Nix: Set build revision based on git SHA
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Sep 18, 2024
1 parent 11d0563 commit 47d4880
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs ? import <nixpkgs> { } }:
{ pkgs ? import <nixpkgs> {}, gitSha }:
pkgs.rustPlatform.buildRustPackage {
pname = "amp";
version = "0.7.0";
Expand All @@ -13,8 +13,26 @@
# Packages needed during the build
nativeBuildInputs = with pkgs; [ git ];

# Make the build/check/install commands explicit so we can
# provide the commit SHA for the splash screen
buildPhase = ''
export BUILD_REVISION=${builtins.substring 0 7 gitSha}
echo "BUILD_REVISION=$BUILD_REVISION"
cargo build --release
'';

checkPhase = ''
cargo test
'';

installPhase = ''
mkdir -p $out/bin
cp target/release/amp $out/bin/
'';

# Amp creates files and directories in $HOME/.config/amp when run.
# Since the checkPhase of the build process runs the test suite, we
# need a writable location to avoid permission error test failures.
HOME="$out";
HOME="$src";
}
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
pkgsFor = nixpkgs.legacyPackages;
in {
packages = forAllSystems (system: {
default = pkgsFor.${system}.callPackage ./. { };
default = pkgsFor.${system}.callPackage ./. { gitSha = self.rev; };
});
};
}

0 comments on commit 47d4880

Please sign in to comment.