2025-04-19 22:53:28 -05:00
|
|
|
|
{ config, lib, pkgs, meta, ... }:
|
2025-04-09 13:54:31 -05:00
|
|
|
|
|
2025-04-24 22:53:32 -05:00
|
|
|
|
let
|
|
|
|
|
|
testSiteIndex = pkgs.writeText "index.html" ''
|
|
|
|
|
|
<html>
|
|
|
|
|
|
<head><title>Hello</title></head>
|
|
|
|
|
|
<body>
|
2025-05-03 19:30:28 -05:00
|
|
|
|
<h1>Hello from test.roypository.com</h1>
|
2025-04-24 22:53:32 -05:00
|
|
|
|
<p>This content is defined in configuration.nix</p>
|
|
|
|
|
|
</body>
|
|
|
|
|
|
</html>
|
|
|
|
|
|
'';
|
|
|
|
|
|
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 = {
|
2025-04-29 09:10:16 -05:00
|
|
|
|
# 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 = {
|
|
|
|
|
|
"clusterPassword" = {
|
|
|
|
|
|
sopsFile = ./secrets/build.json;
|
|
|
|
|
|
};
|
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-04-16 10:57:36 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-04-17 13:24:40 -05:00
|
|
|
|
environment.variables = {
|
2025-05-03 19:30:28 -05:00
|
|
|
|
CP = config.sops.secrets."clusterPassword".path;
|
|
|
|
|
|
CAE = config.sops.secrets."cloudflare-api-email".path;
|
|
|
|
|
|
CAK = config.sops.secrets."cloudflare-api-key".path;
|
2025-04-17 10:56:14 -05:00
|
|
|
|
};
|
2025-04-23 15:13:07 -05:00
|
|
|
|
|
2025-04-29 21:37:31 -05:00
|
|
|
|
systemd.user.services.mbsync.unitConfig.After = [ "sops-nix.service" ];
|
2025-05-03 19:30:28 -05:00
|
|
|
|
fileSystems."/persist".neededForBoot = true;
|
|
|
|
|
|
|
2025-04-23 15:13:07 -05:00
|
|
|
|
# set up DNS with nginx
|
|
|
|
|
|
security.acme = {
|
|
|
|
|
|
acceptTerms = true;
|
|
|
|
|
|
defaults = {
|
|
|
|
|
|
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-04-23 15:13:07 -05:00
|
|
|
|
};
|
|
|
|
|
|
};
|
2025-04-24 22:53:32 -05:00
|
|
|
|
|
|
|
|
|
|
services.nginx.enable = true;
|
|
|
|
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."roypository.com" = {
|
|
|
|
|
|
forceSSL = true;
|
|
|
|
|
|
enableACME = true;
|
|
|
|
|
|
acmeRoot = null;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-04-23 15:13:07 -05:00
|
|
|
|
|
2025-04-24 17:07:55 -05:00
|
|
|
|
services.nginx.virtualHosts."test.roypository.com" = {
|
|
|
|
|
|
forceSSL = true;
|
2025-04-24 22:53:32 -05:00
|
|
|
|
enableACME = true;
|
|
|
|
|
|
acmeRoot = null;
|
|
|
|
|
|
root = "${testSiteIndex}";
|
2025-04-24 17:07:55 -05:00
|
|
|
|
locations."/" = {
|
|
|
|
|
|
extraConfig = ''
|
2025-04-24 22:53:32 -05:00
|
|
|
|
index index.html;
|
2025-04-24 17:07:55 -05:00
|
|
|
|
'';
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-04-09 13:54:31 -05:00
|
|
|
|
# Grub Boot Loader Setup
|
|
|
|
|
|
boot.loader.grub = {
|
|
|
|
|
|
enable = true;
|
|
|
|
|
|
zfsSupport = true;
|
|
|
|
|
|
efiSupport = true;
|
|
|
|
|
|
efiInstallAsRemovable = true;
|
|
|
|
|
|
mirroredBoots = [
|
|
|
|
|
|
{ devices = [ "nodev" ]; path = "/boot"; }
|
|
|
|
|
|
];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
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-04-17 13:24:40 -05:00
|
|
|
|
networking.hostName = meta.hostname;
|
2025-04-27 15:20:27 -05:00
|
|
|
|
networking.hostId = meta.hostId;
|
2025-04-09 13:54:31 -05:00
|
|
|
|
|
2025-04-17 13:24:40 -05:00
|
|
|
|
networking.interfaces.eth0.ipv4.addresses = [
|
|
|
|
|
|
{
|
2025-04-19 22:53:28 -05:00
|
|
|
|
address = config.ipAddrs.${meta.hostname};
|
2025-04-17 13:24:40 -05:00
|
|
|
|
prefixLength = 24;
|
|
|
|
|
|
}
|
|
|
|
|
|
];
|
2025-04-16 10:57:36 -05:00
|
|
|
|
|
2025-04-19 20:31:26 -05:00
|
|
|
|
networking.defaultGateway = "192.168.1.1";
|
|
|
|
|
|
networking.nameservers = [ "1.1.1.1" "1.0.0.1" ];
|
|
|
|
|
|
|
|
|
|
|
|
# Open ports in the firewall.
|
|
|
|
|
|
networking.firewall = {
|
|
|
|
|
|
enable = true;
|
|
|
|
|
|
allowedTCPPorts = [ 22 80 443 ];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
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
|
|
|
|
|
|
hashedPassword = "$6$8KRJ44z15XsQALM.$J4geTLaph7ynaLimlYXMGafqPOP6DONLSlTbRowH7JF7WJ4cWyMSTYQQB4OwsAgPpLCTYDzpqn6a/pfIizWFA.";
|
|
|
|
|
|
openssh.authorizedKeys.keys = [
|
|
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICNkZ5Xr75thR/tEgsASzYAtaA/kbsv2PKI8ux9rgpTe roydumblauskas@gmail.com"
|
2025-04-09 13:54:31 -05:00
|
|
|
|
];
|
|
|
|
|
|
};
|
2025-04-19 20:31:26 -05:00
|
|
|
|
|
|
|
|
|
|
users.users.root = {
|
|
|
|
|
|
hashedPassword = "$y$j9T$IjaP0KIfdpEvlLtOn.u0T/$0MJDaFEdSu6zSJ04CF1dtorD6IVgbN3vmDiiwGwwqr5";
|
|
|
|
|
|
openssh.authorizedKeys.keys = [
|
|
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICNkZ5Xr75thR/tEgsASzYAtaA/kbsv2PKI8ux9rgpTe roydumblauskas@gmail.com"
|
|
|
|
|
|
];
|
|
|
|
|
|
};
|
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-04-15 21:03:43 -05:00
|
|
|
|
vim
|
2025-04-09 13:54:31 -05:00
|
|
|
|
wget
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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:
|
|
|
|
|
|
# Enable the OpenSSH daemon.
|
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
|
|
|
|
|
|
|
|
|
|
# Copy the NixOS configuration file and link it from the resulting system
|
|
|
|
|
|
# (/run/current-system/configuration.nix). This is useful in case you
|
|
|
|
|
|
# accidentally delete configuration.nix.
|
|
|
|
|
|
# system.copySystemConfiguration = true;
|
|
|
|
|
|
|
|
|
|
|
|
# INITIAL system version
|
|
|
|
|
|
system.stateVersion = "24.11";
|
|
|
|
|
|
|
|
|
|
|
|
}
|