freebsd.rc: support bash, fix hardcoded paths
Co-Authored-By: Audrey Dutcher <audrey@rhelmot.io>
This commit is contained in:
co-authored by
Audrey Dutcher
parent
41e01ae7d5
commit
771090934f
@@ -0,0 +1,13 @@
|
||||
diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr
|
||||
index 101c69e93cde..b95fc1b93285 100644
|
||||
--- a/libexec/rc/rc.subr
|
||||
+++ b/libexec/rc/rc.subr
|
||||
@@ -2493,7 +2493,7 @@ ltr()
|
||||
fi
|
||||
done
|
||||
if [ -n "${_var}" ]; then
|
||||
- setvar "${_var}" "${_out}"
|
||||
+ printf -v "${_var}" "%s" "${_out}"
|
||||
else
|
||||
echo "${_out}"
|
||||
fi
|
||||
@@ -10,6 +10,14 @@
|
||||
protect,
|
||||
mount,
|
||||
fsck,
|
||||
logger,
|
||||
devmatch,
|
||||
sort,
|
||||
kldload,
|
||||
kldstat,
|
||||
devctl,
|
||||
sed,
|
||||
gnugrep,
|
||||
}:
|
||||
let
|
||||
rcDepsPath = lib.makeBinPath [
|
||||
@@ -22,6 +30,14 @@ let
|
||||
mount
|
||||
protect
|
||||
fsck
|
||||
logger
|
||||
devmatch
|
||||
sort
|
||||
kldload
|
||||
kldstat
|
||||
devctl
|
||||
sed
|
||||
gnugrep
|
||||
];
|
||||
in
|
||||
mkDerivation {
|
||||
@@ -43,20 +59,23 @@ mkDerivation {
|
||||
''
|
||||
+ (
|
||||
let
|
||||
bins = [
|
||||
"/sbin/sysctl"
|
||||
"/usr/bin/protect"
|
||||
"/usr/bin/id"
|
||||
"/bin/ps"
|
||||
"/bin/cpuset"
|
||||
"/usr/bin/stat"
|
||||
"/bin/rm"
|
||||
"/bin/chmod"
|
||||
"/bin/cat"
|
||||
"/bin/sync"
|
||||
"/bin/sleep"
|
||||
"/bin/date"
|
||||
];
|
||||
bins = {
|
||||
"/sbin/sysctl" = sysctl;
|
||||
"/usr/bin/protect" = protect;
|
||||
"/usr/bin/id" = id;
|
||||
"/bin/ps" = bin;
|
||||
"/bin/cpuset" = bin;
|
||||
"/usr/bin/stat" = stat;
|
||||
"/bin/rm" = bin;
|
||||
"/bin/chmod" = bin;
|
||||
"/bin/cat" = bin;
|
||||
"/bin/sync" = bin;
|
||||
"/bin/sleep" = bin;
|
||||
"/bin/date" = bin;
|
||||
"/usr/bin/logger" = logger;
|
||||
"logger" = logger;
|
||||
"kenv" = bin;
|
||||
};
|
||||
scripts = [
|
||||
"rc"
|
||||
"rc.initdiskless"
|
||||
@@ -64,17 +83,26 @@ mkDerivation {
|
||||
"rc.subr"
|
||||
"rc.suspend"
|
||||
"rc.resume"
|
||||
"rc.conf"
|
||||
];
|
||||
scriptPaths = "$BSDSRCDIR/libexec/rc/{${lib.concatStringsSep "," scripts}}";
|
||||
in
|
||||
# set PATH correctly in scripts
|
||||
''
|
||||
sed -E -i -e "s|PATH=.*|PATH=${rcDepsPath}|g" ${scriptPaths}
|
||||
sed -E -i -e "/etc\/rc.subr/i export PATH=${rcDepsPath}" $BSDSRCDIR/libexec/rc/rc.d/*
|
||||
''
|
||||
# replace executable absolute filepaths with PATH lookups
|
||||
+ lib.concatMapStringsSep "\n" (fname: ''
|
||||
sed -E -i -e "s|${fname}|${lib.last (lib.splitString "/" fname)}|g" \
|
||||
${scriptPaths}'') bins
|
||||
# replace executable references with nix store filepaths
|
||||
+ lib.concatMapStringsSep "\n" (
|
||||
{
|
||||
fname ? name,
|
||||
name,
|
||||
value,
|
||||
}:
|
||||
''
|
||||
sed -E -i -e "s|${fname}|${lib.getBin value}/bin/${lib.last (lib.splitString "/" fname)}|g" \
|
||||
${scriptPaths}''
|
||||
) (lib.attrsToList bins)
|
||||
+ "\n"
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user