format: nix command constants

This commit is contained in:
Yonah 2025-07-14 21:45:55 +09:00
parent 36430a77d2
commit ba94989895
Signed by: yonah
SSH Key Fingerprint: SHA256:vnQvK8+XXH9Tbni2AV1a/8qdVK/zPcXw52GM0ruQvwA
2 changed files with 59 additions and 5 deletions

View File

@ -6,6 +6,60 @@ import (
)
const (
// CommandBuild build a derivation or fetch a store path
CommandBuild = "build"
// FlagDryRun show what this command would do without doing it.
FlagDryRun = "--dry-run"
// FlagJson produce output in JSON format, suitable for consumption by another program.
FlagJson = "--json"
// FlagNoLink do not create symlinks to the build results.
FlagNoLink = "--no-link"
// FlagOutLink use path as prefix for the symlinks to the build results. It defaults to result.
FlagOutLink = "--out-link"
// FlagPrintOutPaths print the resulting output paths
FlagPrintOutPaths = "--print-out-paths"
// FlagProfile the profile to operate on.
FlagProfile = "--profile"
// FlagRebuild rebuild an already built package and compare the result to the existing store paths.
FlagRebuild = "--rebuild"
// FlagStdin read installables from the standard input. No default installable applied.
FlagStdin = "--stdin"
// FlagDebug set the logging verbosity level to 'debug'.
FlagDebug = "--debug"
// FlagLogFormat set the format of log output; one of raw, internal-json, bar or bar-with-logs.
FlagLogFormat = "--log-format"
// FlagPrintBuildLogs print full build logs on standard error.
FlagPrintBuildLogs = "--print-build-logs"
// FlagQuiet decrease the logging verbosity level.
FlagQuiet = "--quiet"
// FlagVerbose increase the logging verbosity level.
FlagVerbose = "--verbose"
// FlagOffline disable substituters and consider all previously downloaded files up-to-date.
FlagOffline = "--offline"
// FlagOption set the Nix configuration setting name to value (overriding nix.conf).
FlagOption = "--option"
// FlagRefresh consider all previously downloaded files out-of-date.
FlagRefresh = "--refresh"
// FlagRepair during evaluation, rewrite missing or corrupted files in the Nix store. During building, rebuild missing or corrupted store paths.
FlagRepair = "--repair"
// FlagVersion show version information.
FlagVersion = "--version"
// OptionEvalCache whether to use the flake evaluation cache.
// Certain commands wont have to evaluate when invoked for the second time with a particular version of a flake.
// Intermediate results are not cached.
OptionEvalCache = "eval-cache"
ValueTrue = "true"
ValueFalse = "false"
)
const (
nix = "nix"
nixExtraExperimentalFeatures = "--extra-experimental-features"
nixExperimentalFeaturesFlakes = "nix-command flakes"
)
@ -15,7 +69,7 @@ var nixEnableFlakes = []string{nixExtraExperimentalFeatures, nixExperimentalFeat
// Nix returns the [exec.Cmd] struct to execute a nix command.
func Nix(ctx context.Context, arg ...string) *exec.Cmd {
return exec.CommandContext(ctx, "nix", append(nixEnableFlakes, arg...)...)
return exec.CommandContext(ctx, nix, append(nixEnableFlakes, arg...)...)
}
const (

View File

@ -149,13 +149,13 @@ func (e *InstantiatedEvaluator) Err() error {
func NewInstantiatedEvaluator(ctx context.Context, installable string) (*InstantiatedEvaluator, error) {
c, cancel := context.WithCancel(ctx)
e := &InstantiatedEvaluator{
cmd: Nix(c, "build", installable,
cmd: Nix(c, CommandBuild, installable,
// 'instantiated' messages are only emitted when actually evaluating something
"--option", "eval-cache", "false",
FlagOption, OptionEvalCache, ValueFalse,
// do not actually build anything
"--dry-run",
FlagDryRun,
// increase verbosity so nix outputs 'instantiated' messages
"-Lvvv",
FlagPrintBuildLogs, FlagDebug,
),
cancel: cancel,
}