nixbuild/context.go
Yonah 69c6128ff5
exec: replace global state with interface
This is cleaner, and finally enables writing tests for the nix invoking functions.
2025-07-18 13:40:46 +09:00

23 lines
679 B
Go

package nixbuild
import (
"context"
"io"
"iter"
"os/exec"
)
// Context holds configuration and environment information for interacting with nix.
type Context interface {
// Streams returns the stdout and stderr writers held by this [Context].
Streams() (stdout, stderr io.Writer)
// Nix returns the [exec.Cmd] struct to execute a nix command.
Nix(ctx context.Context, arg ...string) *exec.Cmd
// WriteStdin calls [WriteStdin] for [exec.Cmd]. The function f points to is called if [WriteStdin] succeeds.
WriteStdin(cmd *exec.Cmd, installables iter.Seq[string], f func() error) (int, error)
// Unwrap returns the stored [context.Context]
Unwrap() context.Context
}