]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Add dry-run patch for morph
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 24 Oct 2020 08:49:21 +0000 (10:49 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 24 Oct 2020 08:49:21 +0000 (10:49 +0200)
nixops/Makefile
overlays/morph/default.nix
overlays/morph/dry-run.patch [new file with mode: 0644]

index 0bebaf8202ebaec529a9ec2c9d26e0f766fe8dd9..cefd677a056c04dbcc5519b7f953ad8efded1d8b 100644 (file)
@@ -46,6 +46,9 @@ debug:
 build:
        ./scripts/with_env morph build default.nix $(MORPH_ARGS)
 
+dry-run:
+       ./scripts/with_env morph build --dry-run default.nix $(MORPH_ARGS)
+
 upload:
        ./scripts/with_env morph push default.nix $(MORPH_ARGS)
 
index ee59e2597b5f2eb9a8c2d09d2cdead486b0271ea..448f0515003e74a520e34e0cc69c5eb63a9c2481 100644 (file)
@@ -1,5 +1,5 @@
 self: super: {
   morph = super.morph.overrideAttrs(old: {
-    patches = (old.patches or []) ++ [ ./verbose_nix.patch ];
+    patches = (old.patches or []) ++ [ ./verbose_nix.patch ./dry-run.patch ];
   });
 }
diff --git a/overlays/morph/dry-run.patch b/overlays/morph/dry-run.patch
new file mode 100644 (file)
index 0000000..2ff099e
--- /dev/null
@@ -0,0 +1,59 @@
+diff --git a/morph.go b/morph.go
+index a88414b..e5894df 100644
+--- a/morph.go
++++ b/morph.go
+@@ -542,6 +542,7 @@ func getNixContext() *nix.NixContext {
+       return &nix.NixContext{
+               EvalMachines:    filepath.Join(assetRoot, assets.Friendly, "eval-machines.nix"),
+               ShowTrace:       showTrace,
++              DryRun:          *dryRun,
+               KeepGCRoot:      *keepGCRoot,
+               AllowBuildShell: *allowBuildShell,
+       }
+@@ -574,8 +575,10 @@ func buildHosts(hosts []nix.Host) (resultPath string, err error) {
+               return
+       }
+-      fmt.Fprintln(os.Stderr, "nix result path: ")
+-      fmt.Println(resultPath)
++      if resultPath != "" {
++              fmt.Fprintln(os.Stderr, "nix result path: ")
++              fmt.Println(resultPath)
++      }
+       return
+ }
+diff --git a/nix/nix.go b/nix/nix.go
+index 6a9cfd5..0f7884b 100644
+--- a/nix/nix.go
++++ b/nix/nix.go
+@@ -49,6 +49,7 @@ type Deployment struct {
+ type NixContext struct {
+       EvalMachines    string
+       ShowTrace       bool
++      DryRun          bool
+       KeepGCRoot      bool
+       AllowBuildShell bool
+ }
+@@ -269,6 +270,10 @@ func (ctx *NixContext) BuildMachines(deploymentPath string, hosts []Host, nixArg
+               args = append(args, "--show-trace")
+       }
++      if ctx.DryRun {
++              args = append(args, "--dry-run")
++      }
++
+       if nixBuildTargets != "" {
+               args = append(args,
+                       "--arg", "buildTargets", nixBuildTargets)
+@@ -308,6 +313,10 @@ func (ctx *NixContext) BuildMachines(deploymentPath string, hosts []Host, nixArg
+               return resultPath, errors.New(errorMessage)
+       }
++      if ctx.DryRun {
++              return "", err
++      }
++
+       resultPath, err = os.Readlink(resultLinkPath)
+       if err != nil {
+               return "", err