-
Notifications
You must be signed in to change notification settings - Fork 0
Enable creating "multi-watch" processes #7
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
637d478
3805e3b
a258d7a
c21cc8d
cb309af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,56 +3,126 @@ | |||||||||||||||
| pkgs, | ||||||||||||||||
| }: | ||||||||||||||||
|
|
||||||||||||||||
| { | ||||||||||||||||
| command, | ||||||||||||||||
| paths ? [ "." ], | ||||||||||||||||
| extensions ? [ ], | ||||||||||||||||
| ignore ? [ ], | ||||||||||||||||
| debounce ? null, | ||||||||||||||||
| package ? pkgs.watchexec, | ||||||||||||||||
| packages ? [ ], | ||||||||||||||||
| ... | ||||||||||||||||
| }@args: | ||||||||||||||||
|
|
||||||||||||||||
| assert lib.assertMsg (paths != [ ]) "mkWatch: 'paths' must not be empty"; | ||||||||||||||||
|
|
||||||||||||||||
| let | ||||||||||||||||
| taskModuleArgs = builtins.removeAttrs args [ | ||||||||||||||||
| "command" | ||||||||||||||||
| "paths" | ||||||||||||||||
| "extensions" | ||||||||||||||||
| "ignore" | ||||||||||||||||
| "debounce" | ||||||||||||||||
| "package" | ||||||||||||||||
| "packages" | ||||||||||||||||
| ]; | ||||||||||||||||
|
|
||||||||||||||||
| watchexecPrefix = lib.escapeShellArgs ( | ||||||||||||||||
| [ (lib.getExe package) ] | ||||||||||||||||
| ++ lib.concatMap (p: [ | ||||||||||||||||
| "--watch" | ||||||||||||||||
| p | ||||||||||||||||
| ]) paths | ||||||||||||||||
| ++ lib.optionals (extensions != [ ]) [ | ||||||||||||||||
| "--exts" | ||||||||||||||||
| (lib.concatStringsSep "," extensions) | ||||||||||||||||
| ] | ||||||||||||||||
| ++ lib.concatMap (p: [ | ||||||||||||||||
| "--ignore" | ||||||||||||||||
| p | ||||||||||||||||
| ]) ignore | ||||||||||||||||
| ++ lib.optionals (debounce != null) [ | ||||||||||||||||
| "--debounce" | ||||||||||||||||
| (toString debounce) | ||||||||||||||||
| ] | ||||||||||||||||
| ++ [ "--" ] | ||||||||||||||||
| ); | ||||||||||||||||
| watchexecCmd = "${watchexecPrefix} ${command}"; | ||||||||||||||||
| mkWatchexecCmd = | ||||||||||||||||
| { | ||||||||||||||||
| command, | ||||||||||||||||
| paths ? [ "." ], | ||||||||||||||||
| extensions ? [ ], | ||||||||||||||||
| ignore ? [ ], | ||||||||||||||||
| debounce ? null, | ||||||||||||||||
| package ? pkgs.watchexec, | ||||||||||||||||
| }: | ||||||||||||||||
| assert lib.assertMsg (paths != [ ]) "mkWatchexecCmd: 'paths' must not be empty"; | ||||||||||||||||
| let | ||||||||||||||||
| prefix = lib.escapeShellArgs ( | ||||||||||||||||
| [ (lib.getExe package) ] | ||||||||||||||||
| ++ lib.concatMap (p: [ | ||||||||||||||||
| "--watch" | ||||||||||||||||
| p | ||||||||||||||||
| ]) paths | ||||||||||||||||
| ++ lib.optionals (extensions != [ ]) [ | ||||||||||||||||
| "--exts" | ||||||||||||||||
| (lib.concatStringsSep "," extensions) | ||||||||||||||||
| ] | ||||||||||||||||
| ++ lib.concatMap (p: [ | ||||||||||||||||
| "--ignore" | ||||||||||||||||
| p | ||||||||||||||||
| ]) ignore | ||||||||||||||||
| ++ lib.optionals (debounce != null) [ | ||||||||||||||||
| "--debounce" | ||||||||||||||||
| (toString debounce) | ||||||||||||||||
|
Comment on lines
+34
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, explore the repository structure
git ls-files | head -20Repository: DeterminateSystems/up Length of output: 480 🏁 Script executed: # Find and read lib/watch.nix around lines 34-36
if [ -f lib/watch.nix ]; then
wc -l lib/watch.nix
fiRepository: DeterminateSystems/up Length of output: 83 🏁 Script executed: # Read the relevant section from lib/watch.nix
if [ -f lib/watch.nix ]; then
sed -n '30,40p' lib/watch.nix
fiRepository: DeterminateSystems/up Length of output: 292 🏁 Script executed: # Search for debounce usage in lib/process-tree.nix
if [ -f lib/process-tree.nix ]; then
rg -n "debounce" lib/process-tree.nix -A 2 -B 2
fiRepository: DeterminateSystems/up Length of output: 412 🌐 Web query:
💡 Result: The syntax for the --debounce option in watchexec is -d, --debounce , where specifies the time to wait for new events before taking action (default: 50ms). It accepts: - A unit-less value in milliseconds (e.g., 100 for 100ms). This is deprecated, will warn, and become an error in the future. - A time span value (e.g., 5sec, 20ms, 1min 30s, 30min). Example: watchexec -d 100 command or watchexec --debounce 500ms command. Setting to 0 is highly discouraged. This is from the official watchexec manual. Citations:
Add explicit Watchexec accepts unit-less debounce values as milliseconds but marks this form deprecated and will error on it in future versions. The 🔧 Proposed fix ++ lib.optionals (debounce != null) [
"--debounce"
- (toString debounce)
+ "${toString debounce}ms"
]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| ] | ||||||||||||||||
| ++ [ "--" ] | ||||||||||||||||
| ); | ||||||||||||||||
| in | ||||||||||||||||
| "${prefix} ${command}"; | ||||||||||||||||
|
|
||||||||||||||||
| mkWatch = | ||||||||||||||||
| { | ||||||||||||||||
| command, | ||||||||||||||||
| paths ? [ "." ], | ||||||||||||||||
| extensions ? [ ], | ||||||||||||||||
| ignore ? [ ], | ||||||||||||||||
| debounce ? null, | ||||||||||||||||
| package ? pkgs.watchexec, | ||||||||||||||||
| packages ? [ ], | ||||||||||||||||
| ... | ||||||||||||||||
| }@args: | ||||||||||||||||
| let | ||||||||||||||||
| taskModuleArgs = builtins.removeAttrs args [ | ||||||||||||||||
| "command" | ||||||||||||||||
| "paths" | ||||||||||||||||
| "extensions" | ||||||||||||||||
| "ignore" | ||||||||||||||||
| "debounce" | ||||||||||||||||
| "package" | ||||||||||||||||
| "packages" | ||||||||||||||||
| ]; | ||||||||||||||||
| watchexecCmd = mkWatchexecCmd { | ||||||||||||||||
| inherit | ||||||||||||||||
| command | ||||||||||||||||
| paths | ||||||||||||||||
| extensions | ||||||||||||||||
| ignore | ||||||||||||||||
| debounce | ||||||||||||||||
| package | ||||||||||||||||
| ; | ||||||||||||||||
| }; | ||||||||||||||||
| in | ||||||||||||||||
| taskModuleArgs | ||||||||||||||||
| // { | ||||||||||||||||
| raw = true; | ||||||||||||||||
| skip = true; | ||||||||||||||||
| packages = packages ++ [ package ]; | ||||||||||||||||
| command = watchexecCmd; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| mkWatchMany = | ||||||||||||||||
| { | ||||||||||||||||
| watchers, | ||||||||||||||||
| package ? pkgs.watchexec, | ||||||||||||||||
| packages ? [ ], | ||||||||||||||||
| exitMsg ? "Shutting down", | ||||||||||||||||
| ... | ||||||||||||||||
| }@args: | ||||||||||||||||
| assert lib.assertMsg (watchers != [ ]) "mkWatchMany: 'watchers' must not be empty"; | ||||||||||||||||
| let | ||||||||||||||||
| taskModuleArgs = builtins.removeAttrs args [ | ||||||||||||||||
| "watchers" | ||||||||||||||||
| "package" | ||||||||||||||||
| "packages" | ||||||||||||||||
| ]; | ||||||||||||||||
|
lucperkins marked this conversation as resolved.
|
||||||||||||||||
|
|
||||||||||||||||
| # Resolve each watcher's package (explicit > shared default). | ||||||||||||||||
| watchexecPkg = map (w: w // { package = w.package or package; }) watchers; | ||||||||||||||||
| watcherCmds = map mkWatchexecCmd watchexecPkg; | ||||||||||||||||
| watcherPackages = map (w: w.package) watchexecPkg; | ||||||||||||||||
|
|
||||||||||||||||
| command = '' | ||||||||||||||||
| pids=() | ||||||||||||||||
|
|
||||||||||||||||
| shutdown() { | ||||||||||||||||
| trap - INT TERM | ||||||||||||||||
| echo "${exitMsg}" >&2 | ||||||||||||||||
| kill "''${pids[@]}" 2>/dev/null | ||||||||||||||||
| wait "''${pids[@]}" 2>/dev/null | ||||||||||||||||
| } | ||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||||||||||||||||
| trap shutdown INT TERM | ||||||||||||||||
|
|
||||||||||||||||
| ${lib.concatMapStringsSep "\n" (c: "${c} & pids+=($!)") watcherCmds} | ||||||||||||||||
|
|
||||||||||||||||
| wait | ||||||||||||||||
| ''; | ||||||||||||||||
| in | ||||||||||||||||
| taskModuleArgs | ||||||||||||||||
| // { | ||||||||||||||||
| raw = true; | ||||||||||||||||
| skip = true; | ||||||||||||||||
| packages = lib.unique (packages ++ watcherPackages); | ||||||||||||||||
| inherit command; | ||||||||||||||||
| }; | ||||||||||||||||
| in | ||||||||||||||||
| taskModuleArgs | ||||||||||||||||
| // { | ||||||||||||||||
| raw = true; | ||||||||||||||||
| skip = true; | ||||||||||||||||
| packages = packages ++ [ package ]; | ||||||||||||||||
| command = watchexecCmd; | ||||||||||||||||
| { | ||||||||||||||||
| inherit mkWatch mkWatchMany; | ||||||||||||||||
| } | ||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.