petersweb-infra/nixos/linux.nix

270 lines
6.7 KiB
Nix
Raw Normal View History

2024-11-15 22:00:01 -09:00
{
config,
username,
hostname,
pkgs,
lib,
nix-index-database,
inputs,
specialArgs,
...
}: let
ddnsPkg = import ./invoke-ddns {inherit pkgs;};
startSeq = builtins.fromJSON ''"\u001b[7m"''; # Start inverted color
endSeq = builtins.fromJSON ''"\u001b[27m"''; # End inverted color
motd = "${startSeq} Welcome to the Peterson Mainframe! Look, touch, but DO NOT LICK. ${endSeq}";
nixPkgs = specialArgs.nixPkgs;
ourRustVersion = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.complete);
ourRustPlatform = nixPkgs.makeRustPlatform {
rustc = ourRustVersion;
cargo = ourRustVersion;
};
pullomaticPkg = import ./pullomatic {
inherit lib pkgs;
rustPlatform = ourRustPlatform;
specialArgs = {};
};
pullomatic = "${pullomaticPkg}/bin/pullomatic";
2024-12-06 23:48:02 -09:00
2024-12-07 01:06:16 -09:00
start-arion-run = pkgs.writeShellScriptBin "start-arion-run" ''
2024-12-07 01:20:54 -09:00
set -e
export PATH="${pkgs.nixVersions.stable}/bin:$PATH"
export NIX_PATH="nixpkgs=${pkgs.path}:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels"
2024-12-07 00:42:55 -09:00
cd /root/petersweb-infra/nixos/arion
2024-12-07 01:33:19 -09:00
${pkgs.arion}/bin/arion down 2>> /var/log/start-arion-run.log >> /var/log/start-arion-run.log
${pkgs.arion}/bin/arion up -d 2>> /var/log/start-arion-run.log >> /var/log/start-arion-run.log
2024-12-06 23:48:02 -09:00
'';
2024-11-15 22:00:01 -09:00
in {
imports = [
(import ./cloned_repos {inherit pkgs pullomatic lib;})
(import ./firewall.nix {inherit pkgs;})
2024-12-24 02:49:21 -09:00
(import ./nginx.nix {inherit pkgs lib config;})
2024-11-15 22:00:01 -09:00
(import ./system/users.nix {inherit pkgs config lib nix-index-database;})
];
time.timeZone = "America/Anchorage";
2024-12-22 02:23:47 -09:00
age.secrets = {
nearlyfreespeech = {
file = ./secrets/nearlyfreespeech.age;
owner = "root";
};
webdav = {
file = ./secrets/webdav.age;
owner = "root";
};
2026-05-04 13:44:07 -08:00
anthropic-api-key = {
file = ./secrets/anthropic-api-key.age;
owner = "root";
};
2024-12-22 02:23:47 -09:00
};
2024-11-15 22:00:01 -09:00
environment.systemPackages = [
ddnsPkg
pullomaticPkg
pkgs.vim
pkgs.php
pkgs.rustc
pkgs.cargo
pkgs.util-linux
pkgs.iotop
pkgs.rust-bin.stable.latest.default
pkgs.wget
2024-12-06 22:44:07 -09:00
2026-05-04 13:47:58 -08:00
pkgs.unstable.claude-code
2026-05-04 13:44:07 -08:00
2024-12-06 22:44:07 -09:00
# For docker-compose like setups
pkgs.arion
2024-12-06 23:29:41 -09:00
start-arion-run
2024-11-15 22:00:01 -09:00
];
swapDevices = [
{
device = "/swapfile";
size = 1 * 1024; # 1GB
}
];
2026-05-14 13:25:32 -08:00
systemd.services.forgejo-arion = {
description = "Forgejo via Arion";
after = [ "network.target" "podman.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${start-arion-run}/bin/start-arion-run";
};
};
2024-11-15 22:00:01 -09:00
systemd.tmpfiles.rules = [
"d /home/ironmagma/.config 0755 ${username} users"
"d /root/.config 0755 ${username} users"
];
networking.hostName = "${hostname}";
# FIXME: change your shell here if you don't want zsh
programs.zsh.enable = true;
2026-05-04 13:52:47 -08:00
programs.zsh.shellInit = ''
2026-05-04 13:44:07 -08:00
export ANTHROPIC_API_KEY=$(cat ${config.age.secrets.anthropic-api-key.path})
'';
2024-11-15 22:00:01 -09:00
environment.pathsToLink = ["/share/zsh"];
environment.shells = [pkgs.zsh];
environment.enableAllTerminfo = true;
security.sudo.wheelNeedsPassword = false;
users.motd = motd;
system.stateVersion = "22.05";
virtualisation.docker = {
enable = true;
enableOnBoot = true;
autoPrune.enable = true;
};
2024-12-06 22:48:27 -09:00
# Arion works with Docker, but for NixOS-based containers, you need Podman
# since NixOS 21.05.
virtualisation.podman = {
enable = true;
defaultNetwork.settings.dns_enabled = true;
2024-12-06 22:48:27 -09:00
};
2024-11-15 22:00:01 -09:00
virtualisation.oci-containers = {
backend = "docker";
containers = {
2024-12-07 01:54:11 -09:00
# Example:
# "hello" = {
# autoStart = true;
# image = "nginxdemos/hello";
# #user = "root:jellyfin";
# volumes = [
# ];
# ports = ["8081:80"];
# };
2024-11-15 22:00:01 -09:00
"navidrome" = {
autoStart = true;
environment = {
"TZ" = "America/Anchorage";
"PUID" = "1000";
"PGID" = "100";
"ND_SCANSCHEDULE" = "1h";
"ND_LOGLEVEL" = "info";
"ND_SESSIONTIMEOUT" = "24h";
"ND_BASEURL" = "";
};
ports = ["4533:4533"];
volumes = [
"/var/navidrome/data:/data"
"/var/navidrome/music:/music:ro"
];
image = "deluan/navidrome";
};
2025-01-14 20:43:46 -09:00
"nextcloud" = {
autoStart = true;
2025-01-14 21:13:17 -09:00
image = "quineglobal/ubuntu-with-ssh@sha256:64210887d48fae65bc4552503bf2d21a750ba0417ada530fd31254a8cc916746";
# image = "nextcloud/28-apache@sha256:ed95d344718ec86df96886b4b3465a9ce553c08b44b47306d399f0f201b04cb3";
2025-01-14 20:43:46 -09:00
volumes = [ ];
environment = { };
ports = ["8087:80"];
};
2025-01-14 21:13:17 -09:00
# "ubuntu" = {
# autoStart = true;
# image = "quineglobal/ubuntu-with-ssh@sha256:64210887d48fae65bc4552503bf2d21a750ba0417ada530fd31254a8cc916746";
# volumes = [ ];
# environment = {};
# ports = ["222:22"];
# };
2024-12-21 03:53:58 -09:00
"sync.io" = {
autoStart = true;
image = "quineglobal/sync.io@sha256:cbb180301fde42d8d22c26c952a4d4a487469d6491465302d8d79ebf194813b3";
2024-12-21 04:03:58 -09:00
volumes = [
"/var/syncio-cache:/sync.io-cache"
];
2024-12-21 03:53:58 -09:00
environment = {};
ports = ["9090:8080"];
2024-12-21 04:03:58 -09:00
user = "0"; # run as root
2024-12-21 03:53:58 -09:00
};
2025-01-04 01:12:38 -09:00
"blog-quine" = {
autoStart = true;
2025-06-15 23:45:34 -08:00
image = "quineglobal/blog-quine@sha256:3c2901f772c322d81f843c04d6982b9f50ff0b46d3cc457d9f868a7ff5a15497";
2025-01-04 01:12:38 -09:00
volumes = [];
environment = {};
ports = ["3010:8080"];
};
"riverside" = {
autoStart = true;
image = "forge.quinefoundation.com/ironmagma/riverside@sha256:ab62339730a4ea31a01b05e7fef6a5717d4217a79eb3480c2218eab9305181c3";
volumes = [];
environment = {};
ports = ["3011:8080"];
};
2024-11-15 22:00:01 -09:00
};
};
nix = {
settings = {
trusted-users = [username];
accept-flake-config = true;
auto-optimise-store = true;
};
registry = {
nixpkgs = {
flake = inputs.nixpkgs;
};
};
nixPath = [
"nixpkgs=${inputs.nixpkgs.outPath}"
"nixos-config=/etc/nixos/configuration.nix"
"/nix/var/nix/profiles/per-user/root/channels"
];
2026-05-04 05:31:21 -08:00
package = pkgs.nixVersions.stable;
2024-11-15 22:00:01 -09:00
extraOptions = ''experimental-features = nix-command flakes'';
gc = {
automatic = true;
options = "--delete-older-than 7d";
};
};
# HTTPS
security.acme = {
acceptTerms = true;
defaults.email = "peterson@sent.com";
certs."philippeterson.com" = {
dnsProvider = "nearlyfreespeech";
environmentFile = config.age.secrets."nearlyfreespeech".path;
webroot = null;
};
2024-12-22 02:47:07 -09:00
certs."webdav.philippeterson.com" = {
dnsProvider = "nearlyfreespeech";
environmentFile = config.age.secrets."nearlyfreespeech".path;
webroot = null;
};
2024-11-15 22:00:01 -09:00
};
}