-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
82f98b1
to
b0772ec
Compare
b0772ec
to
86bc80b
Compare
There was a problem hiding this 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/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; }; |
There was a problem hiding this comment.
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.
nix/process-compose-flake-lib.nix
Outdated
}; | ||
sort = mkOption { | ||
type = types.str; | ||
default = ""; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
nix/process-compose/cli.nix
Outdated
@@ -70,6 +57,22 @@ in | |||
default = true; | |||
description = "Enable or disable the TUI for the application."; | |||
}; | |||
arguments = process-compose-flake-lib.mkProcessComposeArgumentsOption { }; |
There was a problem hiding this comment.
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.
arguments = process-compose-flake-lib.mkProcessComposeArgumentsOption { }; | |
cli = process-compose-flake-lib.mkProcessComposeArgumentsOption { }; |
nix/process-compose/cli.nix
Outdated
@@ -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 { }; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final review, hopefully!
nix/process-compose/cli.nix
Outdated
up = (lib.removeAttrs config.cli.up [ "output" ]) // { config = [ "${config.outputs.settingsTestFile}" ]; }; | ||
global = lib.removeAttrs config.cli.global [ "output" ]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
nix/process-compose/cli.nix
Outdated
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" ]; | ||
} | ||
]; | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
…ptions and handle it manually
@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 :) |
@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. |
Because we use types.nullOr
Yes, this will require users to migrate that's fine.
There was a problem hiding this 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 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. |
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)
This adds many undocumented options. Please add documentation so we can publish the docs on flake.parts. |
@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. |
Links to the upstream docs would do the job just fine.
Of course. Sorry for the grumpy mood. This looks like a nice addition actually :) |
@roberth Is there something in upstream that I can use easily in downstream module? Something as easy as say 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 |
That's not the excuse, but the thing to document.
nix build github:hercules-ci/flake.parts-website --override-input process-compose-flake .
Not feasible until NixOS/nix#7730 is implemented, except perhaps with workarounds that isolate the dependencies. |
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 |
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). |
I'm not opposed to adding placeholder 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 not comfortable with using non-reproducible commands in CI, though. #81 (comment) |
I don't see how that wouldn't be reproducible, because everything seems to be pinned in 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 |
They're live again.
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! |
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 theattach
ordown
command 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.