mirror of
https://github.com/nix-community/home-manager.git
synced 2026-12-06 04:40:17 +00:00
Add programs.t3code.server to run the headless server as a user service with systemd on Linux and launchd on Darwin. Support extra arguments and an optional environment file for runtime secrets. Add tests for generated service files and launchd environment loading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
2.2 KiB
Nix
63 lines
2.2 KiB
Nix
{
|
|
config,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
environmentFile = pkgs.writeText "t3code-env" ''
|
|
T3CODE_PORT=4567
|
|
'';
|
|
# Runnable stand-in for the @t3code@ stub when exercising the launcher.
|
|
testT3code = pkgs.writeShellScriptBin "t3" ''
|
|
[ "$T3CODE_PORT" = 4567 ] || exit 1
|
|
'';
|
|
in
|
|
{
|
|
test.stubs.t3code = { };
|
|
|
|
programs.t3code = {
|
|
enable = true;
|
|
|
|
server = {
|
|
enable = true;
|
|
environmentFile = "/run/secrets/t3code";
|
|
};
|
|
};
|
|
|
|
nmt.script =
|
|
if pkgs.stdenv.hostPlatform.isDarwin then
|
|
let
|
|
serviceLauncher = builtins.head config.launchd.agents.t3code.config.ProgramArguments;
|
|
in
|
|
''
|
|
serviceFile=LaunchAgents/org.nix-community.home.t3code.plist
|
|
assertFileExists "$serviceFile"
|
|
serviceFileNormalized="$(normalizeStorePaths "$serviceFile")"
|
|
assertFileContent "$serviceFileNormalized" ${./server-environment-file.plist}
|
|
|
|
launcherNormalized="$(normalizeStorePaths "${serviceLauncher}")"
|
|
substitute ${./server-environment-file-launcher.sh} "$TMPDIR/launcher-expected.sh" \
|
|
--replace-fail '@shell@' '${pkgs.runtimeShell}'
|
|
launcherExpectedNormalized="$(normalizeStorePaths "$TMPDIR/launcher-expected.sh")"
|
|
assertFileContent "$launcherNormalized" "$launcherExpectedNormalized"
|
|
|
|
substitute "${serviceLauncher}" "$TMPDIR/t3code-launcher" \
|
|
--replace-fail '/run/secrets/t3code' '${environmentFile}' \
|
|
--replace-fail '@t3code@' '${testT3code}'
|
|
${pkgs.runtimeShell} "$TMPDIR/t3code-launcher" \
|
|
|| fail "t3code's launcher must export the environment file's variables to the server"
|
|
|
|
substitute "${serviceLauncher}" "$TMPDIR/t3code-launcher-missing" \
|
|
--replace-fail '/run/secrets/t3code' "$TMPDIR/missing" \
|
|
--replace-fail '@t3code@' '${testT3code}'
|
|
! T3CODE_PORT=4567 ${pkgs.runtimeShell} "$TMPDIR/t3code-launcher-missing" 2>/dev/null \
|
|
|| fail "t3code's launcher must not start the server when the environment file fails to load"
|
|
''
|
|
else
|
|
''
|
|
serviceFile=home-files/.config/systemd/user/t3code.service
|
|
assertFileExists "$serviceFile"
|
|
assertFileContent "$serviceFile" ${./server-environment-file.service}
|
|
'';
|
|
}
|