Files
homelab-config/nixos/configuration.nix
T

320 lines
7.5 KiB
Nix
Raw Normal View History

2025-04-19 22:53:28 -05:00
{ config, lib, pkgs, meta, ... }:
2025-04-09 13:54:31 -05:00
2025-08-24 00:02:38 -05:00
let
nimhStaticSite = pkgs.runCommand "nimh-static-site" { } ''
mkdir -p $out
cp -r ${../homelab-services/nimh-static}/* $out/
'';
in
2025-04-19 20:31:26 -05:00
{
2025-04-09 15:26:07 -05:00
imports = [ ];
2025-04-09 13:54:31 -05:00
2025-04-09 15:55:54 -05:00
nix.settings.experimental-features = [ "nix-command" "flakes" ];
nixpkgs.config.allowUnfree = true;
2025-04-16 10:57:36 -05:00
# Secret Management
sops = {
# make sure that the age key is generated from the persisted host key
age = {
sshKeyPaths = [ "/persist/etc/ssh/ssh_host_ed25519_key" ];
keyFile = "/persist/var/lib/sops-nix/key.txt";
generateKey = true;
};
# I prefer to use json format for the secrets
2025-04-16 10:57:36 -05:00
defaultSopsFormat = "json";
2025-04-29 21:37:31 -05:00
# Define file and key for each secret
2025-04-23 15:13:07 -05:00
secrets = {
2025-04-24 22:53:32 -05:00
"cloudflare-api-email" = {
2025-04-23 15:13:07 -05:00
sopsFile = ./secrets/cloudflare.json;
2025-04-24 22:53:32 -05:00
key = "CF_API_EMAIL";
};
"cloudflare-api-key" = {
sopsFile = ./secrets/cloudflare.json;
key = "CF_API_KEY";
2025-04-23 15:13:07 -05:00
};
2025-06-12 19:01:51 -05:00
"minio-credentials" = {
sopsFile = ./secrets/minio.yaml;
key = "minioCredentials";
2025-06-12 19:04:08 -05:00
format = "yaml";
};
"tests-service" = {
sopsFile = ./secrets/tests-service.yaml;
key = "credentials";
format = "yaml";
};
2025-04-23 15:13:07 -05:00
};
2025-04-16 10:57:36 -05:00
};
2025-04-29 21:37:31 -05:00
systemd.user.services.mbsync.unitConfig.After = [ "sops-nix.service" ];
fileSystems."/persist".neededForBoot = true;
2025-05-30 00:35:34 -05:00
# Set up https certs via cloudflare/acme
2025-04-23 15:13:07 -05:00
security.acme = {
acceptTerms = true;
defaults = {
2025-08-23 22:24:53 -05:00
# use staging for testing
2025-08-23 21:27:28 -05:00
server = "https://acme-staging-v02.api.letsencrypt.org/directory";
2025-08-23 22:04:42 -05:00
# use prod for deploy
# server = "https://acme-v02.api.letsencrypt.org/directory";
2025-04-23 15:13:07 -05:00
email = "roydumblauskas@gmail.com";
dnsProvider = "cloudflare";
2025-04-24 22:53:32 -05:00
credentialFiles = {
2025-04-25 00:28:28 -05:00
CF_API_EMAIL_FILE = config.sops.secrets."cloudflare-api-email".path;
CF_API_KEY_FILE = config.sops.secrets."cloudflare-api-key".path;
2025-04-24 22:53:32 -05:00
};
2025-08-23 21:07:45 -05:00
};
2025-08-23 21:06:20 -05:00
certs = {
"roypository.com" = {
domain = "*.roypository.com";
group = "nginx";
};
2025-04-23 15:13:07 -05:00
};
};
2025-04-24 22:53:32 -05:00
2025-08-24 00:02:38 -05:00
2025-05-30 00:35:34 -05:00
# Setup vhosts via nginx
2025-05-05 12:41:46 -05:00
services.nginx = {
enable = true;
2025-08-23 14:43:42 -05:00
logError = "stderr";
2025-05-05 12:41:46 -05:00
virtualHosts."roypository.com" = {
forceSSL = true;
2025-08-23 21:47:31 -05:00
useACMEHost = "roypository.com";
2025-08-23 23:44:44 -05:00
locations = { };
2025-08-23 21:47:31 -05:00
};
virtualHosts."nimh.roypository.com" = {
forceSSL = true;
useACMEHost = "roypository.com";
2025-08-23 22:11:35 -05:00
2025-08-24 00:02:38 -05:00
locations."/" = {
root = nimhStaticSite;
index = "index.html";
extraConfig = ''
autoindex off;
'';
};
2025-05-05 12:41:46 -05:00
};
2025-05-30 19:27:25 -05:00
};
2025-04-24 22:53:32 -05:00
2025-05-30 19:27:25 -05:00
# Declare test service manually
2025-06-12 18:14:25 -05:00
services.tests-service = {
enable = true;
port = 8080;
credentialsFile = config.sops.secrets."tests-service".path;
2025-06-12 18:14:25 -05:00
default-nginx = {
enable = true;
2025-08-23 15:44:57 -05:00
hostname = "test.roypository.com";
2025-06-12 18:14:25 -05:00
};
};
2025-04-24 17:07:55 -05:00
2025-06-12 18:29:50 -05:00
# Declare minio service manually
services.minio-service = {
enable = true;
2025-07-02 17:23:37 -05:00
# Persist data inside of database
2025-08-16 16:03:17 -05:00
dataDir = "/data/minio";
2025-06-12 19:02:43 -05:00
credentialsFile = config.sops.secrets."minio-credentials".path;
2025-06-12 18:29:50 -05:00
dataPort = 9000; # S3 API access
consolePort = 9001; # Admin console access
2025-08-16 21:13:17 -05:00
bootstrap-minio = {
enable = true;
environments = [ "dev" "prod" ];
};
2025-06-12 18:29:50 -05:00
default-nginx = {
enable = true;
2025-08-23 15:44:57 -05:00
hostname = "imgs.roypository.com";
2025-06-12 18:29:50 -05:00
};
};
2025-06-21 11:54:12 -05:00
# ================================ #
# MINECRAFT #
# ================================ #
2025-06-21 15:45:34 -05:00
services.mc-service = {
enable = true;
storeDir = "/persist/srv/minecraft";
};
2025-06-21 11:54:12 -05:00
# ================================ #
# END MINECRAFT #
# ================================ #
2025-04-09 13:54:31 -05:00
# Grub Boot Loader Setup
2025-06-12 18:00:15 -05:00
boot.loader = {
efi = {
canTouchEfiVariables = true;
efiSysMountPoint = "/boot/efi";
};
grub = {
efiSupport = true;
device = "nodev";
2025-06-12 18:08:47 -05:00
configurationLimit = 3;
2025-06-12 18:00:15 -05:00
};
2025-04-09 13:54:31 -05:00
};
2025-04-27 16:05:18 -05:00
# Rollback root on reboot
2025-04-27 23:07:22 -05:00
boot.initrd.postMountCommands = lib.mkAfter ''
2025-04-27 22:01:25 -05:00
zfs rollback -r zroot/root@blank
2025-04-27 16:05:18 -05:00
'';
2025-05-05 12:41:46 -05:00
networking = {
hostName = meta.hostname;
hostId = meta.hostId;
2025-06-29 23:07:37 -05:00
defaultGateway = "10.0.0.1";
2025-05-05 12:41:46 -05:00
nameservers = [ "1.1.1.1" "1.0.0.1" ];
2025-04-27 16:05:18 -05:00
2025-05-05 12:41:46 -05:00
firewall = {
enable = true;
allowedTCPPorts = [ 22 80 443];
};
2025-04-09 13:54:31 -05:00
2025-05-05 12:41:46 -05:00
interfaces.eth0.ipv4.addresses = [
{
2025-06-02 10:43:30 -05:00
address = config.ipAddrs.${meta.hostname};
2025-05-05 12:41:46 -05:00
prefixLength = 24;
}
];
2025-04-19 20:31:26 -05:00
};
2025-04-09 13:54:31 -05:00
# Set your time zone.
time.timeZone = "America/Chicago";
# Configure network proxy if necessary
# networking.proxy.default = "http://user:password@proxy:port/";
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
# Select internationalisation properties.
# i18n.defaultLocale = "en_US.UTF-8";
# console = {
# font = "Lat2-Terminus16";
# keyMap = "us";
# useXkbConfig = true; # use xkb.options in tty.
# };
# Enable the X11 windowing system.
# services.xserver.enable = true;
# Configure keymap in X11
# services.xserver.xkb.layout = "us";
# services.xserver.xkb.options = "eurosign:e,caps:escape";
# Enable CUPS to print documents.
services.printing.enable = true;
# Enable sound.
# hardware.pulseaudio.enable = true;
# OR
# services.pipewire = {
# enable = true;
# pulse.enable = true;
# };
# Define a user account. Don't forget to set a password with passwd.
2025-04-09 15:26:07 -05:00
users.users.sysAdmin = {
2025-04-09 13:54:31 -05:00
isNormalUser = true;
2025-04-09 15:26:07 -05:00
extraGroups = [ "wheel" "networkManager" ];
# created with mkpasswd
2025-08-23 01:43:06 -05:00
hashedPassword = "$y$j9T$ILYm49Ylk4h6Wforpdw161$ds0DvzLQkbh0o3vN6D.gZ4KMo..0AOR/DwNcWtY0nH2";
2025-04-09 15:26:07 -05:00
openssh.authorizedKeys.keys = [
2025-08-23 01:43:06 -05:00
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFEQyjykrRpkgMFpNAR2G1rbofqbtcuLwIYzgqH85QCn roydumblauskas@gmail.com"
2025-06-12 16:18:51 -05:00
];
};
users.users.roy = {
isNormalUser = true;
extraGroups = [ "wheel" ];
2025-08-23 01:43:06 -05:00
hashedPassword = "$y$j9T$GigbbrHNEe.fhkEYbbYGc1$7dS10OH5LGoZtCfoDy82H71nZVbCgGHdkwVwxZpGUY4";
openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFEQyjykrRpkgMFpNAR2G1rbofqbtcuLwIYzgqH85QCn roydumblauskas@gmail.com"
];
2025-08-22 22:46:03 -05:00
shell = pkgs.fish;
};
2025-06-12 16:18:51 -05:00
users.users.root = {
openssh.authorizedKeys.keys = [
2025-08-23 01:43:06 -05:00
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFEQyjykrRpkgMFpNAR2G1rbofqbtcuLwIYzgqH85QCn roydumblauskas@gmail.com"
2025-04-09 13:54:31 -05:00
];
};
# Symlink the user directories that need to be persisted (ssh key/repository folder)
2025-06-05 12:00:56 -05:00
environment.persistence."/persist" = {
2025-06-05 12:38:48 -05:00
directories = [
"/root/.ssh"
"/var/lib/nixos"
2025-07-02 17:48:26 -05:00
"/var/db/sudo/lectured"
2025-06-05 12:38:48 -05:00
];
2025-06-05 12:00:56 -05:00
};
2025-04-09 15:55:54 -05:00
2025-04-09 13:54:31 -05:00
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs; [
2025-04-09 15:26:07 -05:00
curl
2025-04-27 22:01:25 -05:00
kitty
2025-08-23 14:33:41 -05:00
nginx
2025-06-21 22:45:52 -05:00
tmux
2025-04-15 21:03:43 -05:00
vim
2025-04-09 13:54:31 -05:00
wget
];
fonts.packages = with pkgs; [
nerd-fonts.mononoki
nerd-fonts.ubuntu-mono
];
programs = {
hyprland = {
enable = true;
xwayland.enable = true;
};
waybar.enable = true;
fish.enable = true;
fuse.userAllowOther = true;
};
environment.variables = {
EDITOR = "nvim";
};
2025-04-09 13:54:31 -05:00
# Some programs need SUID wrappers, can be configured further or are
# started in user sessions.
# programs.mtr.enable = true;
# programs.gnupg.agent = {
# enable = true;
# enableSSHSupport = true;
# };
# List services that you want to enable:
2025-04-27 23:07:22 -05:00
services.openssh = {
enable = true;
hostKeys = [
{
type = "ed25519";
path = "/persist/etc/ssh/ssh_host_ed25519_key";
}
{
type = "rsa";
bits = 4096;
path = "/persist/etc/ssh/ssh_host_rsa_key";
}
];
};
2025-04-09 13:54:31 -05:00
# INITIAL system version
system.stateVersion = "24.11";
}