Add NixOS
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
{config, pkgs, lib, ...}:
|
||||
|
||||
{
|
||||
imports = [
|
||||
./hardware-configuration.nix
|
||||
];
|
||||
|
||||
# Packages installed on the whole system
|
||||
environment.systemPackages = with pkgs; [
|
||||
curl
|
||||
nano
|
||||
python3
|
||||
];
|
||||
# Services that are running
|
||||
services = {
|
||||
openssh.enable = true;
|
||||
#xserver.enable = true;
|
||||
};
|
||||
# User setup
|
||||
users.users.vagrant = {
|
||||
isNormalUser = true;
|
||||
extraGroups = [ "wheel" ];
|
||||
password = "vagrant";
|
||||
};
|
||||
security.sudo.extraRules = [
|
||||
{
|
||||
users = [ "vagrant" ];
|
||||
groups = [ "vagrant" ];
|
||||
commands = [
|
||||
{ command = "ALL"; options = [ "NOPASSWD" ]; }
|
||||
];
|
||||
}
|
||||
];
|
||||
|
||||
boot.loader.grub = {
|
||||
enable = true;
|
||||
devices = [ "@BOOT_DEVICE@" ];
|
||||
};
|
||||
networking = {
|
||||
hostName = "vagrant";
|
||||
networkmanager.enable = true;
|
||||
#proxy.default = "http://user:password@proxy:port/";
|
||||
#proxy.noProxy = "127.0.0.1,localhost,internal.domain";
|
||||
};
|
||||
time.timeZone = "UTC";
|
||||
|
||||
i18n.defaultLocale = "en_US.UTF-8";
|
||||
console = {
|
||||
font = "Lat2-Terminux16";
|
||||
keyMap = lib.mkForce "us";
|
||||
useXkbConfig = true;
|
||||
};
|
||||
|
||||
system.stateVersion = "23.05";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
# Set passwords
|
||||
echo "vagrant:vagrant" | chpasswd
|
||||
echo "root:vagrant" | chpasswd
|
||||
|
||||
# Configure vagrant user's SSH key
|
||||
mkdir -m 0700 -p ~vagrant/.ssh
|
||||
curl -o /home/vagrant/.ssh/authorized_keys https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub
|
||||
chmod 600 ~vagrant/.ssh/authorized_keys
|
||||
|
||||
# Set ownership of things vagrant should own
|
||||
chown -R vagrant:wheel ~vagrant/
|
||||
chown -R vagrant:wheel /etc/nixos
|
||||
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
#vim: set ft=bash:
|
||||
set -ex
|
||||
|
||||
port="${1}" # HTTP port that packer is running on
|
||||
|
||||
if [ -e /dev/vda ]; then
|
||||
disk="/dev/vda"
|
||||
elif [ -e /dev/sda ]; then
|
||||
disk="/dev/sda"
|
||||
else
|
||||
exit 1 # Need to teach the script which device to use in this case
|
||||
fi
|
||||
|
||||
# The sed bit is just to strip out the extra fluff, like comments
|
||||
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk ${disk}
|
||||
o # create new DOS partition table
|
||||
n # new
|
||||
p # primary partition
|
||||
1 # part number
|
||||
# default start
|
||||
# default to full disk
|
||||
p # print, for debugging
|
||||
w # write the partition table and exit
|
||||
EOF
|
||||
#t # set partition type
|
||||
#1 # on partition 1
|
||||
#4 # BIOS boot
|
||||
|
||||
# Format and mount partitions
|
||||
mkfs.ext4 -L root "${disk}1"
|
||||
|
||||
mount "${disk}1" /mnt
|
||||
|
||||
# Bootstrap system
|
||||
nixos-generate-config --root /mnt
|
||||
curl -o /mnt/etc/nixos/configuration.nix http://10.0.2.2:"${port}"/configuration.nix
|
||||
sed -i -E -e "s,@BOOT_DEVICE@,${disk}," /mnt/etc/nixos/configuration.nix
|
||||
sed -i -E -e 's,(.*device = "/dev/disk/).*(".*),\1by-label/root\2,' /mnt/etc/nixos/hardware-configuration.nix
|
||||
nixos-install --no-root-password
|
||||
|
||||
# Run stuff in the chroot
|
||||
curl -o /mnt/root/in-chroot.sh http://10.0.2.2:"${port}"/in-chroot.sh
|
||||
nixos-enter --root /mnt -c 'bash /root/in-chroot.sh'
|
||||
rm /mnt/root/in-chroot.sh
|
||||
|
||||
reboot
|
||||
@@ -0,0 +1,15 @@
|
||||
distro = "nixos"
|
||||
version = "23.05"
|
||||
iso = {
|
||||
url = "https://channels.nixos.org/nixos-23.05/latest-nixos-minimal-x86_64-linux.iso"
|
||||
checksum = "f5df994324bc474e834200c8d641ba32492474112e95b63df3153a906ad0bca8"
|
||||
}
|
||||
boot_command = [
|
||||
"<tab><wait> net.ifnames=0<wait> <wait>bi<wait>osdevnames=0<enter>",
|
||||
"<wait60>", # Wait for system to come up?
|
||||
"curl -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.sh<enter>",
|
||||
"<wait>",
|
||||
"sudo bash /tmp/install.sh {{ .HTTPPort }}<enter>"
|
||||
]
|
||||
http_directory = "distros/nixos/23.05/http/"
|
||||
boot_wait = "5s"
|
||||
Reference in New Issue
Block a user