Skip to content

Commit

Permalink
Sync Nix configuration with https://github.com/nix-community/nixbox/
Browse files Browse the repository at this point in the history
  • Loading branch information
amezin committed Feb 4, 2025
1 parent 3ea23ca commit a81efc1
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 11 deletions.
17 changes: 17 additions & 0 deletions nix/bootloader.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is overwritten by the vagrant-nixos plugin
{ config, pkgs, ... }:
{
boot.loader = {
efi = {
canTouchEfiVariables = false;
efiSysMountPoint = "/boot/efi";
};
# Use the GRUB 2 boot loader.
grub = {
enable = true;
efiSupport = true;
device = "nodev";
efiInstallAsRemovable = true;
};
};
}
29 changes: 25 additions & 4 deletions configuration.nix → nix/configuration.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{ config, pkgs, ... }:
{ config, pkgs, modulesPath, ... }:

{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
"${toString modulesPath}/profiles/qemu-guest.nix"
./bootloader.nix
./vagrant.nix
];

boot.loader.systemd-boot.enable = true;
Expand Down Expand Up @@ -32,11 +35,22 @@
#media-session.enable = true;
};

users.users.root = { password = "vagrant"; };

users.groups.vagrant = {
name = "vagrant";
members = [ "vagrant" ];
};

users.users.vagrant = {
initialPassword = "vagrant";
description = "Vagrant User";
name = "vagrant";
group = "vagrant";
password = "vagrant";
extraGroups = [ "networkmanager" "users" "wheel" ];
isNormalUser = true;
description = "Vagrant";
extraGroups = [ "networkmanager" "wheel" ];
createHome = true;
useDefaultShell = true;
packages = with pkgs; [
];
openssh.authorizedKeys.keys = [
Expand All @@ -57,6 +71,13 @@
];

environment.systemPackages = with pkgs; [
findutils
iputils
jq
nettools
netcat
nfs-utils
rsync
];

services.openssh = {
Expand Down
6 changes: 6 additions & 0 deletions nix/vagrant-hostname.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This script is overwritten by vagrant. See
# https://github.com/hashicorp/vagrant/blob/master/templates/guests/nixos/hostname.erb
{ config, pkgs, ... }:
{
networking.hostName = "nixbox";
}
3 changes: 3 additions & 0 deletions nix/vagrant-network.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file is overwritten by vagrant. See
# https://github.com/hashicorp/vagrant/blob/master/templates/guests/nixos/network.erb
{}
8 changes: 8 additions & 0 deletions nix/vagrant.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file is overwritten by the vagrant-nixos plugin
{ config, pkgs, ... }:
{
imports = [
./vagrant-hostname.nix
./vagrant-network.nix
];
}
25 changes: 18 additions & 7 deletions nixos.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ source "qemu" "nixos" {
disk_discard = "unmap"
ssh_timeout = "1h"
ssh_username = "root"
ssh_password = "nixos"
ssh_password = "vagrant"
boot_wait = "1m"
boot_command = [
"sudo passwd root<enter><wait>",
"nixos<enter><wait>",
"nixos<enter><wait>",
"vagrant<enter><wait>",
"vagrant<enter><wait>",
]
efi_firmware_code = "${path.root}/ovmf/OVMF_CODE.4m.fd"
efi_firmware_vars = "${path.root}/ovmf/OVMF_VARS.4m.fd"
Expand All @@ -66,20 +66,31 @@ build {
"swapon /dev/vda2",
"mkfs.fat -F 32 -n boot /dev/vda3",
"mount -o discard /dev/disk/by-label/nixos /mnt",
"mkdir -p /mnt/boot",
"mount /dev/disk/by-label/boot /mnt/boot",
"mkdir -p /mnt/boot/efi",
"mount /dev/disk/by-label/boot /mnt/boot/efi",
"nixos-generate-config --root /mnt",
]
}

provisioner "file" {
content = templatefile("${path.root}/configuration.nix", { path = path, state_version = var.nixos_channel })
sources = [
"${path.root}/nix/bootloader.nix"
"${path.root}/nix/vagrant-hostname.nix"
"${path.root}/nix/vagrant-network.nix"
"${path.root}/nix/vagrant.nix"
]
destination = "/mnt/etc/nixos/"
}

provisioner "file" {
content = templatefile("${path.root}/nix/configuration.nix", { path = path, state_version = var.nixos_channel })
destination = "/mnt/etc/nixos/configuration.nix"
}

provisioner "shell" {
inline = [
"nixos-install --no-root-password",
"nixos-install",
"echo 'nix-env --delete-generations old; nix-collect-garbage -d; fstrim -av --quiet-unsupported' | nixos-enter"
]
}

Expand Down

0 comments on commit a81efc1

Please sign in to comment.