added server configs

This commit is contained in:
Bryan Ramos 2025-01-11 05:52:22 -05:00
parent 34ce975a09
commit 10e8a34586
Signed by: bryan
GPG key ID: 6ABDCD144D6643C8
4 changed files with 152 additions and 2 deletions

View file

@ -3,6 +3,7 @@
with lib;
let
cfg = config.modules.system.bitcoin;
nginx = config.modules.system.nginx;
home = "/var/lib/bitcoind";
@ -35,6 +36,11 @@ in
group = "bitcoin";
createHome = true;
};
"nginx" = {
extraGroups = mkIf nginx.enable [
"bitcoin"
];
};
};
groups = {
"bitcoin" = {
@ -49,8 +55,6 @@ in
btc = "bitcoind";
};
networking.firewall.allowedTCPPorts = [ 8333 ];
services.bitcoind = {
"btc" = {
enable = true;

View file

@ -0,0 +1,58 @@
{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.modules.system.forgejo;
nginx = config.modules.system.nginx;
in
{ options.modules.system.forgejo = { enable = mkEnableOption "Forgejo Server"; };
config = mkIf cfg.enable {
users = {
users = {
"git" = {
description = "Git server system user";
isSystemUser = true;
group = "git";
extraGroups = mkIf nginx.enable [
"web"
];
};
"nginx" = {
extraGroups = mkIf nginx.enable [
"git"
];
};
};
groups = {
"git" = {
members = [
"git"
];
};
};
};
services.forgejo = rec {
enable = true;
user = "git";
group = "git";
stateDir = "/var/lib/forgejo";
settings = {
server = {
PROTOCOL = "http+unix";
DOMAIN = "127.0.0.1";
HTTP_ADDR = "/run/forgejo/forgejo.sock";
};
};
database = {
inherit user;
type = "sqlite3";
path = "${stateDir}/data/forgejo.db";
createDatabase = true;
};
};
};
}

View file

@ -0,0 +1,86 @@
{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.modules.system.nginx;
module = config.modules.system;
in
{ options.modules.system.nginx = { enable = mkEnableOption "Nginx Reverse Proxy"; };
config = mkIf cfg.enable {
users = {
users = {
"nginx" = {
description = "Web server system user";
isSystemUser = true;
group = mkForce "web";
};
"btc" = {
extraGroups = mkIf module.bitcoin.enable [
"web"
];
};
"git" = {
extraGroups = mkIf module.forgejo.enable [
"web"
];
};
};
groups = {
"web" = {
members = [
"nginx"
];
};
};
};
security.acme =
let
acmeDir = "/var/lib/acme";
in
{
acceptTerms = true;
certs = {
"ramos.codes" = {
#webroot = "${acmeDir}/acme-challenge";
directory = "${acmeDir}/ramos.codes";
email = config.user.email;
group = "web";
validMinDays = 90;
extraDomainNames = attrNames config.services.nginx.virtualHosts;
listenHTTP = ":80";
};
};
};
services.nginx = {
enable = true;
virtualHosts =
let
certPath = config.security.acme.certs."ramos.codes".directory;
sslCertificate = "${certPath}/fullchain.pem";
sslCertificateKey = "${certPath}/key.pem";
withSSL = hosts: mapAttrs (name: hostConfig: hostConfig // {
inherit sslCertificate sslCertificateKey;
forceSSL = true;
}) hosts;
in withSSL
{
"git.ramos.codes" = mkIf module.forgejo.enable {
locations = {
"/" = {
proxyPass = "http://unix:${config.services.forgejo.settings.server.HTTP_ADDR}";
};
};
};
#"btc.ramos.codes" = mkIf module.bitcoin.enable {
# locations = {
# };
#};
};
};
};
}