forgejo works now but vaultwarden is fucky
This commit is contained in:
parent
f1b3559434
commit
02eb92a443
5 changed files with 140 additions and 15 deletions
|
|
@ -10,6 +10,12 @@
|
||||||
|
|
||||||
users.default.enable = true;
|
users.default.enable = true;
|
||||||
|
|
||||||
|
containers = {
|
||||||
|
forgejo.enable = true;
|
||||||
|
nginx.enable = true;
|
||||||
|
vaultwarden.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
base = {
|
base = {
|
||||||
nix.enable = true;
|
nix.enable = true;
|
||||||
locale.enable = true;
|
locale.enable = true;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
imports = [
|
imports = [
|
||||||
./nginx.nix
|
./nginx.nix
|
||||||
./forgejo.nix
|
./forgejo.nix
|
||||||
|
./vaultwarden.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,35 @@
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) mkEnableOption mkIf;
|
inherit (lib) types mkOption mkEnableOption mkIf;
|
||||||
cfg = config.horseman.containers.forgejo;
|
cfg = config.horseman.containers.forgejo;
|
||||||
username = config.horseman.username;
|
username = config.horseman.username;
|
||||||
|
|
||||||
HTTP_PORT = 3000;
|
|
||||||
SSH_PORT = 34916;
|
|
||||||
INSTANCE_URL = "http://local.git.server:3000";
|
|
||||||
DATA_DIR = "/home/${username}/backups/volumes/forgejo";
|
DATA_DIR = "/home/${username}/backups/volumes/forgejo";
|
||||||
BACKUP_FILE = "/home/${username}/backups/forgejo.tar";
|
BACKUP_FILE = "/home/${username}/backups/forgejo.tar";
|
||||||
in {
|
in {
|
||||||
options = {
|
options = {
|
||||||
horseman.containers.forgejo = {
|
horseman.containers.forgejo = {
|
||||||
enable = mkEnableOption "forgejo containers";
|
enable = mkEnableOption "forgejo containers";
|
||||||
|
|
||||||
|
port = mkOption {
|
||||||
|
default = 3000;
|
||||||
|
type = types.int;
|
||||||
|
};
|
||||||
|
|
||||||
|
sshPort = mkOption {
|
||||||
|
default = 34916;
|
||||||
|
type = types.int;
|
||||||
|
};
|
||||||
|
|
||||||
|
url = mkOption {
|
||||||
|
default = "https://git.koendev.nl";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
networking.extraHosts = "192.168.100.3 local.git.server";
|
|
||||||
|
|
||||||
systemd.timers."backup-forgejo" = {
|
systemd.timers."backup-forgejo" = {
|
||||||
wantedBy = ["timers.target"];
|
wantedBy = ["timers.target"];
|
||||||
timerConfig = {
|
timerConfig = {
|
||||||
|
|
@ -36,7 +46,7 @@ in {
|
||||||
environment.systemPackages = [pkgs.gnutar];
|
environment.systemPackages = [pkgs.gnutar];
|
||||||
systemd.services."backup-forgejo" = {
|
systemd.services."backup-forgejo" = {
|
||||||
script = ''
|
script = ''
|
||||||
${pkgs.gnutar} -cf ${BACKUP_FILE} ${DATA_DIR}
|
${pkgs.gnutar}/bin/tar -cf ${BACKUP_FILE} ${DATA_DIR}
|
||||||
'';
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
User = "root";
|
User = "root";
|
||||||
|
|
@ -123,9 +133,9 @@ in {
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
server = {
|
server = {
|
||||||
HTTP_PORT = HTTP_PORT;
|
HTTP_PORT = cfg.port;
|
||||||
SSH_PORT = SSH_PORT;
|
SSH_PORT = cfg.sshPort;
|
||||||
ROOT_URL = INSTANCE_URL;
|
ROOT_URL = cfg.url;
|
||||||
};
|
};
|
||||||
session = {
|
session = {
|
||||||
COOKIE_SECURE = false; # TODO Set to true
|
COOKIE_SECURE = false; # TODO Set to true
|
||||||
|
|
@ -148,7 +158,7 @@ in {
|
||||||
networking = {
|
networking = {
|
||||||
firewall = {
|
firewall = {
|
||||||
enable = true;
|
enable = true;
|
||||||
allowedTCPPorts = [HTTP_PORT SSH_PORT];
|
allowedTCPPorts = [cfg.port cfg.sshPort];
|
||||||
};
|
};
|
||||||
# Use systemd-resolved inside the container
|
# Use systemd-resolved inside the container
|
||||||
# Workaround for bug https://github.com/NixOS/nixpkgs/issues/162686
|
# Workaround for bug https://github.com/NixOS/nixpkgs/issues/162686
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) mkEnableOption mkIf mkOption types;
|
inherit (lib) mkEnableOption mkIf mkOption types;
|
||||||
cfg = config.horseman.containers.nginx;
|
cfg = config.horseman.containers.nginx;
|
||||||
|
osConfig = config;
|
||||||
in {
|
in {
|
||||||
options = {
|
options = {
|
||||||
horseman.containers.nginx = {
|
horseman.containers.nginx = {
|
||||||
|
|
@ -16,7 +17,7 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
networking.extraHosts = "192.168.100.1 koendev.nl *.koendev.nl";
|
networking.extraHosts = "192.168.100.1 koendevLocal.nl git.koendevLocal.nl vault.koendevLocal.nl";
|
||||||
|
|
||||||
containers.nginx = {
|
containers.nginx = {
|
||||||
autoStart = true;
|
autoStart = true;
|
||||||
|
|
@ -41,15 +42,19 @@ in {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
virtualHosts = {
|
virtualHosts = {
|
||||||
"koendev.nl" = {
|
"koendevLocal.nl" = {
|
||||||
# addSSL = false;
|
# addSSL = false;
|
||||||
# enableACME = false;
|
# enableACME = false;
|
||||||
root = "/var/www/portfolio";
|
root = "/var/www/portfolio";
|
||||||
|
default = true;
|
||||||
|
extraConfig = ''
|
||||||
|
error_page 404 /404.html;
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
"vault.koendev.nl" = {
|
"git.koendevLocal.nl" = {
|
||||||
locations."/" = {
|
locations."/" = {
|
||||||
proxyPass = "http://172.16.0.2";
|
proxyPass = "http://${osConfig.containers.forgejo.localAddress}:${toString osConfig.horseman.containers.forgejo.port}";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
103
modules/containers/vaultwarden.nix
Normal file
103
modules/containers/vaultwarden.nix
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
{
|
||||||
|
inputs,
|
||||||
|
outputs,
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit (lib) types mkOption mkEnableOption mkIf;
|
||||||
|
cfg = config.horseman.containers.vaultwarden;
|
||||||
|
username = config.horseman.username;
|
||||||
|
|
||||||
|
DATA_DIR = "/home/${username}/backups/volumes/vaultwarden";
|
||||||
|
BACKUP_FILE = "/home/${username}/backups/vaultwarden.tar";
|
||||||
|
in {
|
||||||
|
options = {
|
||||||
|
horseman.containers.vaultwarden = {
|
||||||
|
enable = mkEnableOption "forgejo containers";
|
||||||
|
|
||||||
|
port = mkOption {
|
||||||
|
default = 3000;
|
||||||
|
type = types.int;
|
||||||
|
};
|
||||||
|
|
||||||
|
url = mkOption {
|
||||||
|
default = "https://vault.koendev.nl";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
systemd.timers."backup-vaultwarden" = {
|
||||||
|
wantedBy = ["timers.target"];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = "daily";
|
||||||
|
Persistent = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
environment.systemPackages = [pkgs.gnutar];
|
||||||
|
systemd.services."backup-vaultwarden" = {
|
||||||
|
script = ''
|
||||||
|
${pkgs.gnutar}/bin/tar -cf ${BACKUP_FILE} ${DATA_DIR}
|
||||||
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
User = "root";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
containers.vaultwarden = {
|
||||||
|
autoStart = true;
|
||||||
|
privateNetwork = true;
|
||||||
|
hostAddress = "172.16.0.4";
|
||||||
|
localAddress = "192.168.100.4";
|
||||||
|
|
||||||
|
bindMounts = {
|
||||||
|
"/var/lib/vaultwarden" = {
|
||||||
|
hostPath = DATA_DIR;
|
||||||
|
isReadOnly = false;
|
||||||
|
}; # TODO set correct
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
environment.variables = {
|
||||||
|
ROCKET_ADDRESS = "127.0.0.1";
|
||||||
|
ROCKET_PORT = toString cfg.port;
|
||||||
|
WEB_VAULT_ENABLED = "false";
|
||||||
|
};
|
||||||
|
|
||||||
|
services.vaultwarden = {
|
||||||
|
enable = true;
|
||||||
|
backupDir = "/var/local/vaultwarden/backup";
|
||||||
|
# in order to avoid having ADMIN_TOKEN in the nix store it can be also set with the help of an environment file
|
||||||
|
# be aware that this file must be created by hand (or via secrets management like sops)
|
||||||
|
environmentFile = "/var/lib/vaultwarden/vaultwarden.env";
|
||||||
|
config = {
|
||||||
|
DOMAIN = cfg.url;
|
||||||
|
SIGNUPS_ALLOWED = false;
|
||||||
|
|
||||||
|
ROCKET_ADDRESS = "127.0.0.1";
|
||||||
|
ROCKET_PORT = cfg.port;
|
||||||
|
ROCKET_LOG = "critical";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
networking = {
|
||||||
|
firewall = {
|
||||||
|
enable = true;
|
||||||
|
allowedTCPPorts = [cfg.port];
|
||||||
|
};
|
||||||
|
useHostResolvConf = lib.mkForce false;
|
||||||
|
};
|
||||||
|
|
||||||
|
system.stateVersion = "23.11";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue