s6: migrate to /run/user/$id/s6

This commit is contained in:
Colin 2024-03-23 21:33:08 +00:00
parent 5b83d4d944
commit 7f8cae42ff
2 changed files with 18 additions and 12 deletions

View File

@ -10,12 +10,16 @@
# note that one can still manually specify --live; later definitions will override earlier definitions. # note that one can still manually specify --live; later definitions will override earlier definitions.
postInstall = (upstream.postInstall or "") + '' postInstall = (upstream.postInstall or "") + ''
for prog in s6-rc s6-rc-bundle s6-rc-db s6-rc-format-upgrade s6-rc-init s6-rc-update; do for prog in s6-rc s6-rc-bundle s6-rc-db s6-rc-format-upgrade s6-rc-init s6-rc-update; do
wrapProgram "$out/bin/$prog" \ wrapProgram "$bin/bin/$prog" \
--add-flags '--live $XDG_RUNTIME_DIR/s6' --add-flags '-l $XDG_RUNTIME_DIR/s6/live'
done done
''; '';
}); });
persist.private = [
".local/share/s6/logs"
];
sandbox.enable = false; # service manager sandbox.enable = false; # service manager
suggestedPrograms = [ suggestedPrograms = [
"s6-rc-man-pages" "s6-rc-man-pages"

View File

@ -1,6 +1,6 @@
{ lib, pkgs, ... }: { lib, pkgs, ... }:
let let
logBase = "$HOME/.local/state/s6/logs"; logBase = "$HOME/.local/share/s6/logs";
maybe = cond: value: if cond then value else null; maybe = cond: value: if cond then value else null;
# create a derivation whose output is the on-disk representation of some attrset. # create a derivation whose output is the on-disk representation of some attrset.
@ -193,28 +193,30 @@ in
) )
); );
in { in {
# N.B.: `compiled` needs to be writable (for locks -- maybe i can use symlinks to dodge this someday):
# i populate it to ~/.config as a well-known place, and then copy it to /run before actually using it live.
fs.".config/s6/compiled".symlink.target = compileServices sources;
# exposed only for convenience
fs.".config/s6/sources".symlink.target = sources; fs.".config/s6/sources".symlink.target = sources;
# N.B.: `compiled` needs to be writable (for locks -- maybe i can use symlinks to dodge this someday),
# so write this nearby and copy it over to `compiled` later
fs.".config/s6/compiled-static".symlink.target = compileServices sources;
fs.".profile".symlink.text = '' fs.".profile".symlink.text = ''
function startS6() { function startS6() {
local S6_TARGET="''${1:-default}" local S6_TARGET="''${1:-default}"
local COMPILED="$HOME/.config/s6/compiled" local S6_RUN_DIR="$XDG_RUNTIME_DIR/s6"
local LIVE="$HOME/.config/s6/live" local COMPILED="$S6_RUN_DIR/compiled"
local SCANDIR="$HOME/.config/s6/scandir" local LIVE="$S6_RUN_DIR/live"
local SCANDIR="$S6_RUN_DIR/scandir"
rm -rf "$SCANDIR" rm -rf "$SCANDIR"
mkdir "$SCANDIR" mkdir -p "$SCANDIR"
s6-svscan "$SCANDIR" & s6-svscan "$SCANDIR" &
local SVSCAN=$! local SVSCAN=$!
# the scandir is just links back into the compiled dir, # the scandir is just links back into the compiled dir,
# so the compiled dir therefore needs to be writable: # so the compiled dir therefore needs to be writable:
rm -rf "$COMPILED" rm -rf "$COMPILED"
cp --dereference -R "$COMPILED-static" "$COMPILED" cp --dereference -R "$HOME/.config/s6/compiled" "$COMPILED"
chmod -R 0700 "$COMPILED" chmod -R 0700 "$COMPILED"
s6-rc-init -c "$COMPILED" -l "$LIVE" -d "$SCANDIR" s6-rc-init -c "$COMPILED" -l "$LIVE" -d "$SCANDIR"
@ -227,7 +229,7 @@ in
wait "$SVSCAN" wait "$SVSCAN"
} }
function startS6WithLogging() { function startS6WithLogging() {
# TODO: might not want to create log dir here: move to nix fs/persistence. # the log dir should already exist by now (nixos persistence); create it just in case something went wrong.
mkdir -p "${logBase}" mkdir -p "${logBase}"
startS6 2>&1 | tee /dev/stderr | s6-log -- T "${logBase}/catchall" startS6 2>&1 | tee /dev/stderr | s6-log -- T "${logBase}/catchall"
} }