Flakify this mamma jamma

main
Sam Hatfield 2 years ago
parent dd646c0be2
commit 14fcf9e32a

@ -1,4 +1 @@
eval "$(lorri direnv)"
export SSH_IDENTITY_FILE="/home/sam/.ssh/terraform"
export SSH_USER="root"
use flake

@ -0,0 +1,196 @@
{ config, lib, pkgs, ... }: {
# COMMON CONFIG
nix.gc.automatic = true;
nixpkgs.config.allowUnfree = true;
networking.firewall.allowedTCPPorts = [ 20 21 80 443 8888 25565 ];
networking.firewall.allowedTCPPortRanges = [{
from = 56250;
to = 56260;
}];
security.acme.acceptTerms = true;
services.nginx.enable = true;
services.nginx.recommendedProxySettings = true;
services.nginx.recommendedTlsSettings = true;
virtualisation.oci-containers.backend = "podman";
# IPFS
services.ipfs = {
enable = true;
enableGC = true;
emptyRepo = true;
};
# MINECRAFT
systemd.services.fabric-minecraft-server = {
description = "Fabric+Minecraft Server Service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
restartTriggers = [ /home/mar ];
serviceConfig = {
ExecStart = "${pkgs.adoptopenjdk-jre-hotspot-bin-16}/bin/java -Dlog4j2.formatMsgNoLookups=true -jar fabric-server-launch.jar";
Restart = "always";
WorkingDirectory = "/home/mar";
};
};
services.vsftpd = {
enable = true;
writeEnable = true;
localUsers = true;
extraConfig = ''
pasv_min_port=56250
pasv_max_port=56260
'';
};
# PAPERLESS
services.paperless-ng = {
enable = true;
extraConfig = {
PAPERLESS_DISABLE_LOGIN = "false";
PAPERLESS_PASSPHRASE = "$(< /run/keys/paperless_passphrase)";
PAPERLESS_FORGIVING_OCR = "true";
};
};
security.acme.certs."paperless.samhatfield.me".email = "hey@samhatfield.me";
services.nginx.virtualHosts."paperless.samhatfield.me" =
let cfg = config.services.paperless-ng;
in {
enableACME = true;
forceSSL = true;
locations = {
"/" = {
proxyPass = "http://${cfg.address}:${toString cfg.port}";
extraConfig = ''
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
'';
};
"/static/" = {
alias = "${cfg.dataDir}/static/";
extraConfig = ''
autoindex on;
'';
};
};
};
users.users.paperless = {
isSystemUser = true;
extraGroups = [ "keys" ];
};
# LYCHEE
users.users.lychee = {
description = "Lychee server service user";
group = "users";
isSystemUser = true;
home = "/var/lib/lychee";
createHome = true;
};
virtualisation.oci-containers.containers."Lychee" = {
image = "lycheeorg/lychee";
ports = [ "8888:80" ];
volumes = [
"/var/lib/lychee/uploads:/uploads"
"/var/lib/lychee/sym:/sym"
"/var/lib/lychee/conf:/conf"
];
};
security.acme.certs."lychee.samhatfield.me".email = "hey@samhatfield.me";
services.nginx.virtualHosts."lychee.samhatfield.me" = {
enableACME = true;
forceSSL = true;
locations = { "/" = { proxyPass = "http://localhost:8888"; }; };
};
# BORGBACKUP JOBS
services.borgbackup = {
jobs = let
job = name: value: {
paths = value;
repo = "/root/backup";
encryption = {
mode = "repokey";
passCommand = "cat /run/keys/borgbackup_passphrase";
};
compression = "auto,lzma";
startAt = "weekly";
};
in lib.attrsets.mapAttrs job {
paperless = "/var/lib/paperless";
lychee = "/var/lib/lychee";
minecraft = "/home/mar";
taskserver = "/var/lib/taskserver";
hedgedoc = "/var/lib/hedgedoc";
};
};
# WEBSITES
# samhatfield.me
security.acme.certs."samhatfield.me".email = "hey@samhatfield.me";
services.nginx.virtualHosts."samhatfield.me" = {
enableACME = true;
forceSSL = true;
root = "/var/www/html/samhatfield.me";
};
# beccastevens.me
security.acme.certs."beccastevens.me".email = "hello@beccastevens.me";
services.nginx.virtualHosts."beccastevens.me" = {
enableACME = true;
forceSSL = true;
root = "/var/www/html/beccastevens.me/web";
};
# HEDGEDOC
security.acme.certs."hedgedoc.samhatfield.me".email = "hey@samhatfield.me";
services.nginx.virtualHosts."hedgedoc.samhatfield.me" = {
enableACME = true;
forceSSL = true;
locations = let host = config.services.hedgedoc.configuration.host;
port = toString config.services.hedgedoc.configuration.port;
in {
"/" = {
proxyPass = "http://${host}:${port}";
};
"/socket.io/" = {
proxyPass = "http://${host}:${port}";
proxyWebsockets = true;
};
};
};
services.hedgedoc = let cfg = config.services.hedgedoc; in {
enable = true;
configuration = {
db = {
dialect = "sqlite";
storage = "${cfg.workDir}/db.hedgedoc.sqlite";
};
};
};
# SEHQLR
users.users.sehqlr = {
isNormalUser = true;
home = "/home/sehqlr";
description = "Sam Hatfield <hey@samhatfield.me>";
extraGroups = [ "wheel" ];
shell = pkgs.zsh;
};
}

@ -0,0 +1,237 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs"
mms.url = "github:mkaito/nixos-modded-minecraft-servers";
pea.url = "git+https://git.bytes.zone/sehqlr/personal-effectivity-application.git";
};
outputs = { self, mms, nixpkgs, ...}@attrs: {
nixosConfiguration."samhatfield.me" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
({ config, lib, ... }: let port = 25566; in {
imports = [ mms.module ];
services.modded-minecraft-servers = {
eula = true;
oasis = {
enable = true;
serverConfig = {
server-port = port + 1;
motd = "Welcome to the Oasis SMP";
};
};
mythic = {
enable = true;
serverConfig = {
server-port = port + 2;
motd = "Welcome to the Mythic SMP";
};
};
};
})
];
};
};
}
/*
{ config, lib, pkgs, ... }: {
# COMMON CONFIG
nix.gc.automatic = true;
nixpkgs.config.allowUnfree = true;
networking.firewall.allowedTCPPorts = [ 20 21 80 443 8888 25565 ];
networking.firewall.allowedTCPPortRanges = [{
from = 56250;
to = 56260;
}];
security.acme.acceptTerms = true;
services.nginx.enable = true;
services.nginx.recommendedProxySettings = true;
services.nginx.recommendedTlsSettings = true;
virtualisation.oci-containers.backend = "podman";
# IPFS
services.ipfs = {
enable = true;
enableGC = true;
emptyRepo = true;
};
# MINECRAFT
systemd.services.fabric-minecraft-server = {
description = "Fabric+Minecraft Server Service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
restartTriggers = [ /home/mar ];
serviceConfig = {
ExecStart = "${pkgs.adoptopenjdk-jre-hotspot-bin-16}/bin/java -Dlog4j2.formatMsgNoLookups=true -jar fabric-server-launch.jar";
Restart = "always";
WorkingDirectory = "/home/mar";
};
};
services.vsftpd = {
enable = true;
writeEnable = true;
localUsers = true;
extraConfig = ''
pasv_min_port=56250
pasv_max_port=56260
'';
};
# PAPERLESS
services.paperless-ng = {
enable = true;
extraConfig = {
PAPERLESS_DISABLE_LOGIN = "false";
PAPERLESS_PASSPHRASE = "$(< /run/keys/paperless_passphrase)";
PAPERLESS_FORGIVING_OCR = "true";
};
};
security.acme.certs."paperless.samhatfield.me".email = "hey@samhatfield.me";
services.nginx.virtualHosts."paperless.samhatfield.me" =
let cfg = config.services.paperless-ng;
in {
enableACME = true;
forceSSL = true;
locations = {
"/" = {
proxyPass = "http://${cfg.address}:${toString cfg.port}";
extraConfig = ''
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
'';
};
"/static/" = {
alias = "${cfg.dataDir}/static/";
extraConfig = ''
autoindex on;
'';
};
};
};
users.users.paperless = {
isSystemUser = true;
extraGroups = [ "keys" ];
};
# LYCHEE
users.users.lychee = {
description = "Lychee server service user";
group = "users";
isSystemUser = true;
home = "/var/lib/lychee";
createHome = true;
};
virtualisation.oci-containers.containers."Lychee" = {
image = "lycheeorg/lychee";
ports = [ "8888:80" ];
volumes = [
"/var/lib/lychee/uploads:/uploads"
"/var/lib/lychee/sym:/sym"
"/var/lib/lychee/conf:/conf"
];
};
security.acme.certs."lychee.samhatfield.me".email = "hey@samhatfield.me";
services.nginx.virtualHosts."lychee.samhatfield.me" = {
enableACME = true;
forceSSL = true;
locations = { "/" = { proxyPass = "http://localhost:8888"; }; };
};
# BORGBACKUP JOBS
services.borgbackup = {
jobs = let
job = name: value: {
paths = value;
repo = "/root/backup";
encryption = {
mode = "repokey";
passCommand = "cat /run/keys/borgbackup_passphrase";
};
compression = "auto,lzma";
startAt = "weekly";
};
in lib.attrsets.mapAttrs job {
paperless = "/var/lib/paperless";
lychee = "/var/lib/lychee";
minecraft = "/home/mar";
taskserver = "/var/lib/taskserver";
hedgedoc = "/var/lib/hedgedoc";
};
};
# WEBSITES
# samhatfield.me
security.acme.certs."samhatfield.me".email = "hey@samhatfield.me";
services.nginx.virtualHosts."samhatfield.me" = {
enableACME = true;
forceSSL = true;
root = "/var/www/html/samhatfield.me";
};
# beccastevens.me
security.acme.certs."beccastevens.me".email = "hello@beccastevens.me";
services.nginx.virtualHosts."beccastevens.me" = {
enableACME = true;
forceSSL = true;
root = "/var/www/html/beccastevens.me/web";
};
# HEDGEDOC
security.acme.certs."hedgedoc.samhatfield.me".email = "hey@samhatfield.me";
services.nginx.virtualHosts."hedgedoc.samhatfield.me" = {
enableACME = true;
forceSSL = true;
locations = let host = config.services.hedgedoc.configuration.host;
port = toString config.services.hedgedoc.configuration.port;
in {
"/" = {
proxyPass = "http://${host}:${port}";
};
"/socket.io/" = {
proxyPass = "http://${host}:${port}";
proxyWebsockets = true;
};
};
};
services.hedgedoc = let cfg = config.services.hedgedoc; in {
enable = true;
configuration = {
db = {
dialect = "sqlite";
storage = "${cfg.workDir}/db.hedgedoc.sqlite";
};
};
};
# SEHQLR
users.users.sehqlr = {
isNormalUser = true;
home = "/home/sehqlr";
description = "Sam Hatfield <hey@samhatfield.me>";
extraGroups = [ "wheel" ];
shell = pkgs.zsh;
};
}
*/

@ -1,36 +0,0 @@
let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs { };
in {
network = {
inherit pkgs;
description = "samhatfield.me web services";
};
"samhatfield.me" = { config, pkgs, ... }: {
imports = [ ./services/ipfs.nix ./services/minecraft-server.nix ];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
fileSystems = {
"/" = {
label = "nixos";
fsType = "ext4";
};
"/boot" = {
label = "boot";
fsType = "vfat";
};
};
nixpkgs.config.packageOverrides = pkgs: {
nur = import (builtins.fetchTarball
"https://github.com/nix-community/NUR/archive/master.tar.gz") {
inherit pkgs;
};
};
services.openssh.enable = true;
};
}

@ -23,7 +23,7 @@ resource "digitalocean_droplet" "main" {
resource "digitalocean_volume" "storage" {
region = "nyc3"
name = "storage"
size = 100
size = 1000
initial_filesystem_type = "ext4"
description = "main storage volume"
}
@ -33,10 +33,12 @@ resource "digitalocean_volume_attachment" "storage" {
volume_id = digitalocean_volume.storage.id
}
# DOMAINS
resource "digitalocean_domain" "default" {
name = "samhatfield.me"
}
# WEB SERVICES
resource "digitalocean_record" "www" {
domain = digitalocean_domain.default.name
type = "A"
@ -44,13 +46,6 @@ resource "digitalocean_record" "www" {
value = digitalocean_droplet.main.ipv4_address
}
resource "digitalocean_record" "nextcloud" {
domain = digitalocean_domain.default.name
type = "CNAME"
name = "files"
value = "samhatfield.me."
}
# GITHUB PAGES
resource "digitalocean_record" "neuron" {
domain = digitalocean_domain.default.name
@ -58,69 +53,3 @@ resource "digitalocean_record" "neuron" {
name = "neuron"
value = "sehqlr.github.io."
}
# EMAIL SETTINGS
resource "digitalocean_record" "mx1" {
domain = digitalocean_domain.default.name
type = "MX"
name = "@"
priority = 10
value = "in1-smtp.messagingengine.com."
}
resource "digitalocean_record" "mx2" {
domain = digitalocean_domain.default.name
type = "MX"
name = "@"
priority = 20
value = "in2-smtp.messagingengine.com."
}
resource "digitalocean_record" "dkim1" {
domain = digitalocean_domain.default.name
type = "CNAME"
name = "fm1._domainkey"
value = "fm1.samhatfield.me.dkim.fmhosted.com."
}
resource "digitalocean_record" "dkim2" {
domain = digitalocean_domain.default.name
type = "CNAME"
name = "fm2._domainkey"
value = "fm2.samhatfield.me.dkim.fmhosted.com."
}
resource "digitalocean_record" "dkim3" {
domain = digitalocean_domain.default.name
type = "CNAME"
name = "fm3._domainkey"
value = "fm3.samhatfield.me.dkim.fmhosted.com."
}
resource "digitalocean_record" "txt" {
domain = digitalocean_domain.default.name
type = "TXT"
name = "@"
value = "v=spf1 include:spf.messagingengine.com ?all"
}
# DNS
resource "digitalocean_record" "ns1" {
domain = digitalocean_domain.default.name
type = "NS"
name = "@"
value = "ns1.digitalocean.com."
}
resource "digitalocean_record" "ns2" {
domain = digitalocean_domain.default.name
type = "NS"
name = "@"
value = "ns2.digitalocean.com."
}
resource "digitalocean_record" "n3" {
domain = digitalocean_domain.default.name
type = "NS"
name = "@"
value = "ns3.digitalocean.com."
}

@ -1,26 +0,0 @@
{
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",
"homepage": "https://github.com/nmattia/niv",
"owner": "nmattia",
"repo": "niv",
"rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070",
"sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx",
"type": "tarball",
"url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42070.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "release-21.05",
"description": "Nix Packages collection",
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "15379213a4bd7f91605418f0b9d74653ee4cea10",
"sha256": "0ggkd5lz017lva4chsfl4yj2haazrgpncbilszavxhp7wr4m4ydw",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/15379213a4bd7f91605418f0b9d74653ee4cea10.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}

@ -1,174 +0,0 @@
# This file has been generated by Niv.
let
#
# The fetchers. fetch_<type> fetches specs of type <type>.
#
fetch_file = pkgs: name: spec:
let
name' = sanitizeName name + "-src";
in
if spec.builtin or true then
builtins_fetchurl { inherit (spec) url sha256; name = name'; }
else
pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
fetch_tarball = pkgs: name: spec:
let
name' = sanitizeName name + "-src";
in
if spec.builtin or true then
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
else
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
fetch_git = name: spec:
let
ref =
if spec ? ref then spec.ref else
if spec ? branch then "refs/heads/${spec.branch}" else
if spec ? tag then "refs/tags/${spec.tag}" else
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
in
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
fetch_local = spec: spec.path;
fetch_builtin-tarball = name: throw
''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
$ niv modify ${name} -a type=tarball -a builtin=true'';
fetch_builtin-url = name: throw
''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
$ niv modify ${name} -a type=file -a builtin=true'';
#
# Various helpers
#
# https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
sanitizeName = name:
(
concatMapStrings (s: if builtins.isList s then "-" else s)
(
builtins.split "[^[:alnum:]+._?=-]+"
((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
)
);
# The set of packages used when specs are fetched using non-builtins.
mkPkgs = sources: system:
let
sourcesNixpkgs =
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in
if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> {}
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';
# The actual fetching function.
fetch = pkgs: name: spec:
if ! builtins.hasAttr "type" spec then
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
else if spec.type == "file" then fetch_file pkgs name spec
else if spec.type == "tarball" then fetch_tarball pkgs name spec
else if spec.type == "git" then fetch_git name spec
else if spec.type == "local" then fetch_local spec
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
else if spec.type == "builtin-url" then fetch_builtin-url name
else
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
# If the environment variable NIV_OVERRIDE_${name} is set, then use
# the path directly as opposed to the fetched source.
replace = name: drv:
let
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
in
if ersatz == "" then drv else
# this turns the string into an actual Nix path (for both absolute and
# relative paths)
if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
# Ports of functions for older nix versions
# a Nix version of mapAttrs if the built-in doesn't exist
mapAttrs = builtins.mapAttrs or (
f: set: with builtins;
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
concatMapStrings = f: list: concatStrings (map f list);
concatStrings = builtins.concatStringsSep "";
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
optionalAttrs = cond: as: if cond then as else {};
# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else
fetchTarball attrs;
# fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, name ? null, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12" then
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else
fetchurl attrs;
# Create the final "sources" from the config
mkSources = config:
mapAttrs (
name: spec:
if builtins.hasAttr "outPath" spec
then abort
"The values in sources.json should not have an 'outPath' attribute"
else
spec // { outPath = replace name (fetch config.pkgs name spec); }
) config.sources;
# The "config" used by the fetchers
mkConfig =
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
, sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
, system ? builtins.currentSystem
, pkgs ? mkPkgs sources system
}: rec {
# The sources, i.e. the attribute set of spec name to spec
inherit sources;
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
inherit pkgs;
};
in
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }

@ -1,7 +0,0 @@
{ config, pkgs, ... }: {
services.ipfs = {
enable = true;
enableGC = true;
emptyRepo = true;
};
}

@ -1,8 +0,0 @@
{ config, pkgs, ... }:
{
services.minecraft-server = {
enable = true;
eula = true;
openFirewall = true;
};
}

@ -1,4 +0,0 @@
let sources = import ./nix/sources.nix;
in { pkgs ? import sources.nixpkgs { } }:
pkgs.mkShell { buildInputs = [ pkgs.doctl pkgs.morph pkgs.terraform-full ]; }
Loading…
Cancel
Save