nixbuild/build.go
Ophestra 61c6b5d78e
treewide: use internal pipe for nix command
This essentially does the same thing underneath the hood but the API is less painful to use, and it makes more sense in this use case.
2025-07-15 01:14:27 +09:00

51 lines
929 B
Go

package nixbuild
import (
"context"
"io"
"iter"
"strings"
)
// Build builds all entries yielded by installables.
func Build(ctx context.Context, installables iter.Seq[string]) error {
c, cancel := context.WithCancel(ctx)
defer cancel()
cmd := Nix(c, CommandBuild,
FlagKeepGoing, FlagNoLink, FlagStdin)
if Stdout != nil {
cmd.Stdout = Stdout
cmd.Args = append(cmd.Args, FlagPrintBuildLogs)
} else {
cmd.Args = append(cmd.Args, FlagQuiet)
}
if Stderr != nil {
cmd.Stderr = Stderr
cmd.Args = append(cmd.Args, FlagVerbose)
}
ir, iw := io.Pipe()
cmd.Stdin = ir
if err := cmd.Start(); err != nil {
return err
}
for drv := range installables {
if strings.HasSuffix(drv, ".drv") {
// this is just what nix requires now :c
drv += "^*"
}
if _, err := iw.Write([]byte(drv + "\n")); err != nil {
return err
}
}
if err := iw.Close(); err != nil {
return err
}
return cmd.Wait()
}