(ctx context.Context, args *BuildArgs, installables ...string)
| 19 | } |
| 20 | |
| 21 | func Build(ctx context.Context, args *BuildArgs, installables ...string) error { |
| 22 | defer debug.FunctionTimer().End() |
| 23 | |
| 24 | FixInstallableArgs(installables) |
| 25 | |
| 26 | // --impure is required for allowUnfreeEnv/allowInsecureEnv to work. |
| 27 | cmd := Command("build", "--impure") |
| 28 | cmd.Args = appendArgs(cmd.Args, args.Flags) |
| 29 | cmd.Args = appendArgs(cmd.Args, installables) |
| 30 | // Adding extra substituters only here to be conservative, but this could also |
| 31 | // be added to ExperimentalFlags() in the future. |
| 32 | if len(args.ExtraSubstituters) > 0 { |
| 33 | cmd.Args = append(cmd.Args, |
| 34 | "--extra-substituters", |
| 35 | strings.Join(args.ExtraSubstituters, " "), |
| 36 | ) |
| 37 | } |
| 38 | cmd.Env = append(allowUnfreeEnv(os.Environ()), args.Env...) |
| 39 | if args.AllowInsecure { |
| 40 | slog.Debug("Setting Allow-insecure env-var\n") |
| 41 | cmd.Env = allowInsecureEnv(cmd.Env) |
| 42 | } |
| 43 | |
| 44 | // If nix build runs as tty, the output is much nicer. If we ever |
| 45 | // need to change this to our own writers, consider that you may need |
| 46 | // to implement your own nicer output. --print-build-logs flag may be useful. |
| 47 | cmd.Stdin = os.Stdin |
| 48 | cmd.Stdout = args.Writer |
| 49 | cmd.Stderr = args.Writer |
| 50 | return cmd.Run(ctx) |
| 51 | } |
no test coverage detected