Deployment and lifecycle management for Nix
0
fork

Configure Feed

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

client: add seed download command

+75 -25
+30 -8
client/main.go
··· 76 76 var seedCmd = &cobra.Command{ 77 77 Use: "seed", 78 78 Short: "Run seed related actions", 79 - // Run: func(cmd *cobra.Command, args []string) { 80 - // }, 79 + Run: func(cmd *cobra.Command, args []string) { 80 + fmt.Println(args) 81 + }, 81 82 } 82 83 rootCmd.AddCommand(seedCmd) 83 84 var seedDownloadCommand = &cobra.Command{ 84 85 Use: "download", 85 86 Short: "Download a seed", 86 87 Run: func(cmd *cobra.Command, args []string) { 87 - fmt.Println(args) 88 + name, err := cmd.Flags().GetString("name") 89 + if err != nil { 90 + log.Error().Err(err).Msg("Failed loading seed name") 91 + os.Exit(1) 92 + } 93 + if name == "" { 94 + name = seed.DefaultName() 95 + } 96 + 97 + seedType, err := cmd.Flags().GetString("type") 98 + if err != nil { 99 + log.Error().Err(err).Msg("Failed loading seed type") 100 + os.Exit(1) 101 + } 102 + if seedType == "" { 103 + seedType = seed.DefaultType() 104 + } 105 + 106 + wantedSeed := seed.NewSeed(name, seedType, "") 107 + 108 + if err := wantedSeed.Download(); err != nil { 109 + log.Error().Err(err).Msg("Failed downloading seed") 110 + os.Exit(1) 111 + } 88 112 }, 89 113 } 90 114 seedCmd.AddCommand(seedDownloadCommand) 91 - // seedDownloadCommand.Flags().String("name", seed.defaultName(), "seed name") 92 - // seedDownloadCommand.Flags().String("type", seed.defaultType(), "seed type") 115 + seedDownloadCommand.Flags().String("name", "", "seed name") 116 + seedDownloadCommand.Flags().String("type", "", "seed type") 93 117 94 118 if err := rootCmd.Execute(); err != nil { 95 - fmt.Println(err) 119 + log.Error().Err(err).Msg("") 96 120 os.Exit(1) 97 121 } 98 122 } ··· 185 209 log.Error().Err(err).Msg("failed to join dedicated channel") 186 210 } 187 211 188 - // seedPush, err := dedicatedChannel.Push("seed:submit", map[string]any{"name": "blank", "seed_type": "nixos", "out_path": "/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb-nixos-system-blank-24.11.20240716.ad0b5ee"}) 189 - // seed := NewSeed("blank", "nixos", "/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb-nixos-system-blank-24.11.20240716.ad0b5ee") 190 212 seed := seed.NewSeed("blank", "home-manager", "/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb-nixos-system-blank-24.11.20240716.ad0b5ee") 191 213 seedPush, err := dedicatedChannel.Push("seed:submit", seed) 192 214 if err != nil {
+45 -17
client/seed/seed.go
··· 20 20 SeedType string `json:"seed_type"` 21 21 } 22 22 23 - func NewSeed(name, seed_type, out_path string) Seed { 24 - seed := &GenericSeed{ 25 - Name: name, 26 - OutPath: out_path, 27 - SeedType: seed_type, 28 - } 29 - 30 - switch seed_type { 31 - case "nixos": 32 - return &NixosSeed{ 33 - GenericSeed: *seed, 34 - } 35 - } 36 - 37 - return seed 38 - } 39 - 40 23 func (d *GenericSeed) Activate() error { 41 24 log.Debug().Msgf("Activating seed %s", d.Name) 42 25 return nil ··· 44 27 45 28 func (d *GenericSeed) Download() error { 46 29 log.Debug().Any("seed", d).Msgf("Downloading seed") 30 + 31 + if d.OutPath == "" { 32 + return fmt.Errorf("Cannot download without seed out_path") 33 + } 47 34 48 35 cmd := exec.Command("nix-store", "--realize", d.OutPath) 49 36 ··· 90 77 log.Debug().Msg("Nixos is a different activation") 91 78 return nil 92 79 } 80 + 81 + func NewSeed(name, seed_type, out_path string) Seed { 82 + seed := &GenericSeed{ 83 + Name: name, 84 + OutPath: out_path, 85 + SeedType: seed_type, 86 + } 87 + 88 + switch seed_type { 89 + case "nixos": 90 + return &NixosSeed{ 91 + GenericSeed: *seed, 92 + } 93 + } 94 + 95 + return seed 96 + } 97 + 98 + func DefaultName() string { 99 + name := "blank" 100 + 101 + // SeedType::Nixos | SeedType::NixDarwin => nix::unistd::gethostname() 102 + // .expect("Failed getting hostname") 103 + // .into_string() 104 + // .unwrap(), 105 + // SeedType::HomeManager => env::var("USER").expect("can not detect username"), 106 + 107 + return name 108 + } 109 + 110 + func DefaultType() string { 111 + name := "nixos" 112 + 113 + // SeedType::Nixos | SeedType::NixDarwin => nix::unistd::gethostname() 114 + // .expect("Failed getting hostname") 115 + // .into_string() 116 + // .unwrap(), 117 + // SeedType::HomeManager => env::var("USER").expect("can not detect username"), 118 + 119 + return name 120 + }