From b4e6cfa3a30e30790892a1c75167a5862c4d3597 Mon Sep 17 00:00:00 2001 From: Jordan MacDonald Date: Mon, 9 Sep 2024 22:22:00 -0400 Subject: [PATCH] Use Nix built-ins to extract the build revision --- default.nix | 9 ++++++++- flake.nix | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/default.nix b/default.nix index b156e15a..bdff2b94 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,4 @@ -{ pkgs ? import { } }: +{ pkgs ? import { }, gitSha ? "unknown" }: pkgs.rustPlatform.buildRustPackage { pname = "amp"; version = "0.7.0"; @@ -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. diff --git a/flake.nix b/flake.nix index 7d9df7a4..76c78c16 100644 --- a/flake.nix +++ b/flake.nix @@ -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; + }; }); }; }