From 73d09e67a7e79c1bad57f2eddd51b7f00e0eb374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 8 Aug 2025 08:02:37 +0200 Subject: [PATCH] add rc.d script for the nix-daemon --- misc/freebsd/meson.build | 10 ++++++++ misc/freebsd/nix-daemon.in | 49 ++++++++++++++++++++++++++++++++++++++ misc/meson.build | 4 ++++ 3 files changed, 63 insertions(+) create mode 100644 misc/freebsd/meson.build create mode 100644 misc/freebsd/nix-daemon.in diff --git a/misc/freebsd/meson.build b/misc/freebsd/meson.build new file mode 100644 index 000000000..d94149883 --- /dev/null +++ b/misc/freebsd/meson.build @@ -0,0 +1,10 @@ +configure_file( + input : 'nix-daemon.in', + output : 'nix-daemon', + install : true, + install_dir : get_option('prefix') / 'etc/rc.d', + install_mode : 'rwxr-xr-x', + configuration : { + 'bindir' : bindir, + }, +) diff --git a/misc/freebsd/nix-daemon.in b/misc/freebsd/nix-daemon.in new file mode 100644 index 000000000..9eb269850 --- /dev/null +++ b/misc/freebsd/nix-daemon.in @@ -0,0 +1,49 @@ +#!/bin/sh +# +# PROVIDE: nix_daemon +# REQUIRE: DAEMON +# KEYWORD: shutdown +# +# Add the following lines to /etc/rc.conf to enable nix-daemon: +# +# nix_daemon_enable="YES" +# + +# shellcheck source=/dev/null +. /etc/rc.subr + +name="nix_daemon" +# shellcheck disable=SC2034 +rcvar="nix_daemon_enable" + +load_rc_config $name + +: "${nix_daemon_enable:=NO}" + +command="@bindir@/nix-daemon" +command_args="" +pidfile="/var/run/nix-daemon.pid" + +# shellcheck disable=SC2034 +start_cmd="${name}_start" +# shellcheck disable=SC2034 +stop_cmd="${name}_stop" + +nix_daemon_start() { + echo "Starting ${name}." + # command_args is intentionally unquoted to allow multiple arguments + # shellcheck disable=SC2086 + /usr/sbin/daemon -c -f -p "${pidfile}" "${command}" ${command_args} +} + +nix_daemon_stop() { + if [ -f "${pidfile}" ]; then + echo "Stopping ${name}." + kill -TERM "$(cat "${pidfile}")" + rm -f "${pidfile}" + else + echo "${name} is not running." + fi +} + +run_rc_command "$1" \ No newline at end of file diff --git a/misc/meson.build b/misc/meson.build index 82f2b0c65..fc2bca07f 100644 --- a/misc/meson.build +++ b/misc/meson.build @@ -9,3 +9,7 @@ endif if host_machine.system() == 'darwin' subdir('launchd') endif + +if host_machine.system() == 'freebsd' + subdir('freebsd') +endif