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

make arguments configurable via options #81

Merged
merged 16 commits into from
Oct 14, 2024

Conversation

VanCoding
Copy link
Contributor

@VanCoding VanCoding commented Oct 1, 2024

Here I've made options for every process-compose argument there currently is.
This makes it nicer to set arguments in a modular way, and also paves the way to conditionally pass arguments to process-compose based on the subcommand (don't pass --config to the attach or downcommand for example)

For compatibility, I've remapped the tui and httpServer options to set these new options under the hood.

Also worth mentioning: The "normal" and the "test"-process use different arguments, to solve this problem I made separate "test-arguments" options, that default to the normal options.

Copy link
Member

@srid srid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful addition! Here's my initial review.

nix/process-compose-flake-lib.nix Outdated Show resolved Hide resolved
nix/lib.nix Outdated
@@ -39,6 +39,7 @@ rec {
evalModules = { name ? "process-compose", modules }: (lib.evalModules {
specialArgs = {
inherit name pkgs;
process-compose-flake-lib = (import ./process-compose-flake-lib.nix) { lib = pkgs.lib; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect a special arg like process-compose-flake-lib to point to ./nix/lib.nix. Besides, as commented elsewhere, a function like mkProcessComposeArgumentsOption seems redundant (unless I'm missing something), and that you can simply import that submodule directly for re-use.

};
sort = mkOption {
type = types.str;
default = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using empty strings (which has ambiguous meaning, since you are forced to look at the implementation to understand the semantics), we should use types.nullOr types.str as type in options like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used nullable strings in the past as well, but don't do that nowadays, except if null and "" has different meaning. In this case, it doesn't. The string being nullable only adds the burden of needing to check if it's null in addition to needing to check if it's empty. Same goes for arrays, i always default to [] instead of null for the same reasons.

But in the end it's a matter of taste and I'll follow your command.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in the end it's a matter of taste and I'll follow your command.

Ok.

@@ -70,6 +57,22 @@ in
default = true;
description = "Enable or disable the TUI for the application.";
};
arguments = process-compose-flake-lib.mkProcessComposeArgumentsOption { };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cli is simpler I think.

Suggested change
arguments = process-compose-flake-lib.mkProcessComposeArgumentsOption { };
cli = process-compose-flake-lib.mkProcessComposeArgumentsOption { };

@@ -70,6 +57,22 @@ in
default = true;
description = "Enable or disable the TUI for the application.";
};
arguments = process-compose-flake-lib.mkProcessComposeArgumentsOption { };
test-arguments = process-compose-flake-lib.mkProcessComposeArgumentsOption { };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect users to be able to set test-arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, I mainly introduced this to be able to configure the "config" argument in the same way as every other argument. And because this one depends on it being a test-process or not, I couldn't come up with another solution.

But I mean.. why not? Could be handy, no?

nix/process-compose/default.nix Show resolved Hide resolved
@VanCoding
Copy link
Contributor Author

@srid I've done the refactoring as requested, except of removing "test-arguments" (now test-cli). Additionally, I've made an optional commit which moved actually building the CLI arguments into output options, but I'm not sure if that's a good idea. I'd revert it if it was my decision :D

Copy link
Member

@srid srid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final review, hopefully!

Comment on lines 79 to 80
up = (lib.removeAttrs config.cli.up [ "output" ]) // { config = [ "${config.outputs.settingsTestFile}" ]; };
global = lib.removeAttrs config.cli.global [ "output" ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is output being removed? Can you add a comment explaining the purpose of this logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to figure this out as well. If we don't remove it we'resetting the output of test-cli to the output of the normal cli, which completely misses the point.

Comment on lines 64 to 83
config = {
cli = lib.mkMerge [{
up = {
config = [ "${config.outputs.settingsFile}" ];
tui = config.tui;
};
global = {
port = config.httpServer.port;
use-uds = config.httpServer.uds != false;
unix-socket = if builtins.isString config.httpServer.uds then config.httpServer.uds else "";
no-server = if config.httpServer.enable == true then false else true;
};
}];
test-cli = lib.mkMerge [
{
up = (lib.removeAttrs config.cli.up [ "output" ]) // { config = [ "${config.outputs.settingsTestFile}" ]; };
global = lib.removeAttrs config.cli.global [ "output" ];
}
];
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need mkMerge with singleton lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, i'd need to test it again, but with my tests it was needed. But don't ask me why, i'm no expert of how the module system works.

nix/process-compose/cli.nix Outdated Show resolved Hide resolved
nix/process-compose/cli-options.nix Outdated Show resolved Hide resolved
nix/process-compose/default.nix Outdated Show resolved Hide resolved
@VanCoding
Copy link
Contributor Author

Maybe I'll have the energy to go all over it once again, but this is already much more cumbersome than i initially thought, so i'll prioritize it a bit less.

@VanCoding
Copy link
Contributor Author

VanCoding commented Oct 6, 2024

@srid I've done another round of refactoring. I think this should account for all of your comments except for the "up" subcommand.

Sorry for the slightly negative tone of the previous command btw, I was a bit frustrated. But I'm learning a lot while doing this so it's fine :)

@srid
Copy link
Member

srid commented Oct 14, 2024

@VanCoding No worries (I didn't sense any negative tone).

Sorry I've let this PR slip by. It generally looks good to me, but I'll check it locally and give it a thorough review, push some commits and then squash merge.

Copy link
Member

@srid srid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the PR, the diff is small and it does one thing (implement most of the CLI options of process-compose, encapsulated nicely in a submodule) well.

@srid srid merged commit 4448f64 into Platonic-Systems:main Oct 14, 2024
2 checks passed
@VanCoding
Copy link
Contributor Author

@srid Nice! Thanks for merging that one in.

Regarding the subcommand topic: This is a really tricky one, and I've already had a hacky solution here: VanCoding@5b66d08

But that's also not perfect, because then the subcommand has to be the first argument. And properly parsing the arguments just for this is probably overkill, so I don't know what's the best way to approach this. I'm alreay happy if it's possible to use subcommands other than "up", which with the current solution is the case.

If it's okay for you I'll open another PR to change the ponysay example to use the "detached" mode, and add the comments as in the referenced commit above.

roberth added a commit to hercules-ci/flake.parts-website that referenced this pull request Oct 18, 2024
roberth added a commit to hercules-ci/flake.parts-website that referenced this pull request Oct 18, 2024
Culprit seems to be Platonic-Systems/process-compose-flake#81

Flake lock file updates:

• Updated input 'process-compose-flake':
    'github:Platonic-systems/process-compose-flake/29301aec92d73c9b075fcfd06a6fb18665bfe6b5?narHash=sha256-yEMzxZfy%2BEE9gSqn%2B%2BSyZeAVHXYupFT8Wyf99Z/CXXU%3D' (2024-10-14)
  → 'github:Platonic-systems/process-compose-flake/40a3d1b892e4669ac23d215ef1ab5db6e6a63136?narHash=sha256-dZHk%2BQNBTpg5V6dEXcP4paOyNCDq8YTmNjb0ICh3FdQ%3D' (2024-10-14)
@roberth
Copy link
Contributor

roberth commented Oct 18, 2024

This adds many undocumented options. Please add documentation so we can publish the docs on flake.parts.
It'd be good to have a CI check as well, although I'm surprised that this passed review without documentation.

@VanCoding
Copy link
Contributor Author

@roberth Yeah, it wasn't originally meant to be a breaking change.

Fortunately, the new options closely reflect the cli arguments of process-compose , so if you know these, you also know the options.

But it's of course even better to have these documented with all the other options, so let me know if i can help with that.

@roberth
Copy link
Contributor

roberth commented Oct 18, 2024

Links to the upstream docs would do the job just fine.

wasn't originally meant to be a breaking change.

Of course. Sorry for the grumpy mood. This looks like a nice addition actually :)

@srid
Copy link
Member

srid commented Oct 18, 2024

It'd be good to have a CI check as well,

@roberth Is there something in upstream that I can use easily in downstream module? Something as easy as say import'ing the flake-parts module.

In this particular case, though, these options need not strictly be documented due to the 1-on-1 map with upstream. However, when refactoring it1, we could add some stub docs to make flake-parts docs site check happy.

Footnotes

  1. https://github.com/Platonic-Systems/process-compose-flake/blob/29301aec92d73c9b075fcfd06a6fb18665bfe6b5/nix/process-compose/cli-options.nix#L91

@roberth
Copy link
Contributor

roberth commented Oct 19, 2024

need not strictly be documented due to the 1-on-1 map with upstream.

That's not the excuse, but the thing to document.

Is there something in upstream that I can use easily in downstream module?

nix build github:hercules-ci/flake.parts-website --override-input process-compose-flake .

say import'ing the flake-parts module.

Not feasible until NixOS/nix#7730 is implemented, except perhaps with workarounds that isolate the dependencies.
Personally I'm sick of working around that, so I'm ok with the nix build command for the time being.

@roberth
Copy link
Contributor

roberth commented Oct 19, 2024

Even better:

nix build github:hercules-ci/flake.parts-website#checks.x86_64-linux.linkcheck --override-input process-compose-flake .

The link check is very fast nowadays, thanks to the lychee project.

@srid
Copy link
Member

srid commented Oct 19, 2024

That's not reproducible. Even when I make it reproducible (srid/haskell-flake#244) it fails on when next updating flake-parts-website (why srid/haskell-flake#354 is never merged).

@srid
Copy link
Member

srid commented Oct 19, 2024

That's not the excuse, but the thing to document.

I'm not opposed to adding placeholder description to these options, but I cannot guarantee that future PRs will stick to consistent options documentation without a reliable CI check in place.

Also, it would be helpful to others to document these expectations when they are adding their module to https://github.com/hercules-ci/flake.parts-website

I'm ok with the nix build command for the time being.

I'm not comfortable with using non-reproducible commands in CI, though. #81 (comment)

@roberth
Copy link
Contributor

roberth commented Oct 19, 2024

I don't see how that wouldn't be reproducible, because everything seems to be pinned in doc/flake.lock.

That said, I wouldn't be surprised if Nix still had a bug with input overriding, and that would be another reason to implement NixOS/nix#7730. Overriding is more natural to implement in the expression language, following the usual implementation patterns for that (ie lib.fixedPoints, without actual lib).

@srid
Copy link
Member

srid commented Oct 21, 2024

I've added description to all options and added the linkCheck to CI (if the check fails in future for reasons outside of the scope of this repo, I may have to remove it)

#84

014bfa1

@roberth
Copy link
Contributor

roberth commented Oct 21, 2024

They're live again.

may have to remove it

Of course you'll be free to do so, and conversely I may have to pin it again, but until either of that happens, progress will be smoother. Thanks for adding the check!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants