@@ -156,7 +156,7 @@ func runJSON(cmd string, args ...string) ([]byte, error) {
156156 return out , nil
157157}
158158
159- func validateJobs (jobs map [string ]JobSpec ) (map [string ]JobSpec , error ) {
159+ func validateJobs (jobs map [string ]JobSpec , flake string ) (map [string ]JobSpec , error ) {
160160 validated := make (map [string ]JobSpec )
161161
162162 for name , spec := range jobs {
@@ -167,12 +167,30 @@ func validateJobs(jobs map[string]JobSpec) (map[string]JobSpec, error) {
167167 }
168168
169169 if spec .Output == "" {
170- return nil , fmt .Errorf ("unsupported system type '%s' for job: %s" , spec .Type , name )
171-
170+ return nil , fmt .Errorf ("missing 'output' for job: %s" , name )
172171 }
173172
174173 if spec .User == "" {
175- return nil , fmt .Errorf ("missing user for job: %s" , name )
174+ return nil , fmt .Errorf ("missing 'user' for job: %s" , name )
175+ }
176+
177+ // Infer Type if missing
178+ if spec .Type == "" {
179+ expr := fmt .Sprintf ("%s#nynxDeployments.%s.output.system" , flake , name )
180+ data , err := run ("nix" , "--extra-experimental-features" , "nix-command flakes" , "eval" , "--raw" , expr )
181+ if err != nil {
182+ return nil , fmt .Errorf ("failed to infer type for job '%s': %w" , name , err )
183+ }
184+ system := strings .TrimSpace (string (data ))
185+
186+ switch {
187+ case strings .Contains (system , "darwin" ):
188+ spec .Type = "darwin"
189+ case strings .Contains (system , "linux" ):
190+ spec .Type = "nixos"
191+ default :
192+ return nil , fmt .Errorf ("could not infer system type for job '%s' from system '%s'" , name , system )
193+ }
176194 }
177195
178196 if spec .Type != "nixos" && spec .Type != "darwin" {
0 commit comments