this repo has no description
0
fork

Configure Feed

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

feat(nixos): initial install with nixos-anywhere

Needs to wire this to the API.

Khue Doan 59e2b4ef 1b9de2fb

+50 -3
+4 -3
README.md
··· 25 25 "first machine in the data center" problem: in bare-metal setups with 26 26 persistent PXE servers, you would otherwise need to automate the installation 27 27 of the PXE server itself. 28 - [^2]: Using the provided examples with a warm cache. Factors that affect the 29 - speed include whether the configuration has been cached in the Nix store, 30 - the size of the NixOS configuration, the network speed, etc. 28 + [^2]: Using the provided examples with a warm cache on a 1 Gbps network. 29 + Factors that affect the speed include whether the configuration has been 30 + cached in the Nix store, the size of the NixOS configuration, the network 31 + speed, etc. 31 32 32 33 ## Usage 33 34
+5
cmd/nixie/main.go
··· 78 78 }() 79 79 log.Info("API server started", "address", address) 80 80 81 + // TODO IMPORTANT obviously, should be API call 82 + // TODO IMPORTANT support SSH key 83 + log.Info("installing NixOS", "host", "192.168.1.8", "flake", "./examples#machine1") 84 + nixos.Install(ctx, "./examples#machine1", "root", "192.168.1.8", "nixos-installer", flags.Debug) 85 + 81 86 sigCh := make(chan os.Signal, 1) 82 87 signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) 83 88
+10
examples/flake.nix
··· 40 40 } 41 41 ]; 42 42 }; 43 + machine2 = nixpkgs.lib.nixosSystem { 44 + system = "x86_64-linux"; 45 + modules = [ 46 + disko.nixosModules.disko 47 + ./configuration.nix 48 + { 49 + networking.hostName = "machine2"; 50 + } 51 + ]; 52 + }; 43 53 }; 44 54 }; 45 55 }
+31
internal/nixos/anywhere.go
··· 1 + package nixos 2 + 3 + import ( 4 + "context" 5 + "fmt" 6 + "os" 7 + "os/exec" 8 + ) 9 + 10 + func Install(ctx context.Context, flakeRef, user, host, password string, debug bool) error { 11 + cmd := exec.CommandContext( 12 + ctx, 13 + "nixos-anywhere", 14 + "--flake", flakeRef, 15 + "--target-host", fmt.Sprintf("%s@%s", user, host), 16 + "--env-password", 17 + // In the case of PXE boot, where target machines are usually on the same LAN as the one running Nixie, 18 + // pushing from the Nix store where Nixie is running is usually faster than pulling from a remote cache over the internet. 19 + // Additionally, it's air-gapped. 20 + "--no-substitute-on-destination", 21 + ) 22 + 23 + cmd.Env = append(os.Environ(), fmt.Sprintf("SSHPASS=%s", password)) 24 + 25 + if debug { 26 + cmd.Stdout = os.Stdout 27 + cmd.Stderr = os.Stderr 28 + } 29 + 30 + return cmd.Run() 31 + }