Compare commits

...

10 Commits
main ... nixos

Author SHA1 Message Date
Cadey Ratio f0ed071618 enable cloud init
Signed-off-by: Christine Dodrill <me@christine.website>
2021-05-17 21:29:37 -04:00
Cadey Ratio 984508b295 lol oops x3
Signed-off-by: Christine Dodrill <me@christine.website>
2021-05-17 21:28:20 -04:00
Cadey Ratio 3a7506c30d openstack is banned
Signed-off-by: Christine Dodrill <me@christine.website>
2021-05-17 21:20:41 -04:00
Cadey Ratio b89eeaea6e enable ssh lol
Signed-off-by: Christine Dodrill <me@christine.website>
2021-05-17 21:17:29 -04:00
Cadey Ratio dd322d7f91 write a fake cloud config i guess
Signed-off-by: Christine Dodrill <me@christine.website>
2021-05-17 21:14:27 -04:00
Cadey Ratio 89e4f8af71 oops lol
Signed-off-by: Christine Dodrill <me@christine.website>
2021-05-17 21:11:01 -04:00
Cadey Ratio 555d35e340 openstack?
Signed-off-by: Christine Dodrill <me@christine.website>
2021-05-17 20:54:05 -04:00
Cadey Ratio 4b03ce4078 oops
Signed-off-by: Christine Dodrill <me@christine.website>
2021-05-17 20:50:23 -04:00
Cadey Ratio c3c0d86f9a does this work lol
Signed-off-by: Christine Dodrill <me@christine.website>
2021-05-17 20:48:56 -04:00
Cadey Ratio 6c6b4146dc build nixos
Signed-off-by: Christine Dodrill <me@christine.website>
2021-05-17 20:43:53 -04:00
4 changed files with 86 additions and 12 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.qcow2

56
main.go
View File

@ -44,6 +44,16 @@ func main() {
rand.Seed(time.Now().Unix())
flag.Parse()
cdir, err := os.UserCacheDir()
if err != nil {
log.Fatalf("can't find cache dir: %v", err)
}
cdir = filepath.Join(cdir, "within", "mkvm")
os.MkdirAll(filepath.Join(cdir, "nixos"), 0755)
os.MkdirAll(filepath.Join(cdir, "qcow2"), 0755)
os.MkdirAll(filepath.Join(cdir, "seed"), 0755)
vmID := uuid.New().String()
if *name == "" {
commonBladeName, err := getName()
if err != nil {
@ -59,6 +69,18 @@ func main() {
var resultDistro Distro
var found bool
qcowPath := filepath.Join(cdir, "nixos", vmID, "nixos.qcow2")
if *distro == "nixos" {
found = true
resultDistro = Distro{
Name: "nixos",
DownloadURL: "file://" + qcowPath,
Sha256Sum: "<computed after build>",
MinSize: 8,
}
}
for _, d := range distros {
if d.Name == *distro {
found = true
@ -78,7 +100,11 @@ func main() {
}
os.Exit(1)
}
zvol := filepath.Join(*zvolPrefix, *name)
if resultDistro.Name != "nixos" {
qcowPath = filepath.Join(cdir, "qcow2", resultDistro.Sha256Sum)
}
macAddress, err := randomMac()
if err != nil {
@ -90,8 +116,6 @@ func main() {
log.Fatalf("can't connect to libvirt: %v", err)
}
vmID := uuid.New().String()
log.Println("plan:")
log.Printf("name: %s", *name)
log.Printf("zvol: %s (%d GB)", zvol, *zvolSize)
@ -108,14 +132,13 @@ func main() {
fmt.Print("press enter if this looks okay: ")
reader.ReadString('\n')
cdir, err := os.UserCacheDir()
if err != nil {
log.Fatalf("can't find cache dir: %v", err)
if *distro == "nixos" {
_, err := mkNixOSImage(*cloudConfig, cdir, vmID)
if err != nil {
log.Fatal(err)
}
}
cdir = filepath.Join(cdir, "within", "mkvm")
os.MkdirAll(filepath.Join(cdir, "qcow2"), 0755)
os.MkdirAll(filepath.Join(cdir, "seed"), 0755)
qcowPath := filepath.Join(cdir, "qcow2", resultDistro.Sha256Sum)
_, err = os.Stat(qcowPath)
if err != nil {
log.Printf("downloading distro image %s to %s", resultDistro.DownloadURL, qcowPath)
@ -189,9 +212,18 @@ func main() {
}
fout.Close()
err = run("cp", *cloudConfig, filepath.Join(dir, "user-data"))
if err != nil {
log.Fatal(err)
if *distro != "nixos" {
err = run("cp", *cloudConfig, filepath.Join(dir, "user-data"))
if err != nil {
log.Fatal(err)
}
} else {
fout, err := os.Create(filepath.Join(dir, "user-data"))
if err != nil {
log.Fatal(err)
}
fmt.Fprintln(fout, "#cloud-config")
fout.Close()
}
isoPath := filepath.Join(cdir, "seed", fmt.Sprintf("%s-%s.iso", *name, vmID))

13
nixos.go Normal file
View File

@ -0,0 +1,13 @@
package main
import "path/filepath"
func mkNixOSImage(configFname, cacheDir, vmID string) (string, error) {
outputFname := filepath.Join(cacheDir, "nixos", vmID)
err := run("nix-shell", "-p", "nixos-generators", "--run", "nixos-generate -f qcow -o "+outputFname+" -c "+configFname)
if err != nil {
return "", err
}
return outputFname, nil
}

28
var/xe-base.nix Normal file
View File

@ -0,0 +1,28 @@
{ config, pkgs, modulesPath, ... }:
{
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];
boot.initrd.availableKernelModules =
[ "ata_piix" "uhci_hcd" "virtio_pci" "sr_mod" "virtio_blk" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];
users.users.xe = {
isNormalUser = true;
initialPassword = "hunter2";
extraGroups = [ "wheel" ];
openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPg9gYKVglnO2HQodSJt4z4mNrUSUiyJQ7b+J798bwD9"
];
};
services.openssh.enable = true;
security.sudo.wheelNeedsPassword = false;
services.cloud-init = {
enable = true;
ext4.enable = true;
};
}