-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: James Hillyerd <[email protected]>
- Loading branch information
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ go.work | |
.direnv | ||
debug.log | ||
result | ||
/examples/vagrant-demo/.vagrant | ||
/labcoat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
nodes = [ | ||
{ :name => "db-lab", :ip => "192.168.33.10" }, | ||
{ :name => "web-lab", :ip => "192.168.33.11" }, | ||
] | ||
|
||
Vagrant.configure("2") do |config| | ||
nodes.each do |node| | ||
config.vm.define node[:name] do |nconf| | ||
nconf.vm.box = "nixbox/nixos" | ||
nconf.vm.box_version = "23.05" # 23.11 hangs; https://github.com/NixOS/nixpkgs/issues/262686 | ||
nconf.vm.box_check_update = false | ||
|
||
nconf.vm.hostname = node[:name] | ||
nconf.vm.network "private_network", type: "static", ip: node[:ip] | ||
nconf.vm.synced_folder ".", "/vagrant", disabled: true | ||
|
||
nconf.vm.provision "shell" do |s| | ||
ssh_pub_key = File.readlines("#{ENV['HOME']}/.ssh/id_ed25519.pub").first.strip | ||
s.inline = <<-SHELL | ||
mkdir --mode=0700 /root/.ssh | ||
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys | ||
SHELL | ||
end | ||
|
||
# Activate hostname, network config. | ||
nconf.vm.provision "shell", inline: "nixos-rebuild boot 2>&1 | tee /tmp/build.log", reboot: true | ||
|
||
nconf.vm.provider "libvirt" do |libvirt| | ||
libvirt.driver = "kvm" | ||
libvirt.cpus = 2 | ||
libvirt.cputopology :sockets => '1', :cores => '2', :threads => '1' | ||
libvirt.memory = 1024 # nixos-rebuild silently fails with 512 | ||
end | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
description = "labcoat vagrant-demo system flake"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; | ||
}; | ||
|
||
outputs = { nixpkgs, ... }: | ||
let | ||
inherit (nixpkgs) lib; | ||
in | ||
{ | ||
nixosConfigurations = | ||
let | ||
# Configuration shared by all systems. | ||
commonModule = { | ||
boot.loader.grub.enable = true; | ||
boot.loader.grub.device = "/dev/vda"; | ||
|
||
boot.initrd.checkJournalingFS = false; | ||
|
||
services.openssh = { | ||
enable = true; | ||
settings.PermitRootLogin = "yes"; | ||
}; | ||
|
||
system.stateVersion = "24.05"; | ||
}; | ||
|
||
# Creates a network module based on provided config. | ||
networkModule = { hostName, ipAddr }: { | ||
_module.args.deployAddr = ipAddr; # See labcoat deploy-host-attr config. | ||
networking = { | ||
inherit hostName; | ||
interfaces = { | ||
ens6.ipv4.addresses = [{ | ||
address = ipAddr; | ||
prefixLength = 24; | ||
}]; | ||
}; | ||
}; | ||
}; | ||
in | ||
{ | ||
db-lab = lib.nixosSystem { | ||
system = "x86_64-linux"; | ||
modules = [ | ||
commonModule | ||
./hardware-configuration.nix | ||
(networkModule { hostName = "db-lab"; ipAddr = "192.168.33.10"; }) | ||
]; | ||
}; | ||
|
||
web-lab = lib.nixosSystem { | ||
system = "x86_64-linux"; | ||
modules = [ | ||
commonModule | ||
./hardware-configuration.nix | ||
(networkModule { hostName = "web-lab"; ipAddr = "192.168.33.11"; }) | ||
]; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Vagrant + kvm hardware config. | ||
{ lib, modulesPath, ... }: | ||
{ | ||
imports = | ||
[ (modulesPath + "/profiles/qemu-guest.nix") | ||
]; | ||
|
||
boot.initrd.availableKernelModules = [ "ata_piix" "virtio_pci" "virtio_scsi" "floppy" "sd_mod" "sr_mod" ]; | ||
boot.initrd.kernelModules = [ ]; | ||
boot.kernelModules = [ "kvm-amd" ]; | ||
boot.extraModulePackages = [ ]; | ||
|
||
fileSystems."/" = | ||
{ device = "/dev/disk/by-uuid/f101d11d-cf4b-4705-96ee-bf21580ee386"; | ||
fsType = "ext4"; | ||
}; | ||
|
||
swapDevices = [ ]; | ||
|
||
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking | ||
# (the default) this is the recommended approach. When using systemd-networkd it's | ||
# still possible to use this option, but it's recommended to use it in conjunction | ||
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`. | ||
networking.useDHCP = lib.mkDefault true; | ||
# networking.interfaces.ens4.useDHCP = lib.mkDefault true; | ||
|
||
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Host deployment configuration. Nix attrs typically start with 'flake' or 'target'. | ||
[hosts] | ||
deploy-host-attr = 'target._module.args.deployAddr' |