diff --git a/doc/flatpak-builder.xml b/doc/flatpak-builder.xml
index f0136d41..05017d0c 100644
--- a/doc/flatpak-builder.xml
+++ b/doc/flatpak-builder.xml
@@ -604,8 +604,13 @@
Set this timestamp as SOURCE_DATE_EPOCH to perform the
- build, instead of the last modification time of the manifest.
- This is available since 1.3.1.
+ build. This is available since 1.3.1.
+
+ Since 1.5.0, SOURCE_DATE_EPOCH is set to the fixed
+ UNIX timestamp 1321009871 by default. Passing a value
+ overrides this default. Passing 0
+ disables setting SOURCE_DATE_EPOCH entirely in the
+ build environment.
diff --git a/src/builder-context.c b/src/builder-context.c
index d584687d..004b6609 100644
--- a/src/builder-context.c
+++ b/src/builder-context.c
@@ -41,6 +41,8 @@
"# This file is autogenerated by flatpak-builder.\n" \
"*\n"
+#define DEFAULT_SOURCE_DATE_EPOCH G_GINT64_CONSTANT (1321009871)
+
struct BuilderContext
{
GObject parent;
@@ -90,6 +92,7 @@ struct BuilderContext
BuilderSdkConfig *sdk_config;
BuilderAsUrlPolicy as_url_policy;
+ BuilderSourceDateEpochMode source_date_epoch_mode;
};
typedef struct
@@ -656,10 +659,12 @@ builder_context_get_source_date_epoch (BuilderContext *self)
}
void
-builder_context_set_source_date_epoch (BuilderContext *self,
- gint64 source_date_epoch)
+builder_context_set_source_date_epoch (BuilderContext *self,
+ BuilderSourceDateEpochMode mode,
+ gint64 value)
{
- self->source_date_epoch = source_date_epoch;
+ self->source_date_epoch_mode = mode;
+ self->source_date_epoch = (mode == BUILDER_SOURCE_DATE_EPOCH_OVERRIDE) ? value : DEFAULT_SOURCE_DATE_EPOCH;
}
const char *
@@ -1140,7 +1145,7 @@ char **
builder_context_extend_env_pre (BuilderContext *self,
char **envp)
{
- if (self->source_date_epoch != 0)
+ if (self->source_date_epoch_mode != BUILDER_SOURCE_DATE_EPOCH_UNSET)
{
g_autofree char *s_d_e = g_strdup_printf ("%" G_GUINT64_FORMAT, self->source_date_epoch);
envp = g_environ_setenv (envp, "SOURCE_DATE_EPOCH", s_d_e, FALSE);
diff --git a/src/builder-context.h b/src/builder-context.h
index f6c12329..06aeefdd 100644
--- a/src/builder-context.h
+++ b/src/builder-context.h
@@ -34,6 +34,13 @@ typedef enum {
BUILDER_AS_URL_POLICY_FULL,
} BuilderAsUrlPolicy;
+typedef enum {
+ BUILDER_SOURCE_DATE_EPOCH_DEFAULT,
+ BUILDER_SOURCE_DATE_EPOCH_OVERRIDE,
+ BUILDER_SOURCE_DATE_EPOCH_UNSET,
+} BuilderSourceDateEpochMode;
+
+
/* Same as SOUP_HTTP_URI_FLAGS, means all possible flags for http uris */
#if GLIB_CHECK_VERSION (2, 68, 0)
@@ -92,8 +99,9 @@ const char * builder_context_get_default_branch (BuilderContext *self);
void builder_context_set_default_branch (BuilderContext *self,
const char *default_branch);
gint64 builder_context_get_source_date_epoch (BuilderContext *self);
-void builder_context_set_source_date_epoch (BuilderContext *self,
- gint64 source_date_epoch);
+void builder_context_set_source_date_epoch (BuilderContext *self,
+ BuilderSourceDateEpochMode mode,
+ gint64 value);
const char * builder_context_get_stop_at (BuilderContext *self);
void builder_context_set_stop_at (BuilderContext *self,
const char *module);
diff --git a/src/builder-main.c b/src/builder-main.c
index 3f2704a0..77691834 100644
--- a/src/builder-main.c
+++ b/src/builder-main.c
@@ -35,6 +35,9 @@
#include "builder-utils.h"
#include "builder-git.h"
+#define SOURCE_DATE_EPOCH_DISABLE G_GINT64_CONSTANT (0) /* Disable setting SOURCE_DATE_EPOCH entirely */
+#define SOURCE_DATE_EPOCH_DEFAULT G_GINT64_CONSTANT (-1) /* Default when --override-source-date-epoch is not passed */
+
static gboolean opt_verbose;
static gboolean opt_version;
static gboolean opt_run;
@@ -88,7 +91,7 @@ static char *opt_installation;
static gboolean opt_log_session_bus;
static gboolean opt_log_system_bus;
static gboolean opt_yes;
-static gint64 opt_source_date_epoch = -1;
+static gint64 opt_source_date_epoch = SOURCE_DATE_EPOCH_DEFAULT;
static gchar *opt_as_url_policy = NULL;
static GOptionEntry entries[] = {
@@ -490,7 +493,6 @@ main (int argc,
int i, first_non_arg, orig_argc;
int argnr;
char *p;
- struct stat statbuf;
gsize manifest_length;
setlocale (LC_ALL, "");
@@ -767,10 +769,12 @@ main (int argc,
return 1;
}
- if (opt_source_date_epoch > -1)
- builder_context_set_source_date_epoch (build_context, opt_source_date_epoch);
- else if (stat (flatpak_file_get_path_cached (manifest_file), &statbuf) == 0)
- builder_context_set_source_date_epoch (build_context, (gint64)statbuf.st_mtime);
+ if (opt_source_date_epoch == SOURCE_DATE_EPOCH_DISABLE)
+ builder_context_set_source_date_epoch (build_context, BUILDER_SOURCE_DATE_EPOCH_UNSET, 0);
+ else if (opt_source_date_epoch == SOURCE_DATE_EPOCH_DEFAULT)
+ builder_context_set_source_date_epoch (build_context, BUILDER_SOURCE_DATE_EPOCH_DEFAULT, 0);
+ else
+ builder_context_set_source_date_epoch (build_context, BUILDER_SOURCE_DATE_EPOCH_OVERRIDE, opt_source_date_epoch);
manifest_sha256 = g_compute_checksum_for_string (G_CHECKSUM_SHA256, manifest_contents, -1);
diff --git a/tests/meson.build b/tests/meson.build
index 0e5d0fbd..ba196481 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -15,6 +15,7 @@ test_names = [
'test-builder-flags',
'test-builder-cleanup',
'test-builder-licence-paths',
+ 'test-builder-src-date-epoch',
]
tap_test = find_program(
diff --git a/tests/test-builder-src-date-epoch.sh b/tests/test-builder-src-date-epoch.sh
new file mode 100755
index 00000000..5188c02c
--- /dev/null
+++ b/tests/test-builder-src-date-epoch.sh
@@ -0,0 +1,101 @@
+#!/bin/bash
+#
+# Copyright (C) 2026 Boudhayan Bhattacharya
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+set -euo pipefail
+
+. $(dirname $0)/libtest.sh
+
+skip_without_fuse
+
+echo "1..3"
+
+setup_repo
+install_repo
+setup_sdk_repo
+install_sdk_repo
+
+cd "$TEST_DATA_DIR"
+
+run_build () {
+ local manifest=$1
+ ${FLATPAK_BUILDER} --force-clean appdir "$manifest" >&2
+}
+
+cat > test-src-date-epoch-default.json <<'EOF'
+{
+ "app-id": "org.test.src_date_epoch_default",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-commands": [
+ "echo ${SOURCE_DATE_EPOCH} > /app/sde_out"
+ ]
+ }]
+}
+EOF
+
+run_build test-src-date-epoch-default.json
+
+assert_file_has_content appdir/files/sde_out '^1321009871$'
+
+echo "ok source-date-epoch default fixed epoch is set"
+
+cat > test-src-date-epoch-override.json <<'EOF'
+{
+ "app-id": "org.test.src_date_epoch_override",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-commands": [
+ "echo ${SOURCE_DATE_EPOCH} > /app/sde_out"
+ ]
+ }]
+}
+EOF
+
+${FLATPAK_BUILDER} --force-clean --override-source-date-epoch=1234567890 appdir test-src-date-epoch-override.json >&2
+
+assert_file_has_content appdir/files/sde_out '^1234567890$'
+
+echo "ok source-date-epoch override value is used"
+
+cat > test-src-date-epoch-disable.json <<'EOF'
+{
+ "app-id": "org.test.src_date_epoch_disable",
+ "runtime": "org.test.Platform",
+ "sdk": "org.test.Sdk",
+ "modules": [{
+ "name": "test",
+ "buildsystem": "simple",
+ "build-commands": [
+ "echo ${SOURCE_DATE_EPOCH:-unset} > /app/sde_out"
+ ]
+ }]
+}
+EOF
+
+${FLATPAK_BUILDER} --force-clean --override-source-date-epoch=0 appdir test-src-date-epoch-disable.json >&2
+
+assert_file_has_content appdir/files/sde_out '^unset$'
+
+echo "ok source-date-epoch is unset when disabled with 0"