From 9cd9e240e09ad10dd22eb8a681983460a080bb80 Mon Sep 17 00:00:00 2001 From: Sander van der Burg Date: Thu, 4 Feb 2021 19:56:45 +0100 Subject: [PATCH] Introduce NIXPROC_PROCESS environment variable to more easily rebuild the same configuration --- tools/bsdrc/nixproc-bsdrc-switch.in | 6 +++--- tools/common/nixproc-build.in | 17 +++++++++++------ tools/commonchecks | 13 ++++++++++++- tools/cygrunsrv/nixproc-cygrunsrv-switch.in | 6 +++--- tools/disnix/nixproc-disnix-switch.in | 6 +++--- tools/docker/nixproc-docker-switch.in | 6 +++--- tools/idassign/nixproc-id-assign.in | 9 +++++++-- tools/launchd/nixproc-launchd-switch.in | 4 ++-- tools/s6-rc/nixproc-s6-rc-switch.in | 4 ++-- .../nixproc-supervisord-deploy-stateless.in | 6 ++++-- tools/supervisord/nixproc-supervisord-switch.in | 4 ++-- tools/systemd/nixproc-systemd-switch.in | 4 ++-- tools/sysvinit/nixproc-sysvinit-switch.in | 6 +++--- 13 files changed, 57 insertions(+), 34 deletions(-) diff --git a/tools/bsdrc/nixproc-bsdrc-switch.in b/tools/bsdrc/nixproc-bsdrc-switch.in index 915ec0f..4a080a3 100644 --- a/tools/bsdrc/nixproc-bsdrc-switch.in +++ b/tools/bsdrc/nixproc-bsdrc-switch.in @@ -7,7 +7,7 @@ shopt -s nullglob showUsage() { cat <&2 exit 1 fi -else - exprFile="$(@readlink@ -f "$1")" + exprFileArg="--argstr exprFile $exprFile" fi diff --git a/tools/commonchecks b/tools/commonchecks index 157b9c8..318383c 100644 --- a/tools/commonchecks +++ b/tools/commonchecks @@ -24,6 +24,17 @@ checkProfile() profile=${profile:-processes} } +checkProcessesFile() +{ + if [ "$1" != "" ] + then + processesFile="$1" + elif [ "$NIXPROC_PROCESSES" != "" ] + then + processesFile="$NIXPROC_PROCESSES" + fi +} + buildProfile() { local processManager="$1" @@ -32,7 +43,7 @@ buildProfile() then local deployArg="--undeploy" else - local deployArg="$path" + local deployArg="$processesFile" fi profilePath=$(nixproc-build --process-manager $processManager $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $cacheDirArg $forceDisableUserChangeArg $showTraceArg "${extraParamsArg[@]}" --no-out-link $deployArg) diff --git a/tools/cygrunsrv/nixproc-cygrunsrv-switch.in b/tools/cygrunsrv/nixproc-cygrunsrv-switch.in index 57dde39..77675a2 100644 --- a/tools/cygrunsrv/nixproc-cygrunsrv-switch.in +++ b/tools/cygrunsrv/nixproc-cygrunsrv-switch.in @@ -5,7 +5,7 @@ shopt -s nullglob showUsage() { cat <&2 exit 1 fi - if [ "$processesFile" = "" ] then echo "A processes Nix expression must be provided!" >&2 diff --git a/tools/launchd/nixproc-launchd-switch.in b/tools/launchd/nixproc-launchd-switch.in index f34df54..4f70bd6 100644 --- a/tools/launchd/nixproc-launchd-switch.in +++ b/tools/launchd/nixproc-launchd-switch.in @@ -55,6 +55,7 @@ Environment: NIX_STATE_DIR Overrides the location of the Nix state directory LAUNCHD_TARGET_DIR Directory in which the plist configuration files are managed (defaults to: /Library/LaunchDaemons) + NIXPROC_PROCESSES Path to a processes model NIXPROC_STATE_DIR Changes the directory in which the state of the processes is stored NIXPROC_RUNTIME_DIR Changes the directory in which the PID files are stored @@ -147,12 +148,11 @@ done shift -path="$1" - # Validate the given options source @commonchecks@ +checkProcessesFile "$1" checkNixStateDir checkProfile composeProfileBaseDir diff --git a/tools/s6-rc/nixproc-s6-rc-switch.in b/tools/s6-rc/nixproc-s6-rc-switch.in index 3f3998e..8b4bd34 100644 --- a/tools/s6-rc/nixproc-s6-rc-switch.in +++ b/tools/s6-rc/nixproc-s6-rc-switch.in @@ -50,6 +50,7 @@ Options: Environment: NIX_STATE_DIR Overrides the location of the Nix state directory + NIXPROC_PROCESSES Path to a processes model NIXPROC_STATE_DIR Changes the directory in which the state of the processes is stored NIXPROC_RUNTIME_DIR Changes the directory in which the PID files are stored @@ -142,12 +143,11 @@ done shift -path="$1" - # Validate the given options source @commonchecks@ +checkProcessesFile "$1" checkNixStateDir checkProfile composeProfileBaseDir diff --git a/tools/supervisord/nixproc-supervisord-deploy-stateless.in b/tools/supervisord/nixproc-supervisord-deploy-stateless.in index 8c6f2ca..26440c3 100644 --- a/tools/supervisord/nixproc-supervisord-deploy-stateless.in +++ b/tools/supervisord/nixproc-supervisord-deploy-stateless.in @@ -93,10 +93,12 @@ done shift -path="$1" +source @commonchecks@ + +checkProcessesFile "$1" # Build the environment with supervisord config files -profilePath=$(nixproc-build --process-manager supervisord $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $cacheDirArg $forceDisableUserChangeArg $showTraceArg "${extraParamsArg[@]}" --no-out-link "$path") +profilePath=$(nixproc-build --process-manager supervisord $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $cacheDirArg $forceDisableUserChangeArg $showTraceArg "${extraParamsArg[@]}" --no-out-link "$processesFile") # Initialize all state nixproc-init-state $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $cacheDirArg $forceDisableUserChangeArg diff --git a/tools/supervisord/nixproc-supervisord-switch.in b/tools/supervisord/nixproc-supervisord-switch.in index f0e024a..9a30c08 100644 --- a/tools/supervisord/nixproc-supervisord-switch.in +++ b/tools/supervisord/nixproc-supervisord-switch.in @@ -58,6 +58,7 @@ Options: Environment: NIX_STATE_DIR Overrides the location of the Nix state directory SUPERVISORD_CONF_DIR Directory if which the supervisord.conf resides + NIXPROC_PROCESSES Path to a processes model NIXPROC_STATE_DIR Changes the directory in which the state of the processes is stored NIXPROC_RUNTIME_DIR Changes the directory in which the PID files are stored @@ -150,12 +151,11 @@ done shift -path="$1" - # Validate the given options source @commonchecks@ +checkProcessesFile "$1" checkNixStateDir checkProfile composeProfileBaseDir diff --git a/tools/systemd/nixproc-systemd-switch.in b/tools/systemd/nixproc-systemd-switch.in index b41dab3..b448c58 100644 --- a/tools/systemd/nixproc-systemd-switch.in +++ b/tools/systemd/nixproc-systemd-switch.in @@ -57,6 +57,7 @@ Environment: SYSTEMD_TARGET_DIR Directory in which the unit configuration files are managed (defaults to: /etc/systemd/system or ~/.config/systemd/user) + NIXPROC_PROCESSES Path to a processes model NIXPROC_STATE_DIR Changes the directory in which the state of the processes is stored NIXPROC_RUNTIME_DIR Changes the directory in which the PID files are stored @@ -152,12 +153,11 @@ done shift -path="$1" - # Validate the given options source @commonchecks@ +checkProcessesFile "$1" checkNixStateDir checkProfile composeProfileBaseDir diff --git a/tools/sysvinit/nixproc-sysvinit-switch.in b/tools/sysvinit/nixproc-sysvinit-switch.in index 3e03665..89623e0 100644 --- a/tools/sysvinit/nixproc-sysvinit-switch.in +++ b/tools/sysvinit/nixproc-sysvinit-switch.in @@ -7,7 +7,7 @@ shopt -s nullglob showUsage() { cat <