mirror of
https://github.com/phfroidmont/self-hosting.git
synced 2025-12-25 13:46:59 +01:00
Start migrating config to NixOS modules
This commit is contained in:
parent
c1211cb4e5
commit
c0d929be0b
11 changed files with 283 additions and 183 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
cfg = config.services.custom-backup-job;
|
cfg = config.custom.services.backup-job;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.custom-backup-job = {
|
options.custom.services.backup-job = {
|
||||||
|
enable = mkEnableOption "backup-job";
|
||||||
|
|
||||||
additionalPaths = mkOption {
|
additionalPaths = mkOption {
|
||||||
type = with types; listOf path;
|
type = with types; listOf path;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
|
|
@ -35,7 +37,7 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
sops.secrets = {
|
sops.secrets = {
|
||||||
borgPassphrase = {
|
borgPassphrase = {
|
||||||
|
|
@ -43,6 +45,7 @@ in
|
||||||
key = "borg/passphrase";
|
key = "borg/passphrase";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.borgbackup.jobs.data = {
|
services.borgbackup.jobs.data = {
|
||||||
paths = [ "/nix/var/data" cfg.sshKey ] ++ cfg.additionalPaths;
|
paths = [ "/nix/var/data" cfg.sshKey ] ++ cfg.additionalPaths;
|
||||||
doInit = false;
|
doInit = false;
|
||||||
|
|
@ -1,13 +1,20 @@
|
||||||
{ config, ... }:
|
{ config, lib, ... }:
|
||||||
|
with lib;
|
||||||
|
let
|
||||||
|
cfg = config.custom.services.binary-cache;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
|
options.custom.services.binary-cache = {
|
||||||
|
|
||||||
sops.secrets = {
|
enable = mkEnableOption "binary-cache";
|
||||||
nixCacheKey = {
|
|
||||||
key = "nix/cache_secret_key";
|
secretKeyFile = mkOption {
|
||||||
|
type = types.path;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
services.nix-serve = {
|
services.nix-serve = {
|
||||||
enable = true;
|
enable = true;
|
||||||
port = 1500;
|
port = 1500;
|
||||||
|
|
@ -30,4 +37,5 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
modules/default.nix
Normal file
10
modules/default.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
{ config, pkgs, ... }:
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
./backup-job.nix
|
||||||
|
./monit.nix
|
||||||
|
./gitlab-runner.nix
|
||||||
|
./openssh.nix
|
||||||
|
./murmur.nix
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
with lib;
|
||||||
let
|
let
|
||||||
|
cfg = config.custom.services.dokuwiki;
|
||||||
|
|
||||||
configureWiki = name: {
|
configureWiki = name: {
|
||||||
|
|
||||||
sops.secrets."usersFile-${name}" = {
|
sops.secrets."usersFile-${name}" = {
|
||||||
|
|
@ -25,7 +28,20 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
lib.mkMerge [
|
{
|
||||||
|
options.custom.services.dokuwiki = {
|
||||||
|
|
||||||
|
enable = mkEnableOption "dokuwiki";
|
||||||
|
|
||||||
|
secretKeyFile = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
config = mkIf cfg.enable
|
||||||
|
(lib.mkMerge [
|
||||||
(configureWiki "anderia")
|
(configureWiki "anderia")
|
||||||
(configureWiki "arkadia")
|
(configureWiki "arkadia")
|
||||||
]
|
]);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,14 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
with lib;
|
||||||
|
let
|
||||||
|
cfg = config.custom.services.gitlab-runner;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
|
options.custom.services.gitlab-runner = {
|
||||||
|
enable = mkEnableOption "gitlab-runner";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
sops.secrets = {
|
sops.secrets = {
|
||||||
runnerRegistrationConfig = {
|
runnerRegistrationConfig = {
|
||||||
owner = config.users.users.gitlab-runner.name;
|
owner = config.users.users.gitlab-runner.name;
|
||||||
|
|
@ -79,4 +88,5 @@
|
||||||
system.stateVersion = "22.05";
|
system.stateVersion = "22.05";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
cfg = config.services.custom-monit;
|
cfg = config.custom.services.monit;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.custom-monit = {
|
options.custom.services.monit = {
|
||||||
|
enable = mkEnableOption "monit";
|
||||||
|
|
||||||
additionalConfig = mkOption {
|
additionalConfig = mkOption {
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
|
|
@ -1,5 +1,15 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, ... }:
|
||||||
|
with lib;
|
||||||
|
let
|
||||||
|
cfg = config.custom.services.murmur;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
|
options.custom.services.murmur = {
|
||||||
|
enable = mkEnableOption "murmur";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
sops.secrets.murmurEnvFile = {
|
sops.secrets.murmurEnvFile = {
|
||||||
owner = config.systemd.services.murmur.serviceConfig.User;
|
owner = config.systemd.services.murmur.serviceConfig.User;
|
||||||
key = "murmur.env";
|
key = "murmur.env";
|
||||||
|
|
@ -13,4 +23,5 @@
|
||||||
environmentFile = config.sops.secrets.murmurEnvFile.path;
|
environmentFile = config.sops.secrets.murmurEnvFile.path;
|
||||||
imgMsgLength = 13107200;
|
imgMsgLength = 13107200;
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,20 @@
|
||||||
{ pkgs, lib, config, ... }:
|
{ config, lib, ... }:
|
||||||
|
with lib;
|
||||||
|
let
|
||||||
|
cfg = config.custom.services.openssh;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
|
options.custom.services.openssh = {
|
||||||
|
enable = mkEnableOption "openssh";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
services.openssh.enable = true;
|
services.openssh.enable = true;
|
||||||
services.openssh.permitRootLogin = "prohibit-password";
|
services.openssh.permitRootLogin = "prohibit-password";
|
||||||
users.users.root.openssh.authorizedKeys.keyFiles = [
|
users.users.root.openssh.authorizedKeys.keyFiles = [
|
||||||
../ssh_keys/phfroidmont-desktop.pub
|
../ssh_keys/phfroidmont-desktop.pub
|
||||||
../ssh_keys/froidmpa-laptop.pub
|
../ssh_keys/froidmpa-laptop.pub
|
||||||
];
|
];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,10 @@
|
||||||
imports = [
|
imports = [
|
||||||
../environment.nix
|
../environment.nix
|
||||||
../hardware/hcloud.nix
|
../hardware/hcloud.nix
|
||||||
../modules/openssh.nix
|
../modules
|
||||||
../modules/nginx.nix
|
../modules/nginx.nix
|
||||||
../modules/murmur.nix
|
|
||||||
../modules/synapse.nix
|
../modules/synapse.nix
|
||||||
../modules/nextcloud.nix
|
../modules/nextcloud.nix
|
||||||
../modules/custom-backup-job.nix
|
|
||||||
../modules/custom-monit.nix
|
|
||||||
../modules/dokuwiki.nix
|
../modules/dokuwiki.nix
|
||||||
../modules/website-marie.nix
|
../modules/website-marie.nix
|
||||||
../modules/roundcube.nix
|
../modules/roundcube.nix
|
||||||
|
|
@ -23,7 +20,9 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.custom-backup-job = {
|
custom = {
|
||||||
|
services.backup-job = {
|
||||||
|
enable = true;
|
||||||
additionalPaths = [ "/var/lib/nextcloud/config" ];
|
additionalPaths = [ "/var/lib/nextcloud/config" ];
|
||||||
readWritePaths = [ "/nix/var/data/murmur" "/nix/var/data/backup/" ];
|
readWritePaths = [ "/nix/var/data/murmur" "/nix/var/data/backup/" ];
|
||||||
preHook = ''
|
preHook = ''
|
||||||
|
|
@ -36,7 +35,9 @@
|
||||||
sshKey = config.sops.secrets.borgSshKey.path;
|
sshKey = config.sops.secrets.borgSshKey.path;
|
||||||
};
|
};
|
||||||
|
|
||||||
services.custom-monit.additionalConfig = ''
|
services.monit = {
|
||||||
|
enable = true;
|
||||||
|
additionalConfig = ''
|
||||||
check file nextcloud-data-mounted with path /var/lib/nextcloud/data/index.html
|
check file nextcloud-data-mounted with path /var/lib/nextcloud/data/index.html
|
||||||
start = "${pkgs.systemd}/bin/systemctl start nextcloud-data-sshfs.service"
|
start = "${pkgs.systemd}/bin/systemctl start nextcloud-data-sshfs.service"
|
||||||
|
|
||||||
|
|
@ -53,6 +54,16 @@
|
||||||
with timeout 20 seconds
|
with timeout 20 seconds
|
||||||
then alert
|
then alert
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
services.dokuwiki.enable = true;
|
||||||
|
|
||||||
|
services.openssh.enable = true;
|
||||||
|
|
||||||
|
services.murmur.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
networking.interfaces.enp1s0 = {
|
networking.interfaces.enp1s0 = {
|
||||||
useDHCP = true;
|
useDHCP = true;
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,8 @@
|
||||||
imports = [
|
imports = [
|
||||||
../environment.nix
|
../environment.nix
|
||||||
../hardware/hcloud.nix
|
../hardware/hcloud.nix
|
||||||
../modules/openssh.nix
|
../modules
|
||||||
../modules/postgresql.nix
|
../modules/postgresql.nix
|
||||||
../modules/custom-backup-job.nix
|
|
||||||
../modules/custom-monit.nix
|
|
||||||
../modules/monitoring-exporters.nix
|
../modules/monitoring-exporters.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -19,7 +17,9 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.custom-backup-job = {
|
custom = {
|
||||||
|
services.backup-job = {
|
||||||
|
enable = true;
|
||||||
readWritePaths = [ "/nix/var/data/postgresql" "/nix/var/data/backup/" ];
|
readWritePaths = [ "/nix/var/data/postgresql" "/nix/var/data/backup/" ];
|
||||||
preHook = ''
|
preHook = ''
|
||||||
${pkgs.postgresql_12}/bin/pg_dump -U synapse synapse > /nix/var/data/postgresql/synapse.dmp
|
${pkgs.postgresql_12}/bin/pg_dump -U synapse synapse > /nix/var/data/postgresql/synapse.dmp
|
||||||
|
|
@ -31,4 +31,7 @@
|
||||||
sshKey = config.sops.secrets.borgSshKey.path;
|
sshKey = config.sops.secrets.borgSshKey.path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.openssh.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
imports = [
|
imports = [
|
||||||
../environment.nix
|
../environment.nix
|
||||||
../hardware/hetzner-dedicated-storage1.nix
|
../hardware/hetzner-dedicated-storage1.nix
|
||||||
|
../modules
|
||||||
../modules/openssh.nix
|
../modules/openssh.nix
|
||||||
../modules/mailserver.nix
|
../modules/mailserver.nix
|
||||||
../modules/nginx.nix
|
../modules/nginx.nix
|
||||||
|
|
@ -10,10 +11,7 @@
|
||||||
../modules/stb.nix
|
../modules/stb.nix
|
||||||
../modules/monero.nix
|
../modules/monero.nix
|
||||||
../modules/torrents.nix
|
../modules/torrents.nix
|
||||||
../modules/custom-backup-job.nix
|
|
||||||
../modules/custom-monit.nix
|
|
||||||
../modules/jitsi.nix
|
../modules/jitsi.nix
|
||||||
../modules/gitlab-runner.nix
|
|
||||||
../modules/binary-cache.nix
|
../modules/binary-cache.nix
|
||||||
../modules/grafana.nix
|
../modules/grafana.nix
|
||||||
../modules/monitoring-exporters.nix
|
../modules/monitoring-exporters.nix
|
||||||
|
|
@ -24,6 +22,47 @@
|
||||||
owner = config.services.borgbackup.jobs.data.user;
|
owner = config.services.borgbackup.jobs.data.user;
|
||||||
key = "borg/client_keys/storage1/private";
|
key = "borg/client_keys/storage1/private";
|
||||||
};
|
};
|
||||||
|
nixCacheKey = {
|
||||||
|
key = "nix/cache_secret_key";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
custom = {
|
||||||
|
services.binary-cache = {
|
||||||
|
enable = true;
|
||||||
|
secretKeyFile = config.sops.secrets.nixCacheKey.path;
|
||||||
|
};
|
||||||
|
|
||||||
|
services.backup-job = {
|
||||||
|
enable = true;
|
||||||
|
readWritePaths = [ "/nix/var/data/backup" ];
|
||||||
|
preHook = "${pkgs.docker}/bin/docker exec stb-mariadb sh -c 'mysqldump -u stb -pstb stb' > /nix/var/data/backup/stb_mariadb.sql";
|
||||||
|
postHook = "touch /nix/var/data/backup/backup-ok";
|
||||||
|
startAt = "04:00";
|
||||||
|
sshKey = config.sops.secrets.borgSshKey.path;
|
||||||
|
};
|
||||||
|
|
||||||
|
services.monit = {
|
||||||
|
enable = true;
|
||||||
|
additionalConfig = ''
|
||||||
|
check host nextcloud with address cloud.banditlair.com
|
||||||
|
if failed port 443 protocol https with timeout 20 seconds then alert
|
||||||
|
check host anderia-wiki with address anderia.banditlair.com
|
||||||
|
if failed port 443 protocol https with timeout 20 seconds then alert
|
||||||
|
check host arkadia-wiki with address arkadia.banditlair.com
|
||||||
|
if failed port 443 protocol https with timeout 20 seconds then alert
|
||||||
|
check host website-marie with address osteopathie.froidmont.org
|
||||||
|
if failed port 443 protocol https with timeout 20 seconds then alert
|
||||||
|
check host webmail with address webmail.banditlair.com
|
||||||
|
if failed port 443 protocol https with timeout 20 seconds then alert
|
||||||
|
|
||||||
|
check program raid-md127 with path "${pkgs.mdadm}/bin/mdadm --misc --detail --test /dev/md127"
|
||||||
|
if status != 0 then alert
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
services.gitlab-runner.enable = true;
|
||||||
|
services.openssh.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = [ 80 443 18080 ];
|
networking.firewall.allowedTCPPorts = [ 80 443 18080 ];
|
||||||
|
|
@ -49,30 +88,6 @@
|
||||||
};
|
};
|
||||||
users.groups.steam = { };
|
users.groups.steam = { };
|
||||||
|
|
||||||
services.custom-backup-job = {
|
|
||||||
readWritePaths = [ "/nix/var/data/backup" ];
|
|
||||||
preHook = "${pkgs.docker}/bin/docker exec stb-mariadb sh -c 'mysqldump -u stb -pstb stb' > /nix/var/data/backup/stb_mariadb.sql";
|
|
||||||
postHook = "touch /nix/var/data/backup/backup-ok";
|
|
||||||
startAt = "04:00";
|
|
||||||
sshKey = config.sops.secrets.borgSshKey.path;
|
|
||||||
};
|
|
||||||
|
|
||||||
services.custom-monit.additionalConfig = ''
|
|
||||||
check host nextcloud with address cloud.banditlair.com
|
|
||||||
if failed port 443 protocol https with timeout 20 seconds then alert
|
|
||||||
check host anderia-wiki with address anderia.banditlair.com
|
|
||||||
if failed port 443 protocol https with timeout 20 seconds then alert
|
|
||||||
check host arkadia-wiki with address arkadia.banditlair.com
|
|
||||||
if failed port 443 protocol https with timeout 20 seconds then alert
|
|
||||||
check host website-marie with address osteopathie.froidmont.org
|
|
||||||
if failed port 443 protocol https with timeout 20 seconds then alert
|
|
||||||
check host webmail with address webmail.banditlair.com
|
|
||||||
if failed port 443 protocol https with timeout 20 seconds then alert
|
|
||||||
|
|
||||||
check program raid-md127 with path "${pkgs.mdadm}/bin/mdadm --misc --detail --test /dev/md127"
|
|
||||||
if status != 0 then alert
|
|
||||||
'';
|
|
||||||
|
|
||||||
services.minecraft-server = {
|
services.minecraft-server = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs-unstable.minecraft-server;
|
package = pkgs-unstable.minecraft-server;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue