Description: Make the build reproducible
Author: Chris Lamb <lamby@debian.org>
Last-Update: 2017-06-27

--- singularity-container.orig/libexec/bootstrap-scripts/environment/Makefile.am
+++ singularity-container/libexec/bootstrap-scripts/environment/Makefile.am
@@ -5,6 +5,9 @@
 
 dist_environment_DATA = environment.tar
 
+# older tars did not have --sort option, so we check if it is 
+tarsortopt = $(shell tar --help 2>&1 | grep -qe sort && echo '--sort=name' || : )
+
 .PHONY: environment.tar
 
 environment.tar:
@@ -42,7 +45,7 @@
 	ln -sf .singularity.d/actions/run newroot/.run
 	ln -sf .singularity.d/actions/shell newroot/.shell
 	ln -sf .singularity.d/actions/test newroot/.test
-	cd newroot; tar czf ../environment.tar . --owner=0 --group=0
+	cd newroot; GZIP=-n tar czf ../environment.tar . --owner=0 --group=0 $(tarsortopt) --mtime="@$${SOURCE_DATE_EPOCH:-$$(date +%s)}"
 	rm -rf newroot
 
 MAINTAINERCLEANFILES = Makefile.in
