Unblock Fruix checkout runtime on FreeBSD

This commit is contained in:
2026-04-01 14:09:37 +02:00
parent 0d70317d28
commit d4f1fedcb8
6 changed files with 586 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -37,6 +37,7 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (guix ui) ;import in user interfaces only
+ #:declarative? #f
#:use-module (guix i18n)
#:use-module (guix colors)
#:use-module (guix diagnostics)
@@ -562,20 +563,25 @@
(define* (show-version-and-exit #:optional (command (car (command-line))))
"Display version information for COMMAND and `(exit 0)'."
- (leave-on-EPIPE
- (simple-format #t "~a (~a) ~a~%"
- command %guix-package-name %guix-version)
- (format #t "Copyright ~a 2026 ~a"
- ;; TRANSLATORS: Translate "(C)" to the copyright symbol
- ;; (C-in-a-circle), if this symbol is available in the user's
- ;; locale. Otherwise, do not translate "(C)"; leave it as-is. */
- (G_ "(C)")
- (G_ "the Guix authors\n"))
- (display (G_"\
+ (catch 'system-error
+ (lambda ()
+ (simple-format #t "~a (~a) ~a~%"
+ command %guix-package-name %guix-version)
+ (format #t "Copyright ~a 2026 ~a"
+ ;; TRANSLATORS: Translate "(C)" to the copyright symbol
+ ;; (C-in-a-circle), if this symbol is available in the user's
+ ;; locale. Otherwise, do not translate "(C)"; leave it as-is. */
+ (G_ "(C)")
+ (G_ "the Guix authors\n"))
+ (display (G_"\
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
-")))
+")))
+ (lambda args
+ (if (= EPIPE (system-error-errno args))
+ (primitive-_exit 0)
+ (apply throw args))))
(exit 0))
(define (show-bug-report-information)
@@ -2388,7 +2394,7 @@
((or ("-h") ("--help"))
(leave-on-EPIPE (show-guix-help)))
((or ("-V") ("--version"))
- (show-version-and-exit "guix"))
+ (show-version-and-exit (basename (or (program-name) "guix"))))
(((? option? o) args ...)
(format (current-error-port)
(G_ "guix: unrecognized option '~a'~%") o)
@@ -2404,8 +2410,9 @@
args)))))
(define (guix-main arg0 . args)
- (initialize-guix)
- (apply run-guix args))
+ (parameterize ((program-name (basename arg0)))
+ (initialize-guix)
+ (apply run-guix args)))
;;; Local Variables:
;;; eval: (put 'guard* 'scheme-indent-function 2)
--- a/guix/scripts/repl.scm
+++ b/guix/scripts/repl.scm
@@ -19,6 +19,7 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (guix scripts repl)
+ #:declarative? #f
#:use-module (guix ui)
#:use-module (guix scripts)
#:use-module (guix repl)

View File

@@ -0,0 +1,58 @@
--- a/nix/nix-daemon/nix-daemon.cc
+++ b/nix/nix-daemon/nix-daemon.cc
@@ -169,7 +169,11 @@
static void handleSignal(int signum)
{
+#if defined(__FreeBSD__)
+ string name = getprogname();
+#else
string name = program_invocation_short_name;
+#endif
auto message = name + ": PID " + std::to_string(getpid())
+ " caught signal " + std::to_string(signum) + "\n";
writeFull(STDERR_FILENO, (unsigned char *) message.c_str(), message.length());
@@ -940,12 +944,12 @@
/* If we're on a TCP connection, disable Nagle's algorithm so that
data is sent as soon as possible. */
- (void) setsockopt(remote, SOL_TCP, TCP_NODELAY,
+ (void) setsockopt(remote, IPPROTO_TCP, TCP_NODELAY,
&enabled, sizeof enabled);
#if defined(TCP_QUICKACK)
/* Enable TCP quick-ack if applicable; this might help a little. */
- (void) setsockopt(remote, SOL_TCP, TCP_QUICKACK,
+ (void) setsockopt(remote, IPPROTO_TCP, TCP_QUICKACK,
&enabled, sizeof enabled);
#endif
}
--- a/nix/libutil/spawn.cc
+++ b/nix/libutil/spawn.cc
@@ -31,6 +31,10 @@
#include <cstdlib>
#include <cassert>
#include <format>
+
+#if defined(__FreeBSD__)
+extern char **environ;
+#endif
#if HAVE_SYS_MOUNT_H
#include <sys/mount.h>
--- a/nix/libutil/archive.cc
+++ b/nix/libutil/archive.cc
@@ -298,9 +298,10 @@
errno = posix_fallocate(fd, 0, len);
/* Note that EINVAL may indicate that the underlying
filesystem doesn't support preallocation (e.g. on
- OpenSolaris). Since preallocation is just an
- optimisation, ignore it. */
- if (errno && errno != EINVAL)
+ OpenSolaris). On FreeBSD, EOPNOTSUPP/ENOTSUP can be
+ returned for the same reason. Since preallocation is
+ just an optimisation, ignore those cases. */
+ if (errno && errno != EINVAL && errno != EOPNOTSUPP && errno != ENOTSUP)
throw SysError(std::format("preallocating file of {} bytes", len));
}
#endif

View File

@@ -0,0 +1,98 @@
#!/bin/sh
set -eu
repo_root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
metadata_target=${METADATA_OUT:-}
cleanup=0
if [ -n "${WORKDIR:-}" ]; then
workdir=$WORKDIR
mkdir -p "$workdir"
else
workdir=$(mktemp -d /tmp/fruix-phase5-runtime.XXXXXX)
cleanup=1
fi
if [ "${KEEP_WORKDIR:-0}" -eq 1 ]; then
cleanup=0
fi
cleanup_workdir() {
if [ "$cleanup" -eq 1 ]; then
rm -rf "$workdir"
fi
}
trap cleanup_workdir EXIT INT TERM
setup_metadata=$workdir/setup-metadata.txt
setup_env=$workdir/setup-env.sh
runtime_log=$workdir/runtime-command.log
metadata_file=$workdir/phase5-runtime-metadata.txt
WORKDIR=$workdir/setup KEEP_WORKDIR=1 \
METADATA_OUT=$setup_metadata ENV_OUT=$setup_env \
"$repo_root/tests/guix/setup-phase5-checkout.sh" >"$workdir/setup.log" 2>&1
# shellcheck disable=SC1090
. "$setup_env"
cd "$PHASE5_BUILDDIR"
export LD_LIBRARY_PATH GUILE_LOAD_PATH GUILE_LOAD_COMPILED_PATH GUILE_EXTENSIONS_PATH
export GUILE_AUTO_COMPILE=0
./pre-inst-env guix --version >"$workdir/guix-version.log" 2>&1
./pre-inst-env guix repl --help >"$workdir/guix-repl-help.log" 2>&1
./pre-inst-env guix build --help >"$workdir/guix-build-help.log" 2>&1
./pre-inst-env fruix --version >"$workdir/fruix-version.log" 2>&1
first_guix_version_line=$(sed -n '1p' "$workdir/guix-version.log")
first_fruix_version_line=$(sed -n '1p' "$workdir/fruix-version.log")
repl_usage_line=$(grep -m1 '^Usage:' "$workdir/guix-repl-help.log" || true)
build_usage_line=$(grep -m1 '^Usage:' "$workdir/guix-build-help.log" || true)
printf '%s\n' "$first_guix_version_line" | grep -q '^guix (GNU Guix) ' || {
echo "unexpected guix version output: $first_guix_version_line" >&2
exit 1
}
printf '%s\n' "$first_fruix_version_line" | grep -q '^fruix (GNU Guix) ' || {
echo "unexpected fruix version output: $first_fruix_version_line" >&2
exit 1
}
printf '%s\n' "$repl_usage_line" | grep -q '^Usage: guix repl ' || {
echo "unexpected guix repl help output: $repl_usage_line" >&2
exit 1
}
printf '%s\n' "$build_usage_line" | grep -q '^Usage: guix build' || {
echo "unexpected guix build help output: $build_usage_line" >&2
exit 1
}
cat >"$metadata_file" <<EOF
workdir=$workdir
setup_metadata=$setup_metadata
setup_env=$setup_env
phase5_builddir=$PHASE5_BUILDDIR
phase5_pre_inst_env=$PHASE5_PRE_INST_ENV
guix_version_log=$workdir/guix-version.log
fruix_version_log=$workdir/fruix-version.log
guix_repl_help_log=$workdir/guix-repl-help.log
guix_build_help_log=$workdir/guix-build-help.log
first_guix_version_line=$first_guix_version_line
first_fruix_version_line=$first_fruix_version_line
repl_usage_line=$repl_usage_line
build_usage_line=$build_usage_line
fruix_frontend_policy=symlinked scripts/fruix frontend over upstream-derived guix internals
EOF
if [ -n "$metadata_target" ]; then
mkdir -p "$(dirname "$metadata_target")"
cp "$metadata_file" "$metadata_target"
fi
printf 'PASS phase5-checkout-runtime\n'
printf 'Work directory: %s\n' "$workdir"
printf 'Metadata file: %s\n' "$metadata_file"
if [ -n "$metadata_target" ]; then
printf 'Copied metadata to: %s\n' "$metadata_target"
fi
printf '%s\n' '--- metadata ---'
cat "$metadata_file"

View File

@@ -0,0 +1,199 @@
#!/bin/sh
set -eu
repo_root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
source_repo=${GUIX_SOURCE_REPO:-"$HOME/repos/guix"}
guile_bin=${GUILE_BIN:-/tmp/guile-freebsd-validate-install/bin/guile}
guile_extra_prefix=${GUILE_EXTRA_PREFIX:-/tmp/guile-gnutls-freebsd-validate-install}
store_dir=${STORE_DIR:-/frx/store}
localstatedir=${LOCALSTATEDIR:-/frx/var}
sysconfdir=${SYSCONFDIR:-/frx/etc}
make_bin=${MAKE_BIN:-gmake}
gsed_bin=${GSED_BIN:-/usr/local/bin/gsed}
metadata_target=${METADATA_OUT:-}
env_target=${ENV_OUT:-}
if [ ! -x "$guile_bin" ]; then
echo "Guile binary is not executable: $guile_bin" >&2
exit 1
fi
if [ ! -d "$source_repo/guix" ]; then
echo "Guix source tree not found at $source_repo" >&2
exit 1
fi
for tool in git patch "$make_bin" gm4 "$gsed_bin"; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "Required tool not found: $tool" >&2
exit 1
fi
done
if [ ! -f /usr/local/include/argp.h ]; then
echo "argp-standalone headers not found at /usr/local/include/argp.h" >&2
exit 1
fi
cleanup=0
if [ -n "${WORKDIR:-}" ]; then
workdir=$WORKDIR
mkdir -p "$workdir"
else
workdir=$(mktemp -d /tmp/fruix-phase5-checkout.XXXXXX)
cleanup=1
fi
if [ "${KEEP_WORKDIR:-0}" -eq 1 ]; then
cleanup=0
fi
cleanup_workdir() {
if [ "$cleanup" -eq 1 ]; then
rm -rf "$workdir"
fi
}
trap cleanup_workdir EXIT INT TERM
srcclone=$workdir/guix-src
builddir=$workdir/build
metadata_file=$workdir/phase5-checkout-setup-metadata.txt
env_file=$workdir/phase5-checkout-env.sh
bootstrap_log=$workdir/bootstrap.log
configure_log=$workdir/configure.log
make_scripts_log=$workdir/make-scripts.log
daemon_build_log=$workdir/make-guix-daemon.log
runtime_patch=$repo_root/tests/guix/patches/phase5-checkout-runtime.patch
daemon_patch=$repo_root/tests/guix/patches/phase5-guix-daemon-freebsd.patch
guile_bindir=$(CDPATH= cd -- "$(dirname "$guile_bin")" && pwd)
guile_prefix=$(CDPATH= cd -- "$guile_bindir/.." && pwd)
guile_lib_dir=$guile_prefix/lib
guile_version=$(LD_LIBRARY_PATH="$guile_lib_dir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" "$guile_bin" -c '(display (effective-version))')
extra_site_dir=$guile_extra_prefix/share/guile/site/$guile_version
extra_site_ccache_dir=$guile_extra_prefix/lib/guile/$guile_version/site-ccache
extra_extensions_dir=$guile_extra_prefix/lib/guile/$guile_version/extensions
tool_bindir=$workdir/guile-tools-bin
mkdir -p "$tool_bindir"
ln -sf "$guile_bin" "$tool_bindir/guile"
ln -sf "$guile_bin" "$tool_bindir/guile-3.0"
ln -sf "$guile_bindir/guild" "$tool_bindir/guild"
ln -sf "$guile_bindir/guild" "$tool_bindir/guild-3.0"
ln -sf "$guile_bindir/guile-config" "$tool_bindir/guile-config"
ln -sf "$guile_bindir/guile-config" "$tool_bindir/guile-config-3.0"
ln -sf "$guile_bindir/guile-snarf" "$tool_bindir/guile-snarf"
export PATH="$tool_bindir:$guile_bindir:/usr/local/bin:$PATH"
export ACLOCAL_PATH=/usr/local/share/aclocal${ACLOCAL_PATH:+:$ACLOCAL_PATH}
export PKG_CONFIG_PATH=$guile_extra_prefix/lib/pkgconfig:$guile_extra_prefix/libdata/pkgconfig:$guile_prefix/lib/pkgconfig:/usr/local/libdata/pkgconfig:/usr/local/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
export CPPFLAGS="-I$guile_prefix/include -I$guile_extra_prefix/include -I/usr/local/include"
export LDFLAGS="-L$guile_lib_dir -L$guile_extra_prefix/lib -L/usr/local/lib -Wl,-rpath,$guile_lib_dir -Wl,-rpath,$guile_extra_prefix/lib -Wl,-rpath,/usr/local/lib"
export LD_LIBRARY_PATH="$guile_extra_prefix/lib:$guile_lib_dir:/usr/local/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
if [ -d "$extra_site_dir" ]; then
export GUILE_LOAD_PATH="$extra_site_dir${GUILE_LOAD_PATH:+:$GUILE_LOAD_PATH}"
fi
if [ -d "$extra_site_ccache_dir" ]; then
export GUILE_LOAD_COMPILED_PATH="$extra_site_ccache_dir${GUILE_LOAD_COMPILED_PATH:+:$GUILE_LOAD_COMPILED_PATH}"
fi
if [ -d "$extra_extensions_dir" ]; then
export GUILE_EXTENSIONS_PATH="$extra_extensions_dir${GUILE_EXTENSIONS_PATH:+:$GUILE_EXTENSIONS_PATH}"
fi
printf 'Working directory: %s\n' "$workdir"
printf 'Cloning source from: %s\n' "$source_repo"
rm -rf "$srcclone" "$builddir"
git clone --shared "$source_repo" "$srcclone" >/dev/null 2>&1
(
cd "$srcclone"
M4=gm4 ./bootstrap
) >"$bootstrap_log" 2>&1
(
cd "$srcclone"
patch -p1 < "$runtime_patch"
patch -p1 < "$daemon_patch"
) >/dev/null
mkdir -p "$builddir"
(
cd "$builddir"
MAKE="$make_bin" \
GUILE="$guile_bin" \
GUILE_EFFECTIVE_VERSION=3.0 \
SED="$gsed_bin" \
"$srcclone/configure" \
--with-courage \
--with-store-dir="$store_dir" \
--localstatedir="$localstatedir" \
--sysconfdir="$sysconfdir"
) >"$configure_log" 2>&1
(
cd "$builddir"
"$make_bin" -j1 scripts/guix
) >"$make_scripts_log" 2>&1
(
cd "$builddir"
"$make_bin" -j1 LIBS='-L/usr/local/lib -largp -lintl' nix/libstore/schema.sql.hh guix-daemon
) >"$daemon_build_log" 2>&1
ln -sf guix "$builddir/scripts/fruix"
cat >"$env_file" <<EOF
export PHASE5_WORKDIR='$workdir'
export PHASE5_SRCCLONE='$srcclone'
export PHASE5_BUILDDIR='$builddir'
export PHASE5_PRE_INST_ENV='$builddir/pre-inst-env'
export PHASE5_GUIX_BIN='$builddir/scripts/guix'
export PHASE5_FRUIX_BIN='$builddir/scripts/fruix'
export PHASE5_GUIX_DAEMON='$builddir/guix-daemon'
export LD_LIBRARY_PATH='$guile_extra_prefix/lib:$guile_lib_dir:/usr/local/lib'
export GUILE_LOAD_PATH='$extra_site_dir'
export GUILE_LOAD_COMPILED_PATH='$extra_site_ccache_dir'
export GUILE_EXTENSIONS_PATH='$extra_extensions_dir'
EOF
cat >"$metadata_file" <<EOF
workdir=$workdir
source_repo=$source_repo
srcclone=$srcclone
builddir=$builddir
guile_bin=$guile_bin
guile_extra_prefix=$guile_extra_prefix
guile_version=$guile_version
store_dir=$store_dir
localstatedir=$localstatedir
sysconfdir=$sysconfdir
runtime_patch=$runtime_patch
daemon_patch=$daemon_patch
bootstrap_log=$bootstrap_log
configure_log=$configure_log
make_scripts_log=$make_scripts_log
daemon_build_log=$daemon_build_log
env_file=$env_file
pre_inst_env=$builddir/pre-inst-env
guix_bin=$builddir/scripts/guix
fruix_bin=$builddir/scripts/fruix
guix_daemon=$builddir/guix-daemon
EOF
if [ -n "$metadata_target" ]; then
mkdir -p "$(dirname "$metadata_target")"
cp "$metadata_file" "$metadata_target"
fi
if [ -n "$env_target" ]; then
mkdir -p "$(dirname "$env_target")"
cp "$env_file" "$env_target"
fi
printf 'PASS phase5-checkout-setup\n'
printf 'Environment file: %s\n' "$env_file"
printf 'Metadata file: %s\n' "$metadata_file"
if [ -n "$env_target" ]; then
printf 'Copied environment file to: %s\n' "$env_target"
fi
if [ -n "$metadata_target" ]; then
printf 'Copied metadata file to: %s\n' "$metadata_target"
fi
printf '%s\n' '--- metadata ---'
cat "$metadata_file"