summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Oleinik <[email protected]>2024-03-14 01:59:47 -0700
committerGitHub <[email protected]>2024-03-14 04:59:47 -0400
commit528943263040c9f383361b1a37a3ee4db66412af (patch)
treeff93492146018fa1df1f2cf5f7f19ce324b055ad
parentb7813d224e7630de289d587c90e444c76f3330a0 (diff)
Add support for other procfile runners (#5)
* WIP * WIP * WIP * done * done * fix CI * fix CI * refactor: default to overmind in mkProcfileRunner * module: cleanup option docs * refactor: cleanup multi-test suite --------- Co-authored-by: seth <[email protected]>
-rw-r--r--.github/workflows/ci.yaml16
-rw-r--r--.gitignore3
-rw-r--r--README.md8
-rw-r--r--default.nix19
-rw-r--r--module.nix50
-rw-r--r--test/flake.nix89
6 files changed, 142 insertions, 43 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index be0ae47..57e8d4f 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -23,6 +23,18 @@ jobs:
- name: Run test script
run: |
- set -eux
+ function catch_error() {
+ echo "Job $1 failed!"
+ exit 1
+ }
- nix develop ./test --command 'run-ci'
+ tests=(
+ "overmind"
+ "overmind-dft"
+ "honcho"
+ )
+
+ for test in "${tests[@]}"; do
+ nix develop ./test#"$test" --command 'run-ci' || catch_error "$test"
+ sleep 5 # this is to avoid race conditions with the current proc runner not exiting just yet
+ done
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5545a08
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+result*
+repl-result*
+dump.rdb
diff --git a/README.md b/README.md
index 8d1fc45..fa8cf51 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# procfile-nix
-A library + [flake-parts](https://flake.parts/) module that helps you manage procfiles and background jobs with [overmind](https://github.com/DarthSim/overmind)!
+A library + [flake-parts](https://flake.parts/) module that helps you manage procfiles and background jobs with [overmind](https://github.com/DarthSim/overmind) (or any other Procfile runner)!
## Usage
@@ -46,6 +46,9 @@ First, put this in your `flake.nix`:
procGroup = {
redis = lib.getExe' pkgs.redis "redis-server";
};
+
+ # OPTIONAL: switch the Procfile runner if desired.
+ procRunner = pkgs.honcho;
};
in {
default = pkgs.mkShell {
@@ -89,6 +92,9 @@ Then run `nix develop`, `daemons &`, and you're good to go!
}: {
procfiles.daemons.processes = {
redis = lib.getExe' pkgs.redis "redis-server";
+
+ # OPTIONAL: switch the Procfile runner if desired.
+ procRunner = pkgs.honcho;
};
devShells.default = pkgs.mkShell {
diff --git a/default.nix b/default.nix
index ad898a9..8a0e155 100644
--- a/default.nix
+++ b/default.nix
@@ -21,17 +21,32 @@ in
lib.concatLines (
lib.mapAttrsToList (name: cmd: "${name}: ${cmd}") procGroup
);
+
+ mkRunCommand = procRunner: procfile: let
+ inherit (builtins.parseDrvName procRunner.name) name;
+ default = "${lib.getExe procRunner} ${procfile}";
+ in
+ # special cases for officially supported procfile runners
+ {
+ overmind = ''overmind start -f ${procfile} --root "$PWD" "$@"'';
+ honcho = ''honcho start -f ${procfile} --app-root "$PWD" "$@"'';
+ }
+ .${name}
+ or default;
in {
mkProcfileRunner = {
name,
procGroup,
+ procRunner ? pkgs.overmind,
}:
pkgs.writeShellApplication {
inherit name;
- runtimeInputs = [pkgs.overmind];
+ runtimeInputs = [procRunner];
text = ''
set -x
- overmind start -f ${pkgs.writeText name (toProcfile procGroup)} --root "$PWD" "$@"
+ ${mkRunCommand procRunner (
+ pkgs.writeText "Procfile" (toProcfile procGroup)
+ )}
'';
};
}
diff --git a/module.nix b/module.nix
index cf243f9..8ea5cb0 100644
--- a/module.nix
+++ b/module.nix
@@ -11,6 +11,7 @@ self: {
inherit
(lib)
literalExpression
+ literalMd
mdDoc
mkOption
types
@@ -20,6 +21,7 @@ self: {
config,
name,
system,
+ pkgs,
...
}: {
options = {
@@ -34,6 +36,17 @@ self: {
'';
};
+ procRunner = mkOption {
+ type = types.package;
+ default = pkgs.overmind;
+ defaultText = literalMd "pkgs.overmind";
+ description = mdDoc ''
+ The Procfile runner to use. Officially supports: overmind, honcho.
+ If using an unsupported procRunner, the Procfile path will be passed as an argument to the procRunner.
+ '';
+ example = literalExpression "pkgs.honcho";
+ };
+
package = mkOption {
type = types.package;
description = mdDoc "Final package containing runner for Procfile";
@@ -45,27 +58,34 @@ self: {
package = self.lib.${system}.mkProcfileRunner {
inherit name;
procGroup = config.processes;
+ inherit (config) procRunner;
};
};
};
in {
options = {
- perSystem = mkPerSystemOption ({system, ...}: {
- options.procfiles = mkOption {
- type = types.attrsOf (types.submoduleWith {
- modules = [procfileSubmodule];
- specialArgs = {inherit system;};
- });
+ perSystem = mkPerSystemOption ({
+ system,
+ pkgs,
+ ...
+ }: {
+ options = {
+ procfiles = mkOption {
+ type = types.attrsOf (types.submoduleWith {
+ modules = [procfileSubmodule];
+ specialArgs = {inherit system pkgs;};
+ });
- default = {};
- description = mdDoc "Attribute set containing procfile declarations";
- example = literalExpression ''
- {
- daemons.processes = {
- redis = lib.getExe' pkgs.redis "redis-server";
- };
- }
- '';
+ default = {};
+ description = mdDoc "Attribute set containing procfile declarations";
+ example = literalExpression ''
+ {
+ daemons.processes = {
+ redis = lib.getExe' pkgs.redis "redis-server";
+ };
+ }
+ '';
+ };
};
});
};
diff --git a/test/flake.nix b/test/flake.nix
index 724fc9c..c465c0e 100644
--- a/test/flake.nix
+++ b/test/flake.nix
@@ -26,35 +26,78 @@
lib,
pkgs,
...
- }: {
- procfiles.daemons.processes = {
- redis = lib.getExe' pkgs.redis "redis-server";
- };
+ }: let
+ mkTestShell = runtimeInputs: text:
+ pkgs.mkShellNoCC {
+ packages = [
+ (pkgs.writeShellApplication {
+ name = "run-ci";
+
+ inherit runtimeInputs text;
+ })
+ ];
+ };
- devShells.default = pkgs.mkShellNoCC {
- packages = [
- (pkgs.writeShellApplication {
- name = "run-ci";
+ testScript = exe: check: kill: ''
+ set -x
- runtimeInputs = [pkgs.overmind];
+ ${exe}
+ sleep 5 # avoid race conditions
- text = ''
- set -x
+ if ${check}; then
+ echo "Processes failed to launch! Exiting with error"
+ ${kill}
+ exit 1
+ fi
- exec ${lib.getExe config.procfiles.daemons.package} &
- sleep 5 # avoid race conditions
+ ${kill}
+ echo "Process finished! Exiting as success"
+ '';
+
+ processes = {
+ redis = lib.getExe' pkgs.redis "redis-server";
+ };
+ in {
+ procfiles = {
+ # overmind as default
+ overmind-dft = {inherit processes;};
+
+ # explicit overmind
+ overmind = {
+ inherit processes;
+ procRunner = pkgs.overmind;
+ };
+
+ # honcho
+ honcho = {
+ inherit processes;
+ procRunner = pkgs.honcho;
+ };
+ };
- if ! overmind status | grep running; then
- echo "Processes failed to launch! Exiting with error"
- overmind kill
- exit 1
- fi
+ devShells = {
+ overmind-dft = mkTestShell [pkgs.overmind] (
+ testScript
+ "exec ${(lib.getExe config.procfiles.overmind-dft.package)} &"
+ "! overmind status | grep running"
+ "overmind kill"
+ );
- overmind kill
- echo "Process finished! Exiting as success"
- '';
- })
- ];
+ overmind = mkTestShell [pkgs.overmind] (
+ testScript
+ "exec ${(lib.getExe config.procfiles.overmind.package)} &"
+ "! overmind status | grep running"
+ "overmind kill"
+ );
+ honcho = mkTestShell [pkgs.honcho] (
+ testScript
+ ''
+ exec ${(lib.getExe config.procfiles.honcho.package)} & \
+ PROC_PID=$!
+ ''
+ "! ps -p \"$PROC_PID\" > /dev/null"
+ "kill -2 $PROC_PID; pkill -f \"redis\""
+ );
};
};
};