Skip to content

Commit

Permalink
Use Nix built-ins to extract the build revision
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Sep 10, 2024
1 parent bf711cf commit b4e6cfa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs ? import <nixpkgs> { } }:
{ pkgs ? import <nixpkgs> { }, gitSha ? "unknown" }:
pkgs.rustPlatform.buildRustPackage {
pname = "amp";
version = "0.7.0";
Expand All @@ -13,6 +13,13 @@
# Packages needed during the build
nativeBuildInputs = with pkgs; [ git ];

# Make the build command explicit so we can
# provide the commit SHA for the splash screen
buildPhase = ''
export BUILD_REVISION=${gitSha}
cargo build --release
'';

# 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.
Expand Down
6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};

outputs = { self, nixpkgs }:
outputs = { self, nixpkgs, ampSha ? "unknown" }:
let
supportedSystems = [ "x86_64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgsFor = nixpkgs.legacyPackages;
in {
packages = forAllSystems (system: {
default = pkgsFor.${system}.callPackage ./. { };
default = pkgsFor.${system}.callPackage ./. {
gitSha = ampSha;
};
});
};
}

0 comments on commit b4e6cfa

Please sign in to comment.