git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commit7eaba9af5e4819913ae0ec97c6c6b8ce0143ef4e authorMichael Weiss <dev.primeos@gmail.com> dateMon 5 Nov 2018, 20:27 (8 years ago) parenta35dae7
2 files changed+77
pkgs/tools/typesetting/scdoc/default.nix+2 pkgs/tools/typesetting/scdoc/use-source-date-epoch.patch+75
pkgs/tools/typesetting/scdoc/default.nix+2
@@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
99 sha256 = "0a9sxifzsbj24kjnpc0525i91ni2vkwizhgvwx1m9shvfkiisnc6";
1010 };
1111
12+ patches = [ ./use-source-date-epoch.patch ];
13+
1214 postPatch = ''
1315 substituteInPlace Makefile \
1416 --replace "-static" "" \
pkgs/tools/typesetting/scdoc/use-source-date-epoch.patchnew file+75
@@ -0,0 +1,75 @@
1+diff --git a/src/main.c b/src/main.c
2+index 14b08d2..e2cc33e 100644
3+--- a/src/main.c
4++++ b/src/main.c
5+@@ -3,6 +3,7 @@
6+ #include <stdbool.h>
7+ #include <stdio.h>
8+ #include <stdlib.h>
9++#define __USE_XOPEN
10+ #include <time.h>
11+ #include <unistd.h>
12+ #include "string.h"
13+@@ -66,10 +67,17 @@ static void parse_preamble(struct parser *p) {
14+ int section = -1;
15+ uint32_t ch;
16+ char date[256];
17+- time_t now;
18+- time(&now);
19+- struct tm *now_tm = localtime(&now);
20+- strftime(date, sizeof(date), "%F", now_tm);
21++ char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
22++ if (source_date_epoch != NULL) {
23++ struct tm source_date_epoch_tm;
24++ strptime(source_date_epoch, "%s", &source_date_epoch_tm);
25++ strftime(date, sizeof(date), "%F", &source_date_epoch_tm);
26++ } else {
27++ time_t now;
28++ time(&now);
29++ struct tm *now_tm = localtime(&now);
30++ strftime(date, sizeof(date), "%F", now_tm);
31++ }
32+ while ((ch = parser_getch(p)) != UTF8_INVALID) {
33+ if ((ch < 0x80 && isalnum(ch)) || ch == '_' || ch == '-' || ch == '.') {
34+ assert(str_append_ch(name, ch) != -1);
35+diff --git a/test/preamble b/test/preamble
36+index 03e2d0c..eeb734b 100755
37+--- a/test/preamble
38++++ b/test/preamble
39+@@ -38,31 +38,31 @@ EOF
40+ end 0
41+
42+ begin "Writes the appropriate header"
43+-scdoc <<EOF | grep '^\.TH "test" "8" "'"$(date +'%F')"'"' >/dev/null
44++scdoc <<EOF | grep '^\.TH "test" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'"' >/dev/null
45+ test(8)
46+ EOF
47+ end 0
48+
49+ begin "Preserves dashes"
50+-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'"' >/dev/null
51++scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'"' >/dev/null
52+ test-manual(8)
53+ EOF
54+ end 0
55+
56+ begin "Handles extra footer field"
57+-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "Footer"' >/dev/null
58++scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "Footer"' >/dev/null
59+ test-manual(8) "Footer"
60+ EOF
61+ end 0
62+
63+ begin "Handles both extra fields"
64+-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "Footer" "Header"' >/dev/null
65++scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "Footer" "Header"' >/dev/null
66+ test-manual(8) "Footer" "Header"
67+ EOF
68+ end 0
69+
70+ begin "Emits empty footer correctly"
71+-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "" "Header"' >/dev/null
72++scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "" "Header"' >/dev/null
73+ test-manual(8) "" "Header"
74+ EOF
75+ end 0