nixbuild/copy.go
Ophestra a3427ce7dd
context: interface command type
This should allow caller to override the method to run in a container.
2025-09-13 13:06:39 +09:00

31 lines
655 B
Go

package nix
import (
"context"
"iter"
"os"
)
// Copy copies installables to [Store].
func Copy(ctx Context, store Store, installables iter.Seq[string]) error {
if store == nil {
return os.ErrInvalid
}
c, cancel := context.WithCancel(ctx.Unwrap())
defer cancel()
cmd := ctx.Nix(c, CommandCopy,
FlagTo, store.String(),
FlagStdin)
cmd.ReplaceEnv(append(os.Environ(), store.Environ()...))
if _, ok := store.(Local); ok {
// this is required for chroot stores, but does not seem to have any effect on binary cache
cmd.AppendArgs(FlagNoCheckSigs)
}
setStreams(ctx, cmd)
_, err := ctx.WriteStdin(cmd, installables, nil)
return err
}