Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

client-go: initial realization support

+47 -3
+3 -1
client-go/main.go
··· 138 138 seedPush.Receive("ok", func(response any) { 139 139 seed_id := response.(map[string]interface{})["seed_id"].(string) 140 140 log.Info().Any("seed", seed).Str("seed_id", seed_id).Msgf("Received seed id") 141 - seed.Activate() 141 + if err := seed.Download(); err != nil { 142 + log.Error().Err(err).Msg("") 143 + } 142 144 }) 143 145 144 146 select {}
+44 -2
client-go/seed.go
··· 1 1 package main 2 2 3 - import "github.com/rs/zerolog/log" 3 + import ( 4 + "fmt" 5 + "io" 6 + "os" 7 + "os/exec" 8 + 9 + "github.com/rs/zerolog/log" 10 + ) 4 11 5 12 type Seed interface { 6 13 Activate() error ··· 37 44 } 38 45 39 46 func (d *GenericSeed) Download() error { 40 - log.Debug().Msgf("Downloading seed %s", d.Name) 47 + log.Debug().Any("seed", d).Msgf("Downloading seed") 48 + 49 + cmd := exec.Command("nix-store", "--realize", d.OutPath) 50 + 51 + // Set up the pipes for stdout and stderr 52 + stdout, err := cmd.StdoutPipe() 53 + if err != nil { 54 + return fmt.Errorf("Error creating StdoutPipe: %v", err) 55 + } 56 + stderr, err := cmd.StderrPipe() 57 + if err != nil { 58 + return fmt.Errorf("Error creating StderrPipe: %v", err) 59 + } 60 + 61 + err = cmd.Start() 62 + if err != nil { 63 + return fmt.Errorf("Error starting command: %v", err) 64 + } 65 + 66 + var ioErr error 67 + go func() { 68 + io.Copy(os.Stdout, stdout) // Redirect stdout to terminal's stdout 69 + }() 70 + go func() { 71 + io.Copy(os.Stderr, stderr) // Redirect stderr to terminal's stderr 72 + }() 73 + 74 + err = cmd.Wait() 75 + if err != nil { 76 + return fmt.Errorf("Failed to download seed: %v", err) 77 + } 78 + 79 + if ioErr != nil { 80 + return fmt.Errorf("Error copying output: %v", ioErr) 81 + } 82 + 41 83 return nil 42 84 } 43 85