Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NixOS #147

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
- ubuntu2204
- ubuntu2404
- ubuntu2410
- nixos

runs-on: ubuntu-24.04
timeout-minutes: 45
Expand Down
74 changes: 74 additions & 0 deletions configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{ config, pkgs, ... }:

{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];

boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;

networking.hostName = "nixos";

networking.networkmanager.enable = true;

services.xserver.enable = true;
services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.enable = true;

services.printing.enable = true;

hardware.pulseaudio.enable = false;
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;

# use the example session manager (no others are packaged yet so this is enabled by default,
# no need to redefine it in your config for now)
#media-session.enable = true;
};

users.users.vagrant = {
initialPassword = "vagrant";
isNormalUser = true;
description = "Vagrant";
extraGroups = [ "networkmanager" "wheel" ];
packages = with pkgs; [
];
openssh.authorizedKeys.keys = [
${join("\n", formatlist("\"%s\"", compact(split("\n", file("${path.root}/keys/vagrant.pub")))))}
];
};

security.sudo.extraRules = [
{
users = [ "vagrant" ];
commands = [
{
command = "ALL";
options = [ "NOPASSWD" ];
}
];
}
];

environment.systemPackages = with pkgs; [
];

services.openssh = {
enable = true;
settings.PasswordAuthentication = true;
settings.KbdInteractiveAuthentication = true;
settings.PermitRootLogin = "yes";
};

services.qemuGuest.enable = true;
services.spice-vdagentd.enable = true;
services.spice-webdavd.enable = true;

system.stateVersion = "${state_version}";
}
102 changes: 102 additions & 0 deletions nixos.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
variable "nixos_channel" {
type = string
default = "24.11"
}

data "http" "nixos_iso_checksum" {
url = "https://channels.nixos.org/nixos-${var.nixos_channel}/latest-nixos-minimal-x86_64-linux.iso.sha256"
}

local "nixos_iso_checksum_split" {
expression = compact(split(" ", data.http.nixos_iso_checksum.body))
}

local "nixos_iso_checksum" {
expression = trimspace(local.nixos_iso_checksum_split[0])
}

local "nixos_iso_name" {
expression = trimspace(local.nixos_iso_checksum_split[1])
}

local "nixos_iso_dir" {
expression = regex_replace(local.nixos_iso_name, "nixos-minimal-(.*)-x86_64-linux.iso", "nixos-$1")
}

source "qemu" "nixos" {
iso_url = "https://releases.nixos.org/nixos/${var.nixos_channel}/${local.nixos_iso_dir}/${local.nixos_iso_name}"
iso_checksum = "sha256:${local.nixos_iso_checksum}"
vga = "virtio"
cpus = 2
memory = 4096
headless = var.headless
shutdown_command = "sudo shutdown -P now"
qmp_enable = true
disk_discard = "unmap"
ssh_timeout = "1h"
ssh_username = "root"
ssh_password = "nixos"
boot_wait = "1m"
boot_command = [
"sudo passwd root<enter><wait>",
"nixos<enter><wait>",
"nixos<enter><wait>",
]
efi_firmware_code = "${path.root}/ovmf/OVMF_CODE.4m.fd"
efi_firmware_vars = "${path.root}/ovmf/OVMF_VARS.4m.fd"
qemuargs = [["-serial", "stdio"]]
machine_type = var.machine_type
}

build {
sources = [
"source.qemu.nixos"
]

provisioner "shell" {
inline = [
"parted /dev/vda -- mklabel gpt",
"parted /dev/vda -- mkpart primary 512MB -8GB",
"parted /dev/vda -- mkpart primary linux-swap -8GB 100%",
"parted /dev/vda -- mkpart ESP fat32 1MB 512MB",
"parted /dev/vda -- set 3 esp on",

"mkfs.btrfs -L nixos /dev/vda1",
"mkswap -L swap /dev/vda2",
"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",
"nixos-generate-config --root /mnt",
]
}

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

provisioner "shell" {
inline = [
"nixos-install --no-root-password",
]
}

post-processors {
post-processor "vagrant" {
vagrantfile_template = "Vagrantfile"
include = [
"${path.root}/ovmf/OVMF_CODE.4m.fd",
"${path.root}/output-${source.name}/efivars.fd",
"${path.root}/ovmf/edk2.License.txt",
"${path.root}/ovmf/OvmfPkg.License.txt",
]
}

post-processor "vagrant-registry" {
box_tag = "gnome-shell-box/nixos"
version = local.version
}
}
}
11 changes: 11 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@
"datasourceTemplate": "custom.html",
"depNameTemplate": "debian-amd64-netinst",
"extractVersionTemplate": "(^|/)debian-(?<version>\\d+\\.\\d+\\.\\d+)-amd64-netinst\\.iso$"
},
{
"customType": "regex",
"fileMatch": [
"\\.pkr\\.hcl$"
],
"matchStrings": [
"variable\\s+\"nixos_channel\"\\s*\\{[^}]*default\\s*=\\s*\"(?<currentValue>[^\"]+)"
],
"datasourceTemplate": "endoflife-date",
"packageNameTemplate": "NixOS"
}
],
"packageRules": [
Expand Down