@@ -21,26 +21,11 @@ type JobSpec struct {
2121 User string `json:"user"` // ssh user
2222}
2323
24- func buildClosure (flake string , spec JobSpec , builder string ) (string , error ) {
25- expr := fmt .Sprintf ("%s#%sConfigurations.%s.config.system.build.toplevel" , flake , spec .Type , spec .Output )
26- drvExpr := expr + ".drvPath"
27-
28- // Step 1: Evaluate the .drv path locally
29- data , err := runJSON ("nix" , "--extra-experimental-features" , "nix-command flakes" , "eval" , "--raw" , drvExpr )
30- if err != nil {
31- return "" , fmt .Errorf ("failed to evaluate drvPath for %s: %w" , spec .Output , err )
32- }
33- drvPath := strings .TrimSpace (string (data ))
34-
35- // Step 2: Copy the .drv closure to the remote builder (if needed)
36- if builder != "localhost" {
37- if _ , err := run ("nix" , "--extra-experimental-features" , "nix-command flakes" , "copy" , "--to" , "ssh-ng://" + builder , drvPath ); err != nil {
38- return "" , fmt .Errorf ("failed to copy .drv to %s: %w" , builder , err )
39- }
40- }
41-
42- // Step 3: Build the closure from the drv remotely or locally
24+ func buildClosure (spec JobSpec , drvPath string , builder string ) (string , error ) {
4325 var buildOut []byte
26+ var err error
27+
28+ // Build the closure locally or on the remote builder
4429 if builder != "localhost" {
4530 buildOut , err = runJSON ("nix" , "--extra-experimental-features" , "nix-command flakes" , "build" , "--no-link" , "--json" , "--store" , "ssh-ng://" + builder , drvPath + "^*" )
4631 } else {
@@ -50,7 +35,7 @@ func buildClosure(flake string, spec JobSpec, builder string) (string, error) {
5035 return "" , fmt .Errorf ("failed to build %s on %s: %w" , spec .Output , builder , err )
5136 }
5237
53- // Step 4: Parse the output path
38+ // Parse the output path
5439 var results []BuildResult
5540 if err := json .Unmarshal (buildOut , & results ); err != nil {
5641 return "" , fmt .Errorf ("invalid build JSON for %s: %w\n Raw: %s" , spec .Output , err , string (buildOut ))
@@ -113,6 +98,28 @@ func info(format string, args ...any) {
11398 fmt .Printf ("[nynx] " + format + "\n " , args ... )
11499}
115100
101+ func instantiateDrvPath (flake string , spec JobSpec , builder string ) (string , error ) {
102+ expr := fmt .Sprintf ("%s#%sConfigurations.%s.config.system.build.toplevel" , flake , spec .Type , spec .Output )
103+ drvExpr := expr + ".drvPath"
104+
105+ // Evaluate the .drv path locally
106+ data , err := runJSON ("nix" , "--extra-experimental-features" , "nix-command flakes" , "eval" , "--raw" , drvExpr )
107+ if err != nil {
108+ return "" , fmt .Errorf ("failed to evaluate drvPath for %s: %w" , spec .Output , err )
109+ }
110+
111+ drvPath := strings .TrimSpace (string (data ))
112+
113+ // Copy the .drv to the remote builder (if needed)
114+ if builder != "localhost" {
115+ if _ , err := run ("nix" , "--extra-experimental-features" , "nix-command flakes" , "copy" , "--to" , "ssh-ng://" + builder , drvPath ); err != nil {
116+ return "" , fmt .Errorf ("failed to copy .drv to %s: %w" , builder , err )
117+ }
118+ }
119+
120+ return drvPath , nil
121+ }
122+
116123func loadDeploymentSpec (cfg string ) (map [string ]JobSpec , error ) {
117124 // Nix -> JSON
118125 data , err := runJSON ("nix" , "eval" , "--json" , "-f" , cfg )
0 commit comments