summary refs log tree commit diff
path: root/pkgs/tools
diff options
context:
space:
mode:
authorMichael Weiss <dev.primeos@gmail.com>2018-11-05 20:27:31 +0100
committerMichael Weiss <dev.primeos@gmail.com>2018-11-05 20:37:01 +0100
commit7eaba9af5e4819913ae0ec97c6c6b8ce0143ef4e (patch)
tree6c7daf1105d6e89d41ac2177043cf0e4560d6d3f /pkgs/tools
parenta35dae70c31924253dc26eb62f862cf1f18e6ce0 (diff)
downloadnixlib-7eaba9af5e4819913ae0ec97c6c6b8ce0143ef4e.tar
nixlib-7eaba9af5e4819913ae0ec97c6c6b8ce0143ef4e.tar.gz
nixlib-7eaba9af5e4819913ae0ec97c6c6b8ce0143ef4e.tar.bz2
nixlib-7eaba9af5e4819913ae0ec97c6c6b8ce0143ef4e.tar.lz
nixlib-7eaba9af5e4819913ae0ec97c6c6b8ce0143ef4e.tar.xz
nixlib-7eaba9af5e4819913ae0ec97c6c6b8ce0143ef4e.tar.zst
nixlib-7eaba9af5e4819913ae0ec97c6c6b8ce0143ef4e.zip
scdoc: Use $SOURCE_DATE_EPOCH to produce reproducible man pages
Use this patch until something like it is in the upstream repository.
Without it, the current date is used for the man pages, which makes them
non-reproducible.
Diffstat (limited to 'pkgs/tools')
-rw-r--r--pkgs/tools/typesetting/scdoc/default.nix2
-rw-r--r--pkgs/tools/typesetting/scdoc/use-source-date-epoch.patch75
2 files changed, 77 insertions, 0 deletions
diff --git a/pkgs/tools/typesetting/scdoc/default.nix b/pkgs/tools/typesetting/scdoc/default.nix
index 5789f51abd9c..a5bf2d261e1c 100644
--- a/pkgs/tools/typesetting/scdoc/default.nix
+++ b/pkgs/tools/typesetting/scdoc/default.nix
@@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
     sha256 = "0a9sxifzsbj24kjnpc0525i91ni2vkwizhgvwx1m9shvfkiisnc6";
   };
 
+  patches = [ ./use-source-date-epoch.patch ];
+
   postPatch = ''
     substituteInPlace Makefile \
       --replace "-static" "" \
diff --git a/pkgs/tools/typesetting/scdoc/use-source-date-epoch.patch b/pkgs/tools/typesetting/scdoc/use-source-date-epoch.patch
new file mode 100644
index 000000000000..5a2496d63583
--- /dev/null
+++ b/pkgs/tools/typesetting/scdoc/use-source-date-epoch.patch
@@ -0,0 +1,75 @@
+diff --git a/src/main.c b/src/main.c
+index 14b08d2..e2cc33e 100644
+--- a/src/main.c
++++ b/src/main.c
+@@ -3,6 +3,7 @@
+ #include <stdbool.h>
+ #include <stdio.h>
+ #include <stdlib.h>
++#define __USE_XOPEN
+ #include <time.h>
+ #include <unistd.h>
+ #include "string.h"
+@@ -66,10 +67,17 @@ static void parse_preamble(struct parser *p) {
+ 	int section = -1;
+ 	uint32_t ch;
+ 	char date[256];
+-	time_t now;
+-	time(&now);
+-	struct tm *now_tm = localtime(&now);
+-	strftime(date, sizeof(date), "%F", now_tm);
++	char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
++	if (source_date_epoch != NULL) {
++		struct tm source_date_epoch_tm;
++		strptime(source_date_epoch, "%s", &source_date_epoch_tm);
++		strftime(date, sizeof(date), "%F", &source_date_epoch_tm);
++	} else {
++		time_t now;
++		time(&now);
++		struct tm *now_tm = localtime(&now);
++		strftime(date, sizeof(date), "%F", now_tm);
++	}
+ 	while ((ch = parser_getch(p)) != UTF8_INVALID) {
+ 		if ((ch < 0x80 && isalnum(ch)) || ch == '_' || ch == '-' || ch == '.') {
+ 			assert(str_append_ch(name, ch) != -1);
+diff --git a/test/preamble b/test/preamble
+index 03e2d0c..eeb734b 100755
+--- a/test/preamble
++++ b/test/preamble
+@@ -38,31 +38,31 @@ EOF
+ end 0
+ 
+ begin "Writes the appropriate header"
+-scdoc <<EOF | grep '^\.TH "test" "8" "'"$(date +'%F')"'"' >/dev/null
++scdoc <<EOF | grep '^\.TH "test" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'"' >/dev/null
+ test(8)
+ EOF
+ end 0
+ 
+ begin "Preserves dashes"
+-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'"' >/dev/null
++scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'"' >/dev/null
+ test-manual(8)
+ EOF
+ end 0
+ 
+ begin "Handles extra footer field"
+-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "Footer"' >/dev/null
++scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "Footer"' >/dev/null
+ test-manual(8) "Footer"
+ EOF
+ end 0
+ 
+ begin "Handles both extra fields"
+-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "Footer" "Header"' >/dev/null
++scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "Footer" "Header"' >/dev/null
+ test-manual(8) "Footer" "Header"
+ EOF
+ end 0
+ 
+ begin "Emits empty footer correctly"
+-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "" "Header"' >/dev/null
++scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "" "Header"' >/dev/null
+ test-manual(8) "" "Header"
+ EOF
+ end 0