duckstation: detach sources acquisition to sources.nix

The build scripts used by upstream require Git commands. Because of this, a
`deepClone` is required by fetchFromGitHub.

However, keeping `.git` directory around is detrimental to determinism.

Because of this, we need to run the Git commands "manually", save their outputs
and finally remove `.git`.

In order to not pollute the `package.nix`, this peculiar source acquisition is
detached to its own file and `callPackage`d.

Before this Jesuitic hack, the aforementioned data were obtained and filled by
human hands...
This commit is contained in:
Anderson Torres
2024-07-21 23:03:39 -03:00
parent 80d2de8b7a
commit 19b42ca7b3
2 changed files with 52 additions and 19 deletions
+12 -19
View File
@@ -1,6 +1,5 @@
{ lib
, stdenv
, fetchFromGitHub
, SDL2
, callPackage
, cmake
@@ -14,12 +13,12 @@
, ninja
, pkg-config
, qt6
, substituteAll
, vulkan-loader
, wayland
}:
let
sources = callPackage ./sources.nix { };
shaderc-patched = callPackage ./shaderc-patched.nix { };
inherit (qt6)
qtbase
@@ -30,27 +29,13 @@ let
;
in
stdenv.mkDerivation (finalAttrs: {
pname = "duckstation";
version = "0.1-6658";
src = fetchFromGitHub {
owner = "stenzek";
repo = "duckstation";
rev = "4e0c417add264226b3db065c1466791f0591a1b5";
hash = "sha256-fN0bcjqjMmK3qVLlrYmR2VgjK0BjdK4nUj8vNYdFC3I=";
};
inherit (sources.duckstation) pname version src;
patches = [
# Tests are not built by default
./001-fix-test-inclusion.diff
# Patching yet another script that fills data based on git commands...
(substituteAll {
src = ./002-hardcode-vars.diff;
gitHash = finalAttrs.src.rev;
gitBranch = "master";
gitTag = "${finalAttrs.version}-g4e0c417a";
gitDate = "2024-04-16T12:49:54+10:00";
})
# Patching yet another script that fills data based on git commands . . .
./002-hardcode-vars.diff
];
nativeBuildInputs = [
@@ -82,6 +67,14 @@ stdenv.mkDerivation (finalAttrs: {
(lib.cmakeBool "BUILD_TESTS" true)
];
postPatch = ''
gitHash=$(cat .nixpkgs-auxfiles/git_hash) \
gitBranch=$(cat .nixpkgs-auxfiles/git_branch) \
gitTag=$(cat .nixpkgs-auxfiles/git_tag) \
gitDate=$(cat .nixpkgs-auxfiles/git_date) \
substituteAllInPlace src/scmversion/gen_scmversion.sh
'';
doInstallCheck = true;
installCheckPhase = ''
+40
View File
@@ -0,0 +1,40 @@
{
fetchFromGitHub,
}:
{
duckstation = let
self = {
pname = "duckstation";
version = "0.1-6658";
src = fetchFromGitHub {
owner = "stenzek";
repo = "duckstation";
rev = "refs/tags/v${self.version}";
#
# Some files are filled by using Git commands; it requires deepClone.
# More info at `checkout_ref` function in nix-prefetch-git.
# However, `.git` is a bit nondeterministic (and Git itself makes no
# guarrantees whatsoever).
# Then, in order to enhance reproducibility, what we will do here is:
#
# - Execute the desired Git commands;
# - Save the obtained info into files;
# - Remove `.git` afterwards.
#
deepClone = true;
postFetch = ''
cd $out
mkdir -p .nixpkgs-auxfiles/
git rev-parse HEAD > .nixpkgs-auxfiles/git_hash
git rev-parse --abbrev-ref HEAD | tr -d '\r\n' > .nixpkgs-auxfiles/git_branch
git describe --dirty | tr -d '\r\n' > .nixpkgs-auxfiles/git_tag
git log -1 --date=iso8601-strict --format=%cd > .nixpkgs-auxfiles/git_date
find $out -name .git -print0 | xargs -0 rm -fr
'';
hash = "sha256-ZP9WYaz9e6x3x4UpuW2ep5sc+nUT2O+b0048bmkW0ac=";
};
};
in
self;
}