nixos/applications/gitlab.nix

182 lines
4.6 KiB
Nix
Raw Normal View History

{ config, pkgs, lib, ... }:
with lib;
2023-05-16 15:40:49 +00:00
let
cfg = config.services.skynet_gitlab;
2023-05-16 15:40:49 +00:00
in {
imports = [
./acme.nix
./dns.nix
./firewall.nix
2023-05-16 15:40:49 +00:00
./nginx.nix
];
options.services.skynet_gitlab = {
enable = mkEnableOption "Skynet Gitlab";
host = {
ip = mkOption {
type = types.str;
};
name = mkOption {
type = types.str;
};
};
domain = {
tld = mkOption {
type = types.str;
default = "ie";
};
base = mkOption {
type = types.str;
default = "skynet";
};
sub = mkOption {
type = types.str;
default = "gitlab";
};
};
user = mkOption {
type = types.str;
default = "git";
};
2023-05-24 19:57:49 +00:00
ldap = {
base = mkOption {
type = types.str;
default = "dc=skynet,dc=ie";
description = lib.mdDoc "The base address in the ldap server";
};
};
2023-05-16 15:40:49 +00:00
};
config = mkIf cfg.enable {
2023-05-26 21:21:47 +00:00
# delete all data
# rm -rf /run/gitlab && rm -rf /var/gitlab && rm -rf /var/lib/postgresql && rm -rf /run/gitlab && rm -rf /var/lib/redis-gitlab
# find all data
# grep -r --exclude-dir={docker,containers,log,sys,nix,proc} gitlab /
age.secrets.gitlab_pw = {
file = ../secrets/gitlab/pw.age;
owner = cfg.user;
group = cfg.user;
};
2023-05-24 19:57:49 +00:00
age.secrets.gitlab_secrets_db = {
file = ../secrets/gitlab/secrets_db.age;
owner = cfg.user;
group = cfg.user;
};
age.secrets.gitlab_secrets_secret = {
file = ../secrets/gitlab/secrets_secret.age;
owner = cfg.user;
group = cfg.user;
};
age.secrets.gitlab_secrets_otp = {
file = ../secrets/gitlab/secrets_otp.age;
owner = cfg.user;
group = cfg.user;
};
age.secrets.gitlab_secrets_jws = {
file = ../secrets/gitlab/secrets_jws.age;
owner = cfg.user;
group = cfg.user;
};
age.secrets.gitlab_db_pw = {
file = ../secrets/gitlab/db_pw.age;
owner = cfg.user;
group = cfg.user;
};
# using https://nixos.org/manual/nixos/stable/index.html#module-services-gitlab as a guide
skynet_dns.records.cname = [
"${cfg.domain.sub} CNAME ${cfg.host.name}"
];
2023-05-16 15:40:49 +00:00
networking.firewall.allowedTCPPorts = [
80
443
# for git
22
];
services.nginx. virtualHosts."${cfg.domain.sub}.${cfg.domain.base}.${cfg.domain.tld}" = {
2023-05-16 15:40:49 +00:00
forceSSL = true;
useACMEHost = "skynet";
locations."/".proxyPass = "http://unix:/run/gitlab/gitlab-workhorse.socket";
};
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
# "gitlab-ee"
];
services.gitlab = {
enable = true;
#packages.gitlab = pkgs.gitlab-ee;
databasePasswordFile = config.age.secrets.gitlab_db_pw.path;
initialRootPasswordFile = config.age.secrets.gitlab_pw.path;
https = true;
host = "${cfg.domain.sub}.${cfg.domain.base}.${cfg.domain.tld}";
port = 443;
user = cfg.user;
group = cfg.user;
2023-05-24 19:57:49 +00:00
databaseUsername = cfg.user;
#smtp = {
# enable = true;
# address = "localhost";
# port = 25;
#};
secrets = {
2023-05-24 19:57:49 +00:00
dbFile = config.age.secrets.gitlab_secrets_db.path;
# these must be backed up for future
2023-05-24 19:57:49 +00:00
secretFile = config.age.secrets.gitlab_secrets_secret.path;
otpFile = config.age.secrets.gitlab_secrets_otp.path;
jwsFile = config.age.secrets.gitlab_secrets_jws.path;
};
extraConfig = {
gitlab = {
#email_from = "gitlab-no-reply@example.com";
#email_display_name = "Example GitLab";
#email_reply_to = "gitlab-no-reply@example.com";
default_projects_features = { builds = false; };
};
2023-05-24 19:57:49 +00:00
ldap = {
enabled = true;
servers = {
main = {
label = "Skynet";
host = "sso.skynet.ie";
port = 636;
uid = "uid";
encryption = "simple_tls";
active_directory = false;
#base = "ou=users,${cfg.ldap.base}?sub?(|(skMemberOf=cn=skynet-users,ou=groups,${cfg.ldap.base}))";
base = "ou=users,${cfg.ldap.base}";
user_filter = "(memberOf=cn=skynet-users,ou=groups,${cfg.ldap.base}))";
2023-05-24 19:57:49 +00:00
2023-05-24 20:08:42 +00:00
attributes = {
username = "uid";
email = "skMail";
name = "cn";
};
2023-05-24 19:57:49 +00:00
group_base= "ou=groups,${cfg.ldap.base}";
admin_group = "skynet-admins";
sync_ssh_keys = "sshPublicKey";
};
};
};
2023-05-16 15:40:49 +00:00
};
};
};
}