From 25ce61d6f2196d33170f96bf7d3e54e31ce0337b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Mon, 29 Apr 2024 20:58:09 +0200 Subject: [PATCH] quartus-prime-lite: implement the SOURCE_DATE_EPOCH specification For reproducible builds: https://reproducible-builds.org/specs/source-date-epoch Some programs break with fixed/static clock (or just by the fact that $LD_PRELOAD is set), so * make this feature opt-in; activate by setting NIXPKGS_QUARTUS_REPRODUCIBLE_BUILD=1 * add a blocklist of programs that are known to misbehave, and completely exclude them from the SOURCE_DATE_EPOCH handling In the future NIXPKGS_QUARTUS_REPRODUCIBLE_BUILD=1 might be the default, but let's start gently, in case the blocklist is incomplete. --- .../editors/quartus-prime/default.nix | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pkgs/applications/editors/quartus-prime/default.nix b/pkgs/applications/editors/quartus-prime/default.nix index b50d505e2dbb..8358bb7f160c 100644 --- a/pkgs/applications/editors/quartus-prime/default.nix +++ b/pkgs/applications/editors/quartus-prime/default.nix @@ -1,5 +1,5 @@ { lib, buildFHSEnv, callPackage, makeDesktopItem, runtimeShell -, runCommand, unstick, quartus-prime-lite +, runCommand, unstick, quartus-prime-lite, libfaketime, pkgsi686Linux , withQuesta ? true , supportedDevices ? [ "Arria II" "Cyclone V" "Cyclone IV" "Cyclone 10 LP" "MAX II/V" "MAX 10 FPGA" ] , unwrapped ? callPackage ./quartus.nix { inherit unstick supportedDevices withQuesta; } @@ -85,15 +85,28 @@ in buildFHSEnv rec { progs_wrapped=() for prog in ''${progs_to_wrap[@]}; do relname="''${prog#"${unwrapped}/"}" + bname="$(basename "$relname")" wrapped="$out/$relname" progs_wrapped+=("$wrapped") mkdir -p "$(dirname "$wrapped")" echo "#!${runtimeShell}" >> "$wrapped" + NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK=1 case "$relname" in questa_fse/*) echo "export NIXPKGS_IS_QUESTA_WRAPPER=1" >> "$wrapped" + # Any use of LD_PRELOAD breaks Questa, so disable the + # SOURCE_DATE_EPOCH code path. + NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK=0 ;; esac + # SOURCE_DATE_EPOCH blocklist for programs that are known to hang/break + # with fixed/static clock. + case "$bname" in + jtagd|quartus_pgm|quartus) + NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK=0 + ;; + esac + echo "export NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK=$NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK" >> "$wrapped" echo "exec $wrapper $prog \"\$@\"" >> "$wrapped" done @@ -116,6 +129,17 @@ in buildFHSEnv rec { if [ "$NIXPKGS_IS_QUESTA_WRAPPER" != 1 ]; then export LD_PRELOAD=''${LD_PRELOAD:+$LD_PRELOAD:}/usr/lib/libudev.so.0 fi + + # Implement the SOURCE_DATE_EPOCH specification for reproducible builds + # (https://reproducible-builds.org/specs/source-date-epoch). + # Require opt-in with NIXPKGS_QUARTUS_REPRODUCIBLE_BUILD=1 for now, in case + # the blocklist is incomplete. + if [ -n "$SOURCE_DATE_EPOCH" ] && [ "$NIXPKGS_QUARTUS_REPRODUCIBLE_BUILD" = 1 ] && [ "$NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK" = 1 ]; then + export LD_LIBRARY_PATH="${lib.makeLibraryPath [ libfaketime pkgsi686Linux.libfaketime ]}''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" + export LD_PRELOAD=libfaketime.so.1''${LD_PRELOAD:+:$LD_PRELOAD} + export FAKETIME_FMT="%s" + export FAKETIME="$SOURCE_DATE_EPOCH" + fi '' + extraProfile; # Run the wrappers directly, instead of going via bash.