refactor: simplify host setup

This commit is contained in:
Nickolaj Jepsen 2025-12-13 21:41:52 +01:00
parent 15fb616845
commit d1d4082d56
27 changed files with 147 additions and 90 deletions

View file

@ -4,12 +4,6 @@
inputs, inputs,
... ...
}: { }: {
# Minimal system without desktop or dev tools
fireproof.desktop.enable = false;
fireproof.dev.enable = false;
fireproof.work.enable = false;
fireproof.homelab.enable = false;
# Use the nixos installation ISO as base # Use the nixos installation ISO as base
imports = [ imports = [
"${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix" "${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"

View file

@ -0,0 +1,9 @@
{
config.fireproof.hostname = "bootstrap";
config.fireproof.username = "nickolaj";
imports = [
./configuration.nix
./disk-configuration.nix
];
}

View file

@ -1,21 +1,10 @@
{ {
inputs, inputs,
withSystem, withSystem,
lib,
... ...
}: }: let
with lib; let
mkSystemImports = hostname: let
hostDirectory = ./. + ("/" + hostname);
nixFiles = filter (file: hasSuffix ".nix" file) (attrNames (builtins.readDir hostDirectory));
imports = map (file: ./. + ("/" + hostname + "/" + file)) nixFiles;
in {
inherit imports;
};
mkSystem = { mkSystem = {
hostname, host,
username,
modules ? [], modules ? [],
system ? "x86_64-linux", system ? "x86_64-linux",
}: }:
@ -28,7 +17,7 @@ with lib; let
in in
inputs.nixpkgs.lib.nixosSystem { inputs.nixpkgs.lib.nixosSystem {
inherit system; inherit system;
specialArgs = {inherit inputs hostname username pkgsUnstable;}; specialArgs = {inherit inputs pkgsUnstable;};
modules = modules =
[ [
inputs.disko.nixosModules.disko inputs.disko.nixosModules.disko
@ -46,37 +35,17 @@ with lib; let
../modules/programs ../modules/programs
../modules/desktop ../modules/desktop
../modules/homelab ../modules/homelab
(mkSystemImports hostname) host
{nixpkgs.config.allowUnfree = true;}
] ]
++ modules ++ modules;
++ (
lib.optional (builtins.pathExists ./${hostname}/facter.json)
{config.facter.reportPath = ./${hostname}/facter.json;}
);
} }
); );
in { in {
config.flake.nixosConfigurations = { config.flake.nixosConfigurations = {
laptop = mkSystem { laptop = mkSystem {host = ./laptop;};
hostname = "laptop"; desktop = mkSystem {host = ./desktop;};
username = "nickolaj"; work = mkSystem {host = ./work;};
}; homelab = mkSystem {host = ./homelab;};
desktop = mkSystem { bootstrap = mkSystem {host = ./bootstrap;};
hostname = "desktop";
username = "nickolaj";
};
work = mkSystem {
hostname = "work";
username = "nickolaj";
};
homelab = mkSystem {
hostname = "homelab";
username = "nickolaj";
};
bootstrap = mkSystem {
hostname = "bootstrap";
username = "nickolaj";
};
}; };
} }

View file

@ -1,5 +0,0 @@
{
fireproof.desktop.enable = true;
fireproof.work.enable = true;
fireproof.dev.enable = true;
}

22
hosts/desktop/default.nix Normal file
View file

@ -0,0 +1,22 @@
{
config = {
fireproof = {
hostname = "desktop";
username = "nickolaj";
desktop.enable = true;
work.enable = true;
dev.enable = true;
};
facter.reportPath = ./facter.json;
};
imports = [
./boot.nix
./disk-configuration.nix
./monitors.nix
./networking.nix
./nvidia.nix
./ssh.nix
];
}

View file

@ -3,9 +3,6 @@
lib, lib,
... ...
}: { }: {
fireproof.dev.enable = true;
fireproof.homelab.enable = true;
boot = { boot = {
# Use grub as bootloader as it works better with mdadm # Use grub as bootloader as it works better with mdadm
loader.grub.enable = true; loader.grub.enable = true;

17
hosts/homelab/default.nix Normal file
View file

@ -0,0 +1,17 @@
{
config = {
fireproof = {
hostname = "homelab";
username = "nickolaj";
dev.enable = true;
homelab.enable = true;
};
facter.reportPath = ./facter.json;
};
imports = [
./configuration.nix
./disks.nix
./networking.nix
];
}

View file

@ -1,7 +1,4 @@
{pkgs, ...}: { {pkgs, ...}: {
fireproof.desktop.enable = true;
fireproof.work.enable = true;
fireproof.dev.enable = true;
# Enable OpenGL # Enable OpenGL
hardware.graphics = { hardware.graphics = {
enable = true; enable = true;

19
hosts/laptop/default.nix Normal file
View file

@ -0,0 +1,19 @@
{
config = {
fireproof = {
desktop.enable = true;
work.enable = true;
dev.enable = true;
hostname = "laptop";
username = "nickolaj";
};
facter.reportPath = ./facter.json;
};
imports = [
./configuration.nix
./disk-configuration.nix
./monitors.nix
./ssh.nix
];
}

View file

@ -1,5 +0,0 @@
{
fireproof.desktop.enable = true;
fireproof.work.enable = true;
fireproof.dev.enable = true;
}

21
hosts/work/default.nix Normal file
View file

@ -0,0 +1,21 @@
{
config = {
fireproof = {
hostname = "work";
username = "nickolaj";
desktop.enable = true;
work.enable = true;
dev.enable = true;
};
facter.reportPath = ./facter.json;
};
imports = [
./bluetooth.nix
./disk-configuration.nix
./monitors.nix
./networking.nix
./nvidia.nix
./ssh.nix
];
}

View file

@ -2,6 +2,7 @@ _: {
options.fireproof.base = {}; options.fireproof.base = {};
imports = [ imports = [
./fireproof.nix
./defaults.nix ./defaults.nix
./gc.nix ./gc.nix
./home-manager.nix ./home-manager.nix

View file

@ -0,0 +1,12 @@
{lib, ...}: {
options.fireproof = {
hostname = lib.mkOption {
type = lib.types.str;
description = "The hostname of the machine";
};
username = lib.mkOption {
type = lib.types.str;
description = "The primary username for the machine";
};
};
}

View file

@ -1,10 +1,12 @@
{ {
lib, lib,
config,
options, options,
username,
... ...
}: }:
with lib; { with lib; let
inherit (config.fireproof) username;
in {
options.fireproof = { options.fireproof = {
home-manager = lib.mkOption { home-manager = lib.mkOption {
type = options.home-manager.users.type.nestedTypes.elemType; type = options.home-manager.users.type.nestedTypes.elemType;

View file

@ -1,9 +1,11 @@
{username, ...}: { {config, ...}: {
nixpkgs.config.allowUnfree = true;
nix.settings = { nix.settings = {
trusted-users = [ trusted-users = [
"root" "root"
"@wheel" "@wheel"
username config.fireproof.username
]; ];
experimental-features = "nix-command flakes"; experimental-features = "nix-command flakes";

View file

@ -1,4 +1,5 @@
{hostname, ...}: let {config, ...}: let
inherit (config.fireproof) hostname;
hostSecrets = ../../secrets/hosts + ("/" + hostname); hostSecrets = ../../secrets/hosts + ("/" + hostname);
publicKey = builtins.readFile (hostSecrets + "/id_ed25519.pub"); publicKey = builtins.readFile (hostSecrets + "/id_ed25519.pub");
in { in {

View file

@ -1,9 +1,10 @@
{ {
config, config,
lib, lib,
username,
... ...
}: { }: let
inherit (config.fireproof) username;
in {
config = lib.mkIf config.fireproof.desktop.enable { config = lib.mkIf config.fireproof.desktop.enable {
fireproof.home-manager = { fireproof.home-manager = {
home.file.".config/DankMaterialShell/colors.json".text = builtins.toJSON { home.file.".config/DankMaterialShell/colors.json".text = builtins.toJSON {

View file

@ -1,10 +1,10 @@
{ {
config, config,
lib, lib,
username,
... ...
}: }:
lib.mkIf config.fireproof.homelab.enable (let lib.mkIf config.fireproof.homelab.enable (let
inherit (config.fireproof) username;
user = "media"; user = "media";
group = "media"; group = "media";

View file

@ -1,10 +1,10 @@
{ {
config, config,
hostname,
lib, lib,
... ...
}: }:
lib.mkIf config.fireproof.homelab.enable (let lib.mkIf config.fireproof.homelab.enable (let
inherit (config.fireproof) hostname;
mkScrapeConfig = name: { mkScrapeConfig = name: {
job_name = name; job_name = name;
static_configs = [ static_configs = [

View file

@ -1,10 +1,12 @@
# Enabled when: always # Enabled when: always
{ {
username, config,
pkgs, pkgs,
lib, lib,
... ...
}: { }: let
inherit (config.fireproof) username;
in {
environment.systemPackages = [ environment.systemPackages = [
pkgs.docker pkgs.docker
pkgs.docker-compose pkgs.docker-compose

View file

@ -1,8 +1,10 @@
{ {
username, config,
pkgs, pkgs,
... ...
}: { }: let
inherit (config.fireproof) username;
in {
config = { config = {
programs.fish.enable = true; programs.fish.enable = true;
users.users.${username}.shell = pkgs.fish; users.users.${username}.shell = pkgs.fish;

View file

@ -3,9 +3,10 @@
config, config,
lib, lib,
pkgs, pkgs,
username,
... ...
}: { }: let
inherit (config.fireproof) username;
in {
config = lib.mkIf config.fireproof.dev.enable { config = lib.mkIf config.fireproof.dev.enable {
environment.systemPackages = [ environment.systemPackages = [
pkgs.kubectl pkgs.kubectl

View file

@ -1,10 +1,10 @@
{ {
pkgs, pkgs,
config, config,
username,
pkgsUnstable, pkgsUnstable,
... ...
}: let }: let
inherit (config.fireproof) username;
llmConfig = llmConfig =
if pkgs.stdenv.isDarwin if pkgs.stdenv.isDarwin
then "Library/Application Support/io.datasette.llm" then "Library/Application Support/io.datasette.llm"

View file

@ -2,10 +2,11 @@
{ {
config, config,
lib, lib,
username,
pkgs, pkgs,
... ...
}: { }: let
inherit (config.fireproof) username;
in {
config = lib.mkIf config.fireproof.desktop.enable { config = lib.mkIf config.fireproof.desktop.enable {
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
spotify spotify

View file

@ -1,5 +1,5 @@
{hostname, ...}: { {config, ...}: {
networking = { networking = {
hostName = hostname; hostName = config.fireproof.hostname;
}; };
} }

View file

@ -1,11 +1,11 @@
{ {
config, config,
pkgs, pkgs,
username,
hostname,
lib, lib,
... ...
}: let }: let
inherit (config.fireproof) username;
inherit (config.fireproof) hostname;
# Load all public keys from ../../secrets/hosts/*/id_ed25519.pub # Load all public keys from ../../secrets/hosts/*/id_ed25519.pub
allHosts = lib.attrNames (lib.filterAttrs (_: type: type == "directory") (builtins.readDir ../../secrets/hosts)); allHosts = lib.attrNames (lib.filterAttrs (_: type: type == "directory") (builtins.readDir ../../secrets/hosts));
publicKeys = map (x: builtins.readFile (../../secrets/hosts + ("/" + x) + "/id_ed25519.pub")) allHosts; publicKeys = map (x: builtins.readFile (../../secrets/hosts + ("/" + x) + "/id_ed25519.pub")) allHosts;

View file

@ -1,8 +1,5 @@
{ {config, ...}: let
username, inherit (config.fireproof) username;
config,
...
}: let
inherit (config.age) secrets; inherit (config.age) secrets;
in { in {
config = { config = {