2024-04-29 15:42:44 -04:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
2024-04-13 17:37:28 -04:00
|
|
|
let
|
2024-04-29 15:42:44 -04:00
|
|
|
bootkey = key: { "/crypto/keys/${key}" = /crypto/keys/${key}; };
|
|
|
|
zfskeys = [
|
|
|
|
"zfs-attic-key"
|
|
|
|
"zfs-backup-key"
|
|
|
|
"zfs-calibre-key"
|
|
|
|
"zfs-db-key"
|
|
|
|
"zfs-docker-key"
|
|
|
|
"zfs-games-key"
|
|
|
|
"zfs-hydra-key"
|
|
|
|
"zfs-libvirt-key"
|
|
|
|
"zfs-main-key"
|
|
|
|
"zfs-nxtcld-key"
|
|
|
|
"zfs-torr-key"
|
|
|
|
"zfs-var-docker-key"
|
|
|
|
"zfs-nix-store-key"
|
|
|
|
];
|
2024-04-13 18:31:09 -04:00
|
|
|
in
|
2024-03-03 18:06:28 -05:00
|
|
|
{
|
2024-05-26 18:33:41 -04:00
|
|
|
imports = [ ./networking.nix ];
|
2024-04-10 18:23:40 -04:00
|
|
|
|
2024-03-03 18:06:28 -05:00
|
|
|
systemd.services.hydra-notify.serviceConfig.EnvironmentFile =
|
|
|
|
config.sops.secrets."hydra/environment".path;
|
2024-02-06 23:58:33 +01:00
|
|
|
programs.git.lfs.enable = false;
|
2024-02-05 22:45:43 +01:00
|
|
|
|
|
|
|
nixpkgs.config.packageOverrides = pkgs: {
|
2024-03-03 18:06:28 -05:00
|
|
|
vaapiIntel = pkgs.vaapiIntel.override { enableHybridCodec = true; };
|
2024-02-05 22:45:43 +01:00
|
|
|
};
|
|
|
|
|
2023-12-26 04:07:18 +01:00
|
|
|
boot = {
|
|
|
|
zfs.extraPools = [ "ZFS-primary" ];
|
2023-12-27 10:03:13 +01:00
|
|
|
loader.grub.device = "/dev/sda";
|
|
|
|
filesystem = "zfs";
|
|
|
|
useSystemdBoot = true;
|
2024-03-03 18:06:28 -05:00
|
|
|
kernelParams = [
|
|
|
|
"i915.force_probe=56a5"
|
|
|
|
"i915.enable_guc=2"
|
|
|
|
];
|
2024-02-18 00:27:02 -05:00
|
|
|
kernel.sysctl = {
|
2024-06-03 19:30:55 -04:00
|
|
|
"vm.overcommit_memory" = lib.mkForce 1;
|
2024-02-18 00:27:02 -05:00
|
|
|
"vm.swappiness" = 10;
|
|
|
|
};
|
2024-04-30 23:27:30 -04:00
|
|
|
extraModprobeConfig = ''
|
|
|
|
options zfs zfs_arc_min=82463372083
|
|
|
|
options zfs zfs_arc_max=192414534860
|
|
|
|
'';
|
2024-02-17 15:51:38 +01:00
|
|
|
binfmt.emulatedSystems = [ "aarch64-linux" ];
|
2024-04-29 15:42:44 -04:00
|
|
|
initrd.secrets = lib.mergeAttrsList (map bootkey zfskeys);
|
2023-12-26 04:07:18 +01:00
|
|
|
};
|
2023-12-23 07:39:10 +01:00
|
|
|
|
2024-02-03 22:00:35 +01:00
|
|
|
nix = {
|
|
|
|
extraOptions = ''
|
|
|
|
allowed-uris = github: gitlab: git+https:// git+ssh:// https://
|
2024-02-06 20:35:02 +01:00
|
|
|
builders-use-substitutes = true
|
2024-02-03 22:00:35 +01:00
|
|
|
'';
|
|
|
|
|
2024-03-03 18:06:28 -05:00
|
|
|
buildMachines = [
|
|
|
|
{
|
|
|
|
hostName = "localhost";
|
|
|
|
maxJobs = 2;
|
|
|
|
protocol = "ssh-ng";
|
|
|
|
speedFactor = 2;
|
|
|
|
systems = [
|
|
|
|
"x86_64-linux"
|
|
|
|
"aarch64-linux"
|
2024-04-17 01:31:45 -04:00
|
|
|
"i686-linux"
|
2024-03-03 18:06:28 -05:00
|
|
|
];
|
2024-02-07 00:51:31 +01:00
|
|
|
|
2024-03-03 18:06:28 -05:00
|
|
|
supportedFeatures = [
|
|
|
|
"kvm"
|
|
|
|
"nixos-test"
|
|
|
|
"big-parallel"
|
|
|
|
"benchmark"
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
2024-02-03 22:00:35 +01:00
|
|
|
};
|
2024-02-02 06:31:40 +01:00
|
|
|
|
2024-02-01 05:24:04 +01:00
|
|
|
hardware = {
|
|
|
|
enableAllFirmware = true;
|
|
|
|
opengl = {
|
|
|
|
enable = true;
|
|
|
|
extraPackages = with pkgs; [
|
|
|
|
intel-media-driver # LIBVA_DRIVER_NAME=iHD
|
|
|
|
vaapiIntel # LIBVA_DRIVER_NAME=i965 (older but works better for Firefox/Chromium)
|
|
|
|
vaapiVdpau
|
|
|
|
libvdpau-va-gl
|
|
|
|
intel-compute-runtime
|
|
|
|
intel-media-sdk
|
|
|
|
];
|
|
|
|
};
|
2024-01-27 12:00:32 -05:00
|
|
|
};
|
|
|
|
|
2024-04-18 17:53:15 -04:00
|
|
|
virtualisation.docker.daemon.settings.data-root = "/var/lib/docker2";
|
2023-12-23 07:39:10 +01:00
|
|
|
|
2024-02-05 22:45:43 +01:00
|
|
|
environment.systemPackages = with pkgs; [
|
2024-03-24 13:08:42 -04:00
|
|
|
attic-client
|
|
|
|
attic
|
2024-02-05 22:45:43 +01:00
|
|
|
docker-compose
|
|
|
|
jellyfin-ffmpeg
|
|
|
|
];
|
2023-12-23 07:39:10 +01:00
|
|
|
|
|
|
|
services = {
|
|
|
|
samba.enable = true;
|
|
|
|
nfs.server.enable = true;
|
2023-12-25 13:30:28 -05:00
|
|
|
openssh.ports = [ 666 ];
|
2023-12-29 00:00:49 -05:00
|
|
|
smartd.enable = true;
|
2023-12-29 00:17:27 -05:00
|
|
|
zfs = {
|
|
|
|
trim.enable = true;
|
2023-12-29 11:42:31 -05:00
|
|
|
autoScrub.enable = true;
|
2024-05-28 15:33:12 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
sanoid = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
datasets = {
|
2024-05-28 15:47:40 -04:00
|
|
|
"ZFS-primary/attic".useTemplate = [ "nix-prod" ];
|
|
|
|
"ZFS-primary/backups".useTemplate = [ "production" ];
|
|
|
|
"ZFS-primary/calibre".useTemplate = [ "production" ];
|
|
|
|
"ZFS-primary/db".useTemplate = [ "production" ];
|
|
|
|
"ZFS-primary/docker".useTemplate = [ "production" ];
|
|
|
|
"ZFS-primary/hydra".useTemplate = [ "nix-prod" ];
|
|
|
|
"ZFS-primary/nextcloud".useTemplate = [ "production" ];
|
|
|
|
"ZFS-primary/vardocker".useTemplate = [ "production" ];
|
2024-05-28 15:33:12 -04:00
|
|
|
"ZFS-primary/games" = {
|
2024-05-28 15:47:40 -04:00
|
|
|
useTemplate = [ "games" ];
|
2024-05-28 15:33:12 -04:00
|
|
|
recursive = true;
|
|
|
|
processChildrenOnly = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
templates = {
|
|
|
|
# full resiliency
|
|
|
|
production = {
|
|
|
|
frequently = 0;
|
|
|
|
hourly = 36;
|
|
|
|
daily = 30;
|
|
|
|
monthly = 6;
|
|
|
|
yearly = 3;
|
|
|
|
autosnap = true;
|
|
|
|
autoprune = true;
|
|
|
|
};
|
|
|
|
# some resiliency, but not much
|
|
|
|
# common option for things like nix store and attic where there is
|
|
|
|
# already a lot of resiliency built in
|
|
|
|
nix-prod = {
|
|
|
|
frequently = 4;
|
|
|
|
hourly = 24;
|
|
|
|
daily = 7;
|
|
|
|
};
|
|
|
|
# much shorter lived than others
|
|
|
|
games = {
|
|
|
|
frequently = 6;
|
|
|
|
hourly = 36;
|
|
|
|
daily = 3;
|
|
|
|
autosnap = true;
|
|
|
|
autoprune = true;
|
|
|
|
};
|
2024-05-28 11:32:37 -04:00
|
|
|
};
|
2023-12-29 00:17:27 -05:00
|
|
|
};
|
2024-02-01 05:24:04 +01:00
|
|
|
|
|
|
|
postgresql = {
|
|
|
|
enable = true;
|
|
|
|
enableJIT = true;
|
2024-02-02 04:25:10 +01:00
|
|
|
identMap = ''
|
|
|
|
# ArbitraryMapName systemUser DBUser
|
|
|
|
superuser_map root postgres
|
|
|
|
superuser_map alice postgres
|
|
|
|
# Let other names login as themselves
|
|
|
|
superuser_map /^(.*)$ \1
|
|
|
|
'';
|
|
|
|
|
2024-03-24 13:08:42 -04:00
|
|
|
ensureDatabases = [ "atticd" ];
|
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = "atticd";
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# initialScript = config.sops.secrets."postgres/init".path;
|
|
|
|
|
2024-02-01 05:24:04 +01:00
|
|
|
upgrade = {
|
|
|
|
enable = true;
|
2024-03-24 13:08:42 -04:00
|
|
|
stopServices = [
|
|
|
|
"hydra-evaluator"
|
|
|
|
"hydra-init"
|
|
|
|
"hydra-notify"
|
|
|
|
"hydra-queue-runner"
|
|
|
|
"hydra-send-stats"
|
|
|
|
"hydra-server"
|
|
|
|
"atticd"
|
|
|
|
];
|
2024-02-01 05:24:04 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
hydra = {
|
|
|
|
enable = true;
|
|
|
|
hydraURL = "http://localhost:3000";
|
|
|
|
smtpHost = "alicehuston.xyz";
|
|
|
|
notificationSender = "hydra@alicehuston.xyz";
|
2024-02-10 16:39:33 -05:00
|
|
|
gcRootsDir = "/ZFS/ZFS-primary/hydra";
|
2024-02-01 05:24:04 +01:00
|
|
|
useSubstitutes = true;
|
2024-04-17 01:31:45 -04:00
|
|
|
buildMachinesFiles = [ ];
|
2024-02-01 05:24:04 +01:00
|
|
|
minimumDiskFree = 50;
|
|
|
|
minimumDiskFreeEvaluator = 100;
|
2024-04-20 14:35:32 -04:00
|
|
|
extraConfig = ''
|
|
|
|
<git-input>
|
|
|
|
timeout = 3600
|
|
|
|
</git-input>
|
|
|
|
Include ${config.sops.secrets."alice/gha-hydra-token".path}
|
|
|
|
'';
|
2024-02-01 05:24:04 +01:00
|
|
|
};
|
2024-02-01 16:50:14 -05:00
|
|
|
|
|
|
|
nix-serve = {
|
|
|
|
enable = true;
|
|
|
|
secretKeyFile = config.sops.secrets."nix-serve/secret-key".path;
|
|
|
|
};
|
2024-03-24 13:08:42 -04:00
|
|
|
atticd = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
credentialsFile = config.sops.secrets."attic/secret-key".path;
|
|
|
|
|
|
|
|
settings = {
|
|
|
|
listen = "[::]:8183";
|
|
|
|
allowed-hosts = [ "attic.alicehuston.xyz" ];
|
|
|
|
api-endpoint = "https://attic.alicehuston.xyz";
|
|
|
|
compression.type = "none"; # let ZFS do the compressing
|
|
|
|
database = {
|
|
|
|
url = "postgres://atticd?host=/run/postgresql";
|
|
|
|
# disable postgres, using SOPS fails at below :(
|
|
|
|
# https://github.com/zhaofengli/attic/blob/main/nixos/atticd.nix#L57
|
|
|
|
# url = "sqlite:///ZFS/ZFS-primary/attic/server.db?mode=rwc";
|
|
|
|
heartbeat = true;
|
|
|
|
};
|
|
|
|
storage = {
|
|
|
|
type = "local";
|
|
|
|
path = "/ZFS/ZFS-primary/attic/storage";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Warning: If you change any of the values here, it will be
|
|
|
|
# difficult to reuse existing chunks for newly-uploaded NARs
|
|
|
|
# since the cutpoints will be different. As a result, the
|
|
|
|
# deduplication ratio will suffer for a while after the change.
|
|
|
|
chunking = {
|
|
|
|
# The minimum NAR size to trigger chunking
|
|
|
|
#
|
|
|
|
# If 0, chunking is disabled entirely for newly-uploaded NARs.
|
|
|
|
# If 1, all NARs are chunked.
|
|
|
|
nar-size-threshold = 64 * 1024; # 64 KiB
|
|
|
|
|
|
|
|
# The preferred minimum size of a chunk, in bytes
|
|
|
|
min-size = 16 * 1024; # 16 KiB
|
|
|
|
|
|
|
|
# The preferred average size of a chunk, in bytes
|
|
|
|
avg-size = 64 * 1024; # 64 KiB
|
|
|
|
|
|
|
|
# The preferred maximum size of a chunk, in bytes
|
|
|
|
max-size = 256 * 1024; # 256 KiB
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# borrowing from https://github.com/Shawn8901/nix-configuration/blob/4b8d1d44f47aec60feb58ca7b7ab5ed000506e90/modules/nixos/private/hydra.nix
|
|
|
|
# configured default webstore for this on root user separately
|
|
|
|
systemd.services.attic-watch-store = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-04-20 11:20:41 -04:00
|
|
|
after = [
|
|
|
|
"network-online.target"
|
|
|
|
"docker.service"
|
|
|
|
"atticd.service"
|
|
|
|
];
|
|
|
|
requires = [
|
|
|
|
"network-online.target"
|
|
|
|
"docker.service"
|
|
|
|
"atticd.service"
|
|
|
|
];
|
|
|
|
description = "Upload all store content to binary cache";
|
2024-03-24 13:08:42 -04:00
|
|
|
serviceConfig = {
|
|
|
|
User = "root";
|
|
|
|
Restart = "always";
|
|
|
|
ExecStart = "${pkgs.attic}/bin/attic watch-store cache-nix-dot";
|
|
|
|
};
|
2023-12-23 07:39:10 +01:00
|
|
|
};
|
|
|
|
|
2024-04-13 23:21:16 -04:00
|
|
|
users.users.root.openssh.authorizedKeys.keys = [
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJ/E/y4UJQid6/0D9babh8l/3jTDJRXqZQ5rPcoxwm1j root@palatine-hill"
|
|
|
|
];
|
|
|
|
|
|
|
|
users.users.hydra-queue-runner.openssh.authorizedKeys.keys = [
|
2024-04-13 23:47:31 -04:00
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJ/E/y4UJQid6/0D9babh8l/3jTDJRXqZQ5rPcoxwm1j root@palatine-hill"
|
2024-04-13 23:21:16 -04:00
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINHtwvfXg/QFjMAjC4JRjlMAaGPgEfSyhpprNpqbGSJn hydra-queue-runner@palatine-hill"
|
|
|
|
];
|
|
|
|
|
2024-04-20 11:30:15 -04:00
|
|
|
nix.gc.options = "--delete-older-than 150d";
|
2024-04-19 14:17:41 -04:00
|
|
|
|
2024-04-29 19:58:38 -04:00
|
|
|
# TODO: revert this once UPS is plugged in
|
|
|
|
# Not reverting this before the merge as the UPS not being plugged in is
|
|
|
|
# causing upgrades to fail
|
2024-04-27 20:48:44 -04:00
|
|
|
power.ups = {
|
2024-04-29 17:16:21 -04:00
|
|
|
enable = false;
|
2024-04-27 20:48:44 -04:00
|
|
|
ups."LX1325GU3" = {
|
|
|
|
driver = "usbhid-ups";
|
|
|
|
port = "auto";
|
|
|
|
description = "CyberPower LX1325GU3";
|
|
|
|
};
|
|
|
|
users.upsmon = {
|
|
|
|
passwordFile = config.sops.secrets."upsmon/password".path;
|
|
|
|
upsmon = "primary";
|
|
|
|
};
|
|
|
|
upsmon.monitor."LX1325GU3".user = "upsmon";
|
|
|
|
};
|
|
|
|
|
2024-02-01 16:50:14 -05:00
|
|
|
sops = {
|
|
|
|
defaultSopsFile = ./secrets.yaml;
|
2024-04-29 15:42:44 -04:00
|
|
|
secrets = {
|
|
|
|
"hydra/environment".owner = "hydra";
|
|
|
|
"nix-serve/secret-key".owner = "root";
|
|
|
|
"attic/secret-key".owner = "root";
|
|
|
|
"attic/database-url".owner = "root";
|
|
|
|
"postgres/init".owner = "postgres";
|
|
|
|
"alice/gha-hydra-token" = {
|
|
|
|
sopsFile = ../../users/alice/secrets.yaml;
|
|
|
|
owner = "hydra";
|
|
|
|
group = "hydra";
|
|
|
|
mode = "440";
|
|
|
|
};
|
|
|
|
"upsmon/password".owner = "root";
|
|
|
|
};
|
2024-02-01 16:50:14 -05:00
|
|
|
};
|
|
|
|
|
2023-12-23 08:27:00 +01:00
|
|
|
system.stateVersion = "23.05";
|
2023-12-25 12:40:59 -05:00
|
|
|
}
|