diff --git a/exec.go b/exec.go index 9999607..6973404 100644 --- a/exec.go +++ b/exec.go @@ -5,7 +5,13 @@ import ( "errors" "io" "iter" + "os" "os/exec" + "time" +) + +const ( + defaultWaitDelay = 15 * time.Second ) // Nix is the name of the nix program. @@ -47,7 +53,10 @@ func New(ctx context.Context, extraArgs []string, stdout, stderr io.Writer) Cont } func (n *nix) Nix(ctx context.Context, arg ...string) *exec.Cmd { - return exec.CommandContext(ctx, n.name, append(n.extra, arg...)...) + cmd := exec.CommandContext(ctx, n.name, append(n.extra, arg...)...) + cmd.Cancel = func() error { return cmd.Process.Signal(os.Interrupt) } + cmd.WaitDelay = defaultWaitDelay + return cmd } func (n *nix) WriteStdin(cmd *exec.Cmd, installables iter.Seq[string], f func() error) (int, error) {