Skip to content

Commit

Permalink
Add a 'target' build flag, for passing a single custom target on the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Shados committed Feb 20, 2019
1 parent 27fe820 commit b3eb9cb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions morph.go
Expand Up @@ -33,6 +33,7 @@ var (
timeout int
askForSudoPasswd bool
nixBuildArg []string
nixBuildTarget string
nixBuildTargetFile string
build = buildCmd(app.Command("build", "Build machines"))
push = pushCmd(app.Command("push", "Push machines"))
Expand Down Expand Up @@ -89,6 +90,11 @@ func nixBuildArgFlag(cmd *kingpin.CmdClause) {
StringsVar(&nixBuildArg)
}

func nixBuildTargetFlag(cmd *kingpin.CmdClause) {
cmd.Flag("target", "A Nix lambda defining the build target to use instead of the default").
StringVar(&nixBuildTarget)
}

func nixBuildTargetFileFlag(cmd *kingpin.CmdClause) {
cmd.Flag("target-file", "File containing a Nix attribute set, defining build targets to use instead of the default").
HintFiles("nix").
Expand All @@ -105,6 +111,7 @@ func skipHealthChecksFlag(cmd *kingpin.CmdClause) {
func buildCmd(cmd *kingpin.CmdClause) *kingpin.CmdClause {
selectorFlags(cmd)
nixBuildArgFlag(cmd)
nixBuildTargetFlag(cmd)
nixBuildTargetFileFlag(cmd)
deploymentArg(cmd)
return cmd
Expand Down Expand Up @@ -477,6 +484,8 @@ func buildHosts(hosts []nix.Host) (resultPath string, err error) {
if path, err := filepath.Abs(nixBuildTargetFile); err == nil {
nixBuildTargets = fmt.Sprintf("import \"%s\"", path)
}
} else if nixBuildTarget != "" {
nixBuildTargets = fmt.Sprintf("{ \"out\" = %s; }", nixBuildTarget)
}
resultPath, err = nix.BuildMachines(evalMachinesPath, deploymentPath, hosts, nixBuildArg, nixBuildTargets)
if err != nil {
Expand Down

0 comments on commit b3eb9cb

Please sign in to comment.