82 lines
3.0 KiB
Go
82 lines
3.0 KiB
Go
package nixbuild
|
||
|
||
import (
|
||
"context"
|
||
"os/exec"
|
||
)
|
||
|
||
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 won’t 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"
|
||
)
|
||
|
||
// since flakes are supposedly experimental
|
||
var nixEnableFlakes = []string{nixExtraExperimentalFeatures, nixExperimentalFeaturesFlakes}
|
||
|
||
// 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...)...)
|
||
}
|
||
|
||
const (
|
||
nixosSuffix0 = "#nixosConfigurations."
|
||
nixosSuffix1 = ".config.system.build.toplevel"
|
||
)
|
||
|
||
// NixOSInstallable returns the nixos installable for a given flake and host.
|
||
func NixOSInstallable(flake, host string) string { return flake + nixosSuffix0 + host + nixosSuffix1 }
|