Skip to content

Commit

Permalink
Merge pull request #40 from loqusion/fix/unsetSourceDateEpoch
Browse files Browse the repository at this point in the history
fix: unset `SOURCE_DATE_EPOCH` to allow Typst to use correct date
  • Loading branch information
loqusion authored Jan 3, 2025
2 parents fae09f6 + c010bbd commit 137ed74
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions checks/date/main.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#let UNIX_EPOCH = datetime(
year: 1980,
month: 1,
day: 1,
)
#assert.ne(
datetime.today(),
UNIX_EPOCH,
)
9 changes: 9 additions & 0 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ in
'';
};

date = myLib.buildTypstProject {
inherit typstSource;
src = myLib.cleanTypstSource ./date;
};
dateWatch = watch {} {
inherit typstSource;
src = myLib.cleanTypstSource ./date;
};

devShell = myLib.devShell {
inherit virtualPaths;
checks = {
Expand Down
1 change: 1 addition & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ in {
linkVirtualPaths = callPackage ./linkVirtualPaths.nix {};
mkTypstDerivation = callPackage ./mkTypstDerivation.nix {};
typstOptsFromArgs = callPackage ./typstOptsFromArgs.nix {};
unsetSourceDateEpoch = callPackage ./setupHooks/unsetSourceDateEpoch.nix {};
watchTypstProject = callPackage ./watchTypstProject.nix {};
})
5 changes: 5 additions & 0 deletions lib/devShell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
inherit (lib) optionalAttrs optionalString;
inherit (lib.strings) concatStringsSep;

unsetSourceDateEpochScript = builtins.readFile ./setupHooks/unsetSourceDateEpoch.sh;

cleanedArgs = removeAttrs args [
"checks"
"extraShellHook"
Expand Down Expand Up @@ -44,6 +46,9 @@ in
or (optionalString (virtualPaths != []) (linkVirtualPaths {
inherit virtualPaths forceVirtualPaths;
}))
+ ''
${unsetSourceDateEpochScript}
''
+ optionalString (extraShellHook != "") ''
${extraShellHook}
Expand Down
2 changes: 2 additions & 0 deletions lib/mkTypstDerivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
lib,
stdenvNoCC,
typst,
unsetSourceDateEpoch,
}: args @ {
buildPhaseTypstCommand,
fontPaths ? [],
Expand Down Expand Up @@ -48,6 +49,7 @@ in
++ [
typst
(copyVirtualPathsHook virtualPaths)
unsetSourceDateEpoch
];

buildPhase =
Expand Down
10 changes: 10 additions & 0 deletions lib/setupHooks/unsetSourceDateEpoch.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{makeSetupHook}: let
unsetSourceDateEpoch = builtins.readFile ./unsetSourceDateEpoch.sh;
in
makeSetupHook {
name = "unsetSourceDateEpoch";
substitutions = {
inherit unsetSourceDateEpoch;
};
}
./unsetSourceDateEpochHook.sh
1 change: 1 addition & 0 deletions lib/setupHooks/unsetSourceDateEpoch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unset SOURCE_DATE_EPOCH
5 changes: 5 additions & 0 deletions lib/setupHooks/unsetSourceDateEpochHook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
unsetSourceDateEpoch() {
@unsetSourceDateEpoch@
}

preBuildHooks+=(unsetSourceDateEpoch)
5 changes: 5 additions & 0 deletions lib/watchTypstProject.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
{inherit typstSource;} // args
));

unsetSourceDateEpochScript = builtins.readFile ./setupHooks/unsetSourceDateEpoch.sh;

cleanedArgs = removeAttrs args [
"fontPaths"
"forceVirtualPaths"
Expand Down Expand Up @@ -60,6 +62,9 @@ in
${toShellVars {inherit typstOutput typstSource;}}
out=''${1:-''${typstOutput:?not defined}}
mkdir -p "$(dirname "$out")"
${unsetSourceDateEpochScript}
${typstWatchCommand} ${typstOptsString} "$typstSource" "$out"
'';
})

0 comments on commit 137ed74

Please sign in to comment.