diff --git a/HISTORY b/HISTORY index 1af5e9e5..8b443aa3 100644 --- a/HISTORY +++ b/HISTORY @@ -29,6 +29,11 @@ SnapRAID HISTORY will be slower, this change preserves hash data in the content file to ensure a better fix during disk failures and allows the --import option to remain functional even after an incomplete sync. + * Added --with-smartctl, --with-zfs, --with-zpool, --with-bcachefs + configure options to allow pinning the absolute path of each tool at + build time. When not specified, the existing runtime discovery + behaviour is preserved. Primarily intended for NixOS and other + non-FHS systems. 14.6 2026/06 ============ diff --git a/cmdline/unix.c b/cmdline/unix.c index 6bcb4542..adecc2c7 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -611,6 +611,10 @@ int exit_sync_needed = 2; #if HAVE_LINUX_DEVICE static const char* const bcachefs_paths[] = { +#ifdef BCACHEFS_PATH + /* Path configured at build time (e.g. on NixOS). */ + BCACHEFS_PATH, +#else "/usr/sbin/bcachefs", "/sbin/bcachefs", "/usr/local/sbin/bcachefs", @@ -620,6 +624,7 @@ static const char* const bcachefs_paths[] = { #ifdef __APPLE__ /* macOS (Intel & Apple Silicon) */ "/opt/homebrew/sbin/bcachefs", +#endif #endif 0 }; @@ -638,6 +643,10 @@ static const char* find_bcachefs(void) #if HAVE_LINUX_DEVICE static const char* const zfs_paths[] = { +#ifdef ZFS_PATH + /* Path configured at build time (e.g. on NixOS). */ + ZFS_PATH, +#else "/usr/sbin/zfs", "/sbin/zfs", "/usr/local/sbin/zfs", @@ -647,6 +656,7 @@ static const char* const zfs_paths[] = { #ifdef __APPLE__ /* macOS (Intel & Apple Silicon) */ "/opt/homebrew/sbin/zfs", +#endif #endif 0 }; @@ -662,6 +672,10 @@ static const char* find_zfs(void) } static const char* const zpool_paths[] = { +#ifdef ZPOOL_PATH + /* Path configured at build time (e.g. on NixOS). */ + ZPOOL_PATH, +#else "/usr/sbin/zpool", "/sbin/zpool", "/usr/local/sbin/zpool", @@ -671,6 +685,7 @@ static const char* const zpool_paths[] = { #ifdef __APPLE__ /* macOS (Intel & Apple Silicon) */ "/opt/homebrew/sbin/zpool", +#endif #endif 0 }; @@ -782,7 +797,12 @@ const char* stat_desc(struct stat* st) } #if HAVE_LINUX_DEVICE + static const char* smartctl_paths[] = { +#ifdef SMARTCTL_PATH + /* Path configured at build time (e.g. on NixOS). */ + SMARTCTL_PATH, +#else /* Linux & BSD */ "/usr/sbin/smartctl", "/sbin/smartctl", @@ -792,6 +812,7 @@ static const char* smartctl_paths[] = { #ifdef __APPLE__ /* macOS (Intel & Apple Silicon) */ "/opt/homebrew/sbin/smartctl", +#endif #endif 0 }; diff --git a/configure.ac b/configure.ac index 943257ff..9de437b3 100644 --- a/configure.ac +++ b/configure.ac @@ -456,6 +456,32 @@ AC_ARG_ENABLE([warning], ], []) +# WITH_TOOL(NAME, BINARY, DESCRIPTION) +# Adds --with-NAME=PATH option. Defines NAME_PATH if given. +AC_DEFUN([WITH_TOOL], [ + AC_ARG_WITH([$1], + [AS_HELP_STRING([--with-$1=PATH], + [absolute path to the $2 executable ($3)])], + [ + AS_CASE([$withval], + [/*], [], + [AC_MSG_ERROR([--with-$1 requires an absolute path (got '$withval')])]) + AS_IF([test ! -x "$withval"], + [AC_MSG_WARN([$2 not found or not executable at '$withval'])]) + AC_DEFINE_UNQUOTED(m4_toupper([$1_PATH]), ["$withval"], + [Absolute path to $2, set at configure time.]) + AC_MSG_NOTICE([$2: $withval]) + ], + [ + AC_MSG_NOTICE([$2: use runtime discovery]) + ]) +]) + +WITH_TOOL([smartctl], [smartctl], [S.M.A.R.T. monitoring]) +WITH_TOOL([zfs], [zfs], [ZFS pool management]) +WITH_TOOL([zpool], [zpool], [ZFS pool status]) +WITH_TOOL([bcachefs], [bcachefs], [Bcachefs management]) + AC_ARG_VAR([TESTENV], [Test environment]) AC_ARG_VAR([FAILENV], [Test environment for failing tests]) AC_ARG_VAR([TESTENV_SSE2], [Test environment for SSE2])