Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore old CLI behaviour, while retaining global options added recently #84

Merged
merged 13 commits into from
Oct 21, 2024
8 changes: 7 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- main
pull_request:
jobs:
checks:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -16,3 +16,9 @@ jobs:
- name: Install omnix
run: nix --accept-flake-config profile install "github:juspay/omnix"
- run: om ci
flake-parts-linkCheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- run: nix build github:hercules-ci/flake.parts-website#checks.x86_64-linux.linkcheck --override-input process-compose-flake .
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
## Unreleased

- New features
- #81: Complete support for specifying process-compose CLI options (global and `up` subcommand arguments)
- **Breaking change**: Old options `httpServer` and `tui` were removed; users should use the new `cli` module to set all process-compose cli arguments and options.
- #81, #84: Support for specifying process-compose global CLI options
- **Breaking changes**:
- `preHook` and `postHook` are now inside `cli` module.
- Old options `httpServer` and `tui` were removed; users should use the new `cli` module to set all process-compose cli global options. TUI can be disabled using `cli.environment.PC_DISABLE_TUI = true;`
- ~~#18: Add `testScript` option for adding flake checks based on nixosTest library.~~
- #39: Allow `test` process to act as a test, which then gets run as part of flake checks.
- #55: Add `lib` flake output - library of useful functions
- #80: Add `evalModules`, to use process-compose-flake without flake-parts
- New options
- #52: Add `is_foreground` option
- ~~#54: Add `apiServer` option to control REST API server~~
- $60: Add `httpServer.{enable, port, uds}` options to control the HTTP server.
- ~~$60: Add `httpServer.{enable, port, uds}` options to control the HTTP server.~~
- #56: Add `preHook` and `postHook` for running commands before and after launching process-compose respectively.
- #67: Add `ready_log_line`
- #226: Add `availability.exit_on_skipped`
Expand Down
8 changes: 2 additions & 6 deletions example/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@
in
{
cli = {
# environment.PC_DISABLE_TUI = true;
# Global options for `process-compose`
global = {
options = {
no-server = true;
};
# Options for `process-compose up`
up = {
disable-dotenv = true;
theme = "Cobalt";
};
};
settings = {
environment = {
Expand Down
8 changes: 6 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ doc-static:
nix build ./doc

# Run example, using current process-compose
ex:
cd ./example && nix run --override-input process-compose-flake ..
ex *ARGS:
cd ./example && nix run --override-input process-compose-flake .. . -- {{ARGS}}

# Run example's test
ex-check:
cd ./example && nix flake check -L --override-input process-compose-flake ..
125 changes: 0 additions & 125 deletions nix/process-compose/cli-options.nix

This file was deleted.

94 changes: 90 additions & 4 deletions nix/process-compose/cli.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{ lib, ... }:

{ lib, config, options, ... }:
let
inherit (lib) types mkOption;
in
{
options =
{
options = {
cli = {
preHook = mkOption {
type = types.lines;
default = "";
Expand All @@ -16,5 +15,92 @@ in
default = "";
description = "Shell commands to run after process-compose completes.";
};
environment = mkOption {
default = { };
description = "Environment variables to pass to process-compose binary.";
type = types.submodule {
options = {
PC_DISABLE_TUI = mkOption {
type = types.nullOr types.bool;
default = null;
description = "Disable the TUI (Text User Interface) of process-compose";
};
};
};
};
options = mkOption {
description = "CLI options to pass to process-compose binary";
default = { };
type = types.submodule {
options = {
log-file = mkOption {
type = types.nullOr types.str;
default = null;
description = "Pass --log-file to process-compose";
};
no-server = mkOption {
type = types.bool;
default = false;
description = "Pass --no-server to process-compose";
};
ordered-shutdown = mkOption {
type = types.bool;
default = false;
description = "Pass --ordered-shutdown to process-compose";
};
port = mkOption {
type = types.nullOr types.int;
default = null;
description = "Pass --port to process-compose";
};
read-only = mkOption {
type = types.bool;
default = false;
description = "Pass --read-only to process-compose";
};
unix-socket = mkOption {
type = types.nullOr types.str;
default = null;
description = "Pass --unix-socket to process-compose";
};
use-uds = mkOption {
type = types.bool;
default = false;
description = "Pass --use-uds to process-compose";
};
};
};
};

# The final CLI arguments we will pass to process-compose binary.
outputs = {
# TODO: We should refactor this to generically iterate on options and produce the CLI automatically using naming conventions and types.
options = lib.mkOption {
type = types.str;
readOnly = true;
description = "The final CLI arguments we will pass to process-compose binary.";
default = let o = config.cli.options; in lib.escapeShellArgs (
(lib.optionals (o.log-file != null) [ "--log-file" o.log-file ])
++ (lib.optionals o.no-server [ "--no-server" ])
++ (lib.optionals o.ordered-shutdown [ "--ordered-shutdown" ])
++ (lib.optionals (o.port != null) [ "--port" "${builtins.toString o.port}" ])
++ (lib.optionals o.read-only [ "--read-only" ])
++ (lib.optionals (o.unix-socket != null) [ "--unix-socket" o.unix-socket ])
++ (lib.optionals o.use-uds [ "--use-uds" ])
);
};

environment = lib.mkOption {
type = types.str;
description = "Shell script prefix setting environment variables";
readOnly = true;
default =
lib.concatStringsSep " " (lib.mapAttrsToList
(name: value:
if value == null then "" else "${name}=${builtins.toJSON value}")
config.cli.environment);
};
};
};
};
}
28 changes: 7 additions & 21 deletions nix/process-compose/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ in
{
imports = [
./cli.nix
./cli-options.nix
./settings
./test.nix
];
Expand Down Expand Up @@ -38,25 +37,18 @@ in

config.outputs =
let
mkProcessComposeWrapper = { name, cliOutputs, configFile, preHook, postHook, }:
mkProcessComposeWrapper = { name, configFile }:
pkgs.writeShellApplication {
inherit name;
runtimeInputs = [ config.package ];
text = ''
${preHook}
${config.cli.preHook}

run-process-compose () {
set -x; process-compose ${cliOutputs.global} --config ${configFile} "$@"; set +x
}

# Run `up` command, with arguments; unless the user wants to pass their own subcommand.
if [ "$#" -eq 0 ]; then
run-process-compose up ${cliOutputs.up}
else
run-process-compose "$@"
fi
set -x
${config.cli.outputs.environment} PC_CONFIG_FILES=${configFile} process-compose ${config.cli.outputs.options} "$@"
set +x

${postHook}
${config.cli.postHook}
'';
};
in
Expand All @@ -65,19 +57,13 @@ in
mkProcessComposeWrapper
{
inherit name;
inherit (config) preHook postHook;
cliOutputs = config.cli.outputs;
configFile = config.outputs.settingsFile;
};
testPackage =
if
(builtins.hasAttr "test" config.settings.processes)
then
if (builtins.hasAttr "test" config.settings.processes) then
mkProcessComposeWrapper
{
name = "${name}-test";
inherit (config) preHook postHook;
cliOutputs = config.cli.outputs;
configFile = config.outputs.settingsTestFile;
}
else null;
Expand Down
7 changes: 3 additions & 4 deletions nix/process-compose/settings/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ in
# evaluate it again and to get rid of it.
in
lib.pipe attrs [ f f ];
toPCJson = attrs:
toPCJson = name: attrs:
pkgs.writeTextFile {
name = "process-compose-${name}.json";
text = builtins.toJSON attrs;
};
in
{
settingsFile = toPCJson (removeNullAndEmptyAttrs config.settings);
settingsTestFile = toPCJson (removeNullAndEmptyAttrs
settingsFile = toPCJson name (removeNullAndEmptyAttrs config.settings);
settingsTestFile = toPCJson "${name}-test" (removeNullAndEmptyAttrs
(lib.updateManyAttrsByPath [
{
path = [ "processes" "test" ];
Expand All @@ -144,4 +144,3 @@ in
config.settings));
};
}