Clean up config & add comments.

This commit is contained in:
Fern Garden 2025-07-16 18:46:12 +08:00
parent b504700e61
commit c2fc35e12d
18 changed files with 162 additions and 114 deletions

View file

@ -25,38 +25,44 @@
sops-nix, sops-nix,
... ...
} @ inputs: let } @ inputs: let
flock.lib = import ./lib inputs; # Import helpers & make functions available.
inherit (flock.lib) mergeHosts mkHost; helpers = import ./helpers.nix inputs;
inherit (helpers) mergeHosts mkHost;
in in
mergeHosts [ mergeHosts [
# ThinkPad T480.
(mkHost "muskduck" { (mkHost "muskduck" {
suite = "desktop"; suite = "desktop";
extraModules = [ hostModules = [
lanzaboote.nixosModules.lanzaboote lanzaboote.nixosModules.lanzaboote
nixos-hardware.nixosModules.lenovo-thinkpad-t480 nixos-hardware.nixosModules.lenovo-thinkpad-t480
]; ];
}) })
# Raspberry Pi 4B.
(mkHost "weebill" { (mkHost "weebill" {
suite = "server"; suite = "server";
platform = "aarch64-linux"; platform = "aarch64-linux";
extraModules = [ hostModules = [
nixos-hardware.nixosModules.raspberry-pi-4 nixos-hardware.nixosModules.raspberry-pi-4
]; ];
}) })
# VM running a Minecraft server.
(mkHost "minecraft" { (mkHost "minecraft" {
suite = "vm"; suite = "server/vm";
user = "docker"; docker = true;
}) })
# Container running Technitium DNS Server.
(mkHost "technitium" { (mkHost "technitium" {
suite = "lxc"; suite = "server/lxc";
}) })
# Container running Mozilla's syncstorage-rs
(mkHost "firefox-syncserver" { (mkHost "firefox-syncserver" {
suite = "lxc"; suite = "server/lxc";
extraModules = [ hostModules = [
sops-nix.nixosModules.sops sops-nix.nixosModules.sops
]; ];
}) })

95
helpers.nix Normal file
View file

@ -0,0 +1,95 @@
inputs:
with inputs;
with inputs.nixpkgs.lib; {
# Merge NixOS hosts.
mergeHosts = lists.foldl' (
a: b: attrsets.recursiveUpdate a b
) {};
# Create a NixOS host.
mkHost = hostname: {
platform ? "x86_64-linux",
suite ? "",
docker ? false,
hostModules ? [],
}: let
# System architecture.
system = platform;
# Secrets directory.
secrets = builtins.toString inputs.secrets;
# Extra modules to import.
extraModules =
hostModules # Host-specific modules.
++ optionals (docker == true) [./suites/server/docker] # Enable docker if required.
++ (filesystem.listFilesRecursive ./modules); # Custom modules.
# nixpkgs config.
pkgs = import nixpkgs {
inherit system;
config = {
# Allow installation of proprietary software.
allowUnfree = true;
# Allow the installation of packages marked as insecure in nixpkgs.
permittedInsecurePackages = [
"dotnet-sdk-6.0.428" # For WebOne.
"dotnet-runtime-6.0.36" # For WebOne.
];
};
# Import my overlay.
overlays = [
(import ./overlay.nix {inherit inputs system;})
];
};
# deploy-rs overlay.
deployPkgs = import nixpkgs {
inherit system;
overlays = [
deploy-rs.overlays.default
(self: super: {
deploy-rs = {
inherit (pkgs) deploy-rs;
lib = super.deploy-rs.lib;
};
})
];
};
in
{
nixosConfigurations.${hostname} = nixosSystem {
inherit system pkgs;
specialArgs = {
# Make some variables accesible to modules.
inherit
hostname
platform
suite
secrets
;
};
modules =
[
nixvim.nixosModules.nixvim # Neovim.
./suites/${suite} # Collection of configuration options for different types of systems.
./hosts/${hostname} # Host-specific config.
]
++ extraModules;
};
}
// optionalAttrs (strings.hasPrefix "server" suite) {
deploy.nodes.${hostname} = {
hostname = "${hostname}.local";
profiles.system = {
user = "root";
sshuser = "fern";
path = deploypkgs.deploy-rs.lib.activate.nixos self.nixosconfigurations.${hostname};
};
};
};
}

View file

@ -1,14 +1,17 @@
{ {
# Root filesystem.
fileSystems."/" = { fileSystems."/" = {
device = "/dev/disk/by-uuid/cac60222-9b38-4938-8b17-5fddd67e8e26"; device = "/dev/disk/by-uuid/cac60222-9b38-4938-8b17-5fddd67e8e26";
fsType = "ext4"; fsType = "ext4";
}; };
fileSystems."/home/docker/volumes" = { # Docker data directory
fileSystems."/home/fern/docker/data" = {
device = "/dev/disk/by-uuid/95461a94-ad91-43b9-b502-2b5d4496b84e"; device = "/dev/disk/by-uuid/95461a94-ad91-43b9-b502-2b5d4496b84e";
fsType = "ext4"; fsType = "ext4";
}; };
# Swap.
swapDevices = [ swapDevices = [
{device = "/dev/disk/by-uuid/025beadb-a89b-4abe-8d0c-b55401316319";} {device = "/dev/disk/by-uuid/025beadb-a89b-4abe-8d0c-b55401316319";}
]; ];

View file

@ -4,7 +4,7 @@
secrets, secrets,
... ...
}: { }: {
# Secrets. # Import secrets.
sops = { sops = {
age.sshKeyPaths = ["/etc/ssh/ssh_host_ed25519_key"]; age.sshKeyPaths = ["/etc/ssh/ssh_host_ed25519_key"];
defaultSopsFile = "${secrets}/sops.yaml"; defaultSopsFile = "${secrets}/sops.yaml";

View file

@ -1,14 +1,17 @@
{ {
# Root filesystem.
fileSystems."/" = { fileSystems."/" = {
device = "/dev/disk/by-uuid/cbd70e61-fcdc-4b1f-af03-d3da8a2866ea"; device = "/dev/disk/by-uuid/cbd70e61-fcdc-4b1f-af03-d3da8a2866ea";
fsType = "ext4"; fsType = "ext4";
}; };
fileSystems."/home/docker/volumes" = { # Docker data directory.
fileSystems."/home/fern/docker/data" = {
device = "/dev/disk/by-uuid/3730e48a-8784-4c49-8692-473c9b4bc8c3"; device = "/dev/disk/by-uuid/3730e48a-8784-4c49-8692-473c9b4bc8c3";
fsType = "ext4"; fsType = "ext4";
}; };
# Swap.
swapDevices = [ swapDevices = [
{device = "/dev/disk/by-uuid/3123f58e-63a9-44fa-ac29-3e79dc520b8f";} {device = "/dev/disk/by-uuid/3123f58e-63a9-44fa-ac29-3e79dc520b8f";}
]; ];

View file

@ -1,4 +1,5 @@
{ {
# Kernel modules
boot.initrd.availableKernelModules = [ boot.initrd.availableKernelModules = [
"xhci_pci" "xhci_pci"
"nvme" "nvme"
@ -8,6 +9,7 @@
boot.kernelModules = ["kvm-intel"]; boot.kernelModules = ["kvm-intel"];
# Root filesystem.
fileSystems."/" = { fileSystems."/" = {
device = "/dev/disk/by-uuid/63d79656-aa5b-466a-b369-be5eac3f51ab"; device = "/dev/disk/by-uuid/63d79656-aa5b-466a-b369-be5eac3f51ab";
fsType = "ext4"; fsType = "ext4";
@ -15,6 +17,7 @@
boot.initrd.luks.devices."luks-93fa00bc-777f-4359-bad5-880c29faca0d".device = "/dev/disk/by-uuid/93fa00bc-777f-4359-bad5-880c29faca0d"; boot.initrd.luks.devices."luks-93fa00bc-777f-4359-bad5-880c29faca0d".device = "/dev/disk/by-uuid/93fa00bc-777f-4359-bad5-880c29faca0d";
# EFI/boot partition.
fileSystems."/boot" = { fileSystems."/boot" = {
device = "/dev/disk/by-uuid/EBD7-3E1C"; device = "/dev/disk/by-uuid/EBD7-3E1C";
fsType = "vfat"; fsType = "vfat";
@ -24,7 +27,9 @@
]; ];
}; };
# Allow CPU microcode.
hardware.cpu.intel.updateMicrocode = true; hardware.cpu.intel.updateMicrocode = true;
# Allows remote deployment on ARM systems (ie. Raspberry Pi).
boot.binfmt.emulatedSystems = ["aarch64-linux"]; boot.binfmt.emulatedSystems = ["aarch64-linux"];
} }

View file

@ -1,4 +1,5 @@
{pkgs, ...}: { {pkgs, ...}: {
# Boot loader.
boot = { boot = {
kernelPackages = pkgs.linuxKernel.packages.linux_rpi4; kernelPackages = pkgs.linuxKernel.packages.linux_rpi4;
initrd.availableKernelModules = [ initrd.availableKernelModules = [
@ -13,12 +14,14 @@
}; };
fileSystems = { fileSystems = {
# Root filesystem.
"/" = { "/" = {
device = "/dev/disk/by-label/NIXOS_SD"; device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4"; fsType = "ext4";
options = ["noatime"]; options = ["noatime"];
}; };
# AFP share.
"/srv/iMac" = { "/srv/iMac" = {
device = "/dev/disk/by-uuid/48843b25-4d8c-4638-a5f8-fb3901e1165e"; device = "/dev/disk/by-uuid/48843b25-4d8c-4638-a5f8-fb3901e1165e";
fsType = "ext4"; fsType = "ext4";

View file

@ -1,81 +0,0 @@
inputs:
with inputs;
with inputs.nixpkgs.lib; {
mergeHosts = lists.foldl' (
a: b: attrsets.recursiveUpdate a b
) {};
mkHost = hostname: {
platform ? "x86_64-linux",
suite,
user ? "fern",
extraModules ? [],
}: let
system = platform;
secrets = builtins.toString inputs.secrets;
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
permittedInsecurePackages = [
"dotnet-sdk-6.0.428"
"dotnet-runtime-6.0.36"
];
};
overlays = [
(import ../overlays {inherit inputs system;})
];
};
deployPkgs = import nixpkgs {
inherit system;
overlays = [
deploy-rs.overlays.default
(self: super: {
deploy-rs = {
inherit (pkgs) deploy-rs;
lib = super.deploy-rs.lib;
};
})
];
};
in
{
nixosConfigurations.${hostname} = nixosSystem {
inherit system pkgs;
specialArgs = {
inherit
hostname
platform
suite
user
secrets
; # Inherit variables.
};
modules =
[
nixvim.nixosModules.nixvim
../suites/common.nix
../suites/${suite}.nix
../hosts/${hostname}.nix
]
++ (filesystem.listFilesRecursive ../modules)
++ extraModules;
};
}
// optionalAttrs ((suite == "server")
|| (suite == "vm")
|| (suite == "lxc")) {
deploy.nodes.${hostname} = {
hostname = "${hostname}.local";
profiles.system = {
user = "root";
sshUser = user;
path = deployPkgs.deploy-rs.lib.activate.nixos self.nixosConfigurations.${hostname};
};
};
};
}

View file

@ -10,6 +10,7 @@ in {
options.services.webone.enable = mkEnableOption "Enable WebOne HTTP proxy."; options.services.webone.enable = mkEnableOption "Enable WebOne HTTP proxy.";
config = mkIf cfg.enable { config = mkIf cfg.enable {
# Create user & group for service.
users.groups.webone = {}; users.groups.webone = {};
users.users.webone = { users.users.webone = {
@ -19,6 +20,7 @@ in {
group = "webone"; group = "webone";
}; };
# Create config directory and log file, and set ownership to webone user.
systemd.tmpfiles.settings = { systemd.tmpfiles.settings = {
"10-webone" = { "10-webone" = {
"/var/log/webone.log" = { "/var/log/webone.log" = {
@ -38,6 +40,7 @@ in {
}; };
}; };
# Create a systemd service.
systemd.services.webone = { systemd.services.webone = {
description = "WebOne HTTP Proxy Server"; description = "WebOne HTTP Proxy Server";
documentation = ["https://github.com/atauenis/webone/wiki/"]; documentation = ["https://github.com/atauenis/webone/wiki/"];

View file

@ -6,10 +6,10 @@
with inputs; with inputs;
final: prev: { final: prev: {
# WebOne HTTP proxy. # WebOne HTTP proxy.
webone = prev.pkgs.callPackage ../packages/webone {}; webone = prev.pkgs.callPackage ./packages/webone {};
# Yazi Gruvbox theme. # Yazi Gruvbox theme.
yazi-flavour-gruvbox-dark = prev.pkgs.callPackage ../packages/yazi-flavour-gruvbox {}; yazi-flavour-gruvbox-dark = prev.pkgs.callPackage ./packages/yazi-flavour-gruvbox {};
# Latest FluffyChat. # Latest FluffyChat.
fluffychat = fluffychat =

View file

@ -18,6 +18,7 @@ buildDotnetModule rec {
projectFile = "WebOne.csproj"; projectFile = "WebOne.csproj";
nugetDeps = ./deps.nix; nugetDeps = ./deps.nix;
# Uses outdated dotnet 6.
dotnet-sdk = dotnetCorePackages.sdk_6_0; dotnet-sdk = dotnetCorePackages.sdk_6_0;
dotnet-runtime = dotnetCorePackages.runtime_6_0; dotnet-runtime = dotnetCorePackages.runtime_6_0;

View file

@ -52,10 +52,10 @@ with lib; {
networking.hostName = hostname; networking.hostName = hostname;
# Define a user account. # Define a user account.
users.users.${user} = { users.users.fern = {
isNormalUser = true; isNormalUser = true;
uid = 1000; uid = 1000;
description = mkIf (user == "fern") "Fern Garden"; description = "Fern Garden";
extraGroups = [ extraGroups = [
"wheel" "wheel"
"networkmanager" "networkmanager"
@ -95,6 +95,9 @@ with lib; {
# https://discourse.nixos.org/t/slow-build-at-building-man-cache/52365/2 # https://discourse.nixos.org/t/slow-build-at-building-man-cache/52365/2
documentation.man.generateCaches = false; documentation.man.generateCaches = false;
# Enable all terminfo (for ghostty).
environment.enableAllTerminfo = true;
# Install some packages. # Install some packages.
programs = { programs = {
git.enable = true; git.enable = true;
@ -102,9 +105,11 @@ with lib; {
nixvim = { nixvim = {
enable = true; enable = true;
# Set $EDITOR
defaultEditor = true; defaultEditor = true;
# For telescope. # For telescope grep.
dependencies.ripgrep.enable = true; dependencies.ripgrep.enable = true;
# Space as leader. # Space as leader.
@ -127,7 +132,10 @@ with lib; {
colorschemes.gruvbox = { colorschemes.gruvbox = {
enable = true; enable = true;
settings.contrast = "hard"; settings = {
contrast = "hard";
overrides.SignColumn.bg = "none";
};
}; };
opts = rec { opts = rec {

View file

@ -4,6 +4,8 @@
... ...
}: }:
with lib; { with lib; {
imports = [../.]; # Common config.
# Configure the bootloader. # Configure the bootloader.
boot = { boot = {
# Enable secure boot. # Enable secure boot.

View file

@ -1,15 +1,9 @@
{ {
user, imports = [../.]; # Common config.
lib,
...
}:
with lib; {
# Passwordless sudo. # Passwordless sudo.
security.sudo.wheelNeedsPassword = false; security.sudo.wheelNeedsPassword = false;
# Enable all terminfo (for ghostty).
environment.enableAllTerminfo = true;
# Enable sshd. # Enable sshd.
services.openssh = { services.openssh = {
enable = true; enable = true;
@ -20,14 +14,11 @@ with lib; {
}; };
}; };
users.users.${user} = { # Add authorized ssh pubkeys.
users.users.fern = {
openssh.authorizedKeys.keys = [ openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIETPyuxUVEmYyEW6PVC6BXqkhULHd/RvMm8fMbYhjTMV fern@muskduck" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIETPyuxUVEmYyEW6PVC6BXqkhULHd/RvMm8fMbYhjTMV fern@muskduck"
"sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIMoJvPcUJDVVzO4dHROCFNlgJdDZSP5xyPx2s40zcx5QAAAABHNzaDo= YubiKey5NFC" "sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIMoJvPcUJDVVzO4dHROCFNlgJdDZSP5xyPx2s40zcx5QAAAABHNzaDo= YubiKey5NFC"
]; ];
extraGroups = mkIf (user == "docker") ["docker"]; # if docker is enabled.
}; };
# Enable docker.
virtualisation.docker.enable = mkIf (user == "docker") true;
} }

View file

@ -0,0 +1,9 @@
{
# Add user to docker group.
users.users.fern = {
extraGroups = ["docker"];
};
# Enable docker.
virtualisation.docker.enable = true;
}

View file

@ -1,6 +1,6 @@
{modulesPath, ...}: { {modulesPath, ...}: {
imports = [ imports = [
(modulesPath + "/virtualisation/proxmox-lxc.nix") (modulesPath + "/virtualisation/proxmox-lxc.nix")
./server.nix ../. # Server config.
]; ];
} }

View file

@ -6,7 +6,7 @@
with lib; { with lib; {
imports = [ imports = [
(modulesPath + "/profiles/qemu-guest.nix") (modulesPath + "/profiles/qemu-guest.nix")
./server.nix ../. # Server config.
]; ];
# Load kernel modules. # Load kernel modules.