Fresh repo without sensitive data.

This commit is contained in:
Kevin Baensch 2019-02-26 13:44:40 +01:00
commit 9003080a64
44 changed files with 2039 additions and 0 deletions

9
services/cups.nix Normal file
View file

@ -0,0 +1,9 @@
{ config, lib, pkgs, ... }:
{
services.printing = {
enable = true;
startWhenNeeded = true;
drivers = with pkgs; [ gutenprint hplip splix samsung-unified-linux-driver ];
};
}

7
services/default.nix Normal file
View file

@ -0,0 +1,7 @@
{ config, lib, pkgs, ... }:
let
cfg = import ("/etc/nixos/machines/" + (builtins.replaceStrings ["\n"] [""] (builtins.readFile /etc/hostname)) + "/configuration.nix");
in {
imports = cfg.services;
}

8
services/ejabberd.nix Normal file
View file

@ -0,0 +1,8 @@
{ config, pkgs, ... }:
{
services.ejabberd = {
enable = true;
imagemagick = true;
};
}

69
services/fail2ban.nix Normal file
View file

@ -0,0 +1,69 @@
{ config, lib, pkgs, ... }:
# mostly taken from https://github.com/davidak/nixos-config/blob/master/services/fail2ban.nix
{
services.fail2ban = {
enable = true;
jails = {
DEFAULT = ''
bantime = 3600
logpath = /var/log/auth.log
'';
ssh = ''
enabled = true
filter = sshd
maxretry = 4
action = iptables[name=SSH, port=ssh, protocol=tcp]
'';
sshd-ddos = ''
enabled = true
filter = sshd-ddos
maxretry = 2
action = iptables[name=ssh, port=ssh, protocol=tcp]
'';
postfix = ''
enabled = true
filter = postfix
maxretry = 3
action = iptables[name=postfix, port=smtp, protocol=tcp]
'';
postfix-sasl = ''
enabled = true
filter = postfix-sasl
maxretry = 3
action = iptables[name=postfix, port=smtp, protocol=tcp]
'';
postfix-ddos = ''
enabled = true
filter = postfix-ddos
maxretry = 3
action = iptables[name=postfix, port=submission, protocol=tcp]
bantime = 7200
'';
nginx-req-limit = ''
enabled = true
filter = nginx-req-limit
maxretry = 10
action = iptables-multiport[name=ReqLimit, port="http,https", protocol=tcp]
findtime = 600
bantime = 7200
''
};
};
environment.etc."fail2ban/filter.d/postfix-ddos.conf".text = ''
[Definition]
failregex = lost connection after EHLO from \S+\[<HOST>\]
'';
environment.etc."fail2ban/filter.d/nginx-req-limit.conf".text = ''
[Definition]
failregex = limiting requests, excess:.* by zone.*client: <HOST>
'';
# Limit stack size to reduce memory usage
systemd.services.fail2ban.serviceConfig.LimitSTACK = 256 * 1024;
}

36
services/gitea.nix Normal file
View file

@ -0,0 +1,36 @@
{ stdenv, conf, pkgs, ... }:
{
services.gitea = {
enable = true;
user = "git";
cookieSecure = true;
domain = "git.ophanim.de";
rootUrl = "http://git.ophanim.de/";
database = {
type = "mysql";
user = "git";
name = "gitea";
passwordFile = "/secret/gitea";
};
extraConfig = ''
[repository]
DISABLE_HTTP_GIT = true
USE_COMPAT_SSH_URI = true
[security]
INSTALL_LOCK = true
COOKIE_USERNAME = gitea_username
COOKIE_REMEMBER_NAME = gitea_userauth
[service]
DISABLE_REGISTRATION = true
'';
};
users.users.git = {
isNormalUser = true;
home = "/var/lib/gitea";
createHome = true;
};
}

29
services/hydra.nix Normal file
View file

@ -0,0 +1,29 @@
{ config, pkgs, ... }:
# hydra user needs to be manually crated
# sudo -u hydra -s
# hydra-create-user $USERNAME --password $PASSWORD --role admin
{
# also take a look at ../conf/nix.nix
nix.buildMachines = [
{
hostName = "localhost";
system = "x86_64-linux";
supportedFeatures = ["kvm" "nixos-test" "big-parallel" "benchmark"];
maxJobs = 8;
}
];
services.hydra = {
enable = true;
hydraURL = "https://builder.ophanim.de"; # externally visible URL
listenHost = "localhost";
port = 3001;
minimumDiskFree = 15;
minimumDiskFreeEvaluator = 15;
notificationSender = "hydra@mail.ophanim.de"; # e-mail of hydra service
useSubstitutes = true;
debugServer = false;
};
}

38
services/mailserver.nix Normal file
View file

@ -0,0 +1,38 @@
{ lib, config, pkgs, ... }:
{
imports = [
./mailserver/default.nix
];
mailserver = rec {
enable = true;
fqdn = "mail.ophanim.de";
domains = [ "ophanim.de" ];
loginAccounts = {
"derped@ophanim.de" = {
hashedPassword = (builtins.replaceStrings ["\n"] [""] (builtins.readFile /secret/derped.mail));
};
};
# Use Let's Encrypt certificates. Note that this needs to set up a stripped
# down nginx and opens port 80.
certificateScheme = 1;
certificateFile = "/var/lib/acme/" + fqdn + "/fullchain.pem";
keyFile = "/var/lib/acme/" + fqdn + "/key.pem";
#dhParamBitLength = 4096; # this doesn't exist???
# Enable IMAP and POP3
enableImap = true;
enablePop3 = true;
enableImapSsl = true;
enablePop3Ssl = true;
# Enable the ManageSieve protocol
enableManageSieve = true;
# whether to scan inbound emails for viruses (note that this requires at least
# 1 Gb RAM for the server. Without virus scanning 256 MB RAM should be plenty)
virusScanning = false;
};
}

27
services/mariaDB.nix Normal file
View file

@ -0,0 +1,27 @@
{ config, pkgs, ... }:
let
nextcloudpwd = (builtins.replaceStrings ["\n"] [""] (builtins.readFile /secret/nextcloud_db));
giteapwd = (builtins.replaceStrings ["\n"] [""] (builtins.readFile /secret/gitea));
in {
services.mysql = {
enable = true;
package = pkgs.mariadb;
initialDatabases = [ {
name = "nextcloud";
schema = pkgs.writeText "nextcloud.sql"
''
create user if not exists 'nextcloud'@'localhost' identified by ${nextcloudpwd};
grant all privileges on nextcloud.* to 'nextcloud'@'localhost' identified by ${nextcloudpwd};
'';
}
{
name = "gitea";
schema = pkgs.writeText "gitea.sql"
''
create user if not exists 'git'@'localhost' identified by ${giteapwd};
grant all privileges on gitea.* to 'git'@'localhost' identified by ${giteapwd};
'';
} ];
};
}

27
services/nextcloud.nix Normal file
View file

@ -0,0 +1,27 @@
{ conf, pkgs, ... }:
{
services.nextcloud = {
enable = true;
home = "/var/lib/nextcloud";
hostName = "storage.ophanim.de";
https = true;
maxUploadSize = "1024M";
config = {
adminuser = "derped";
adminpassFile = "/secret/nextcloud_admin";
dbtype = "mysql";
dbhost = "localhost";
dbport = "3306";
dbuser = "nextcloud";
dbpassFile = "/secret/nextcloud_db";
dbname = "nextcloud";
dbtableprefix = "oc_";
};
caching = {
apcu = true;
memcached = true;
redis = false;
};
};
}

286
services/nginx.nix Normal file
View file

@ -0,0 +1,286 @@
##############################################################################################
# Includes: #
# - Nginx + SSL config #
# - Gitea #
# - Nextcloud #
# - Heavily based on: https://gist.github.com/schneefux/22b75d2bd3e4e754ba1684f1d1e93271 #
# - Mail ssl root #
##############################################################################################
{ conf, lib, pkgs, ... }:
let
gitpkgs = import /nixpkgs/default.nix {};
in {
services.nginx = {
enable = true;
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
sslCiphers = "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256";
virtualHosts = {
"ophanim.de" = {
enableACME = true;
forceSSL = true;
root = "/var/www";
};
"builder.ophanim.de" = {
enableACME = true;
forceSSL = true;
extraConfig = ''
location / {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $http_host;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
'';
};
"mail.ophanim.de" = {
enableACME = true;
forceSSL = true;
root = "/var/www";
};
"storage.ophanim.de" = {
enableACME = true;
forceSSL = true;
root = "${gitpkgs.nextcloud}";
locations = {
"/robots.txt" = {
extraConfig = ''
allow all;
log_not_found off;
access_log off;
'';
};
"~ ^/(?:\.htaccess|config|db_structure\.xml|README)" = {
extraConfig = "deny all;";
};
"/" = {
extraConfig = ''
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
try_files $uri $uri/ =404;
'';
};
"~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/)" = {
extraConfig = ''
include ${pkgs.nginx}/conf/uwsgi_params;
uwsgi_modifier1 14;
uwsgi_hide_header X-Frame-Options;
uwsgi_hide_header X-XSS-Protection;
uwsgi_hide_header X-Content-Type-Options;
uwsgi_hide_header X-Robots-Tag;
uwsgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
uwsgi_pass unix:/run/uwsgi/php.sock;
'';
};
"~* \.(?:css|js)$" = {
extraConfig = ''
add_header Cache-Control "public, max-age=7200";
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
access_log off;
'';
};
"~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$" = {
extraConfig = ''
access_log off;
'';
};
"^~ /data" = {
extraConfig = ''
internal;
'';
};
"^~ /apps" = {
extraConfig = ''
alias /var/lib/nextcloud/apps;
'';
};
};
### Settings for new nextcloud module.... does not work yet???
# locations = {
# "= /robots.txt" = {
# priority = 100;
# extraConfig = ''
# allow all;
# log_not_found off;
# access_log off;
# '';
# };
# "/" = {
# priority = 200;
# extraConfig = "rewrite ^ /index.php$uri;";
# };
# "~ ^/store-apps" = {
# priority = 201;
# extraConfig = "root /var/lib/nextcloud;";
# };
# "= /.well-known/carddav" = {
# priority = 210;
# extraConfig = "return 301 $scheme://$host/remote.php/dav;";
# };
# "= /.well-known/caldav" = {
# priority = 210;
# extraConfig = "return 301 $scheme://$host/remote.php/dav;";
# };
# "~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/" = {
# priority = 300;
# extraConfig = "deny all;";
# };
# "~ ^/(?:\\.|autotest|occ|issue|indie|db_|console)" = {
# priority = 300;
# extraConfig = "deny all;";
# };
# "~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\\.php(?:$|/)" = {
# priority = 500;
# extraConfig = ''
# include ${pkgs.nginxMainline}/conf/fastcgi.conf;
# fastcgi_split_path_info ^(.+\.php)(/.*)$;
# fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi_param HTTPS on;
# fastcgi_param modHeadersAvailable true;
# fastcgi_param front_controller_active true;
# fastcgi_pass unix:/run/phpfpm/nextcloud;
# fastcgi_intercept_errors on;
# fastcgi_request_buffering off;
# fastcgi_read_timeout 120s;
# '';
# };
# "~ ^/(?:updater|ocs-provider)(?:$|/)".extraConfig = ''
# try_files $uri/ =404;
# index index.php;
# '';
# "~ \\.(?:css|js|woff|svg|gif)$".extraConfig = ''
# try_files $uri /index.php$uri$is_args$args;
# add_header Cache-Control "public, max-age=15778463";
# add_header X-Content-Type-Options nosniff;
# add_header X-XSS-Protection "1; mode=block";
# add_header X-Robots-Tag none;
# add_header X-Download-Options noopen;
# add_header X-Permitted-Cross-Domain-Policies none;
# access_log off;
# '';
# "~ \\.(?:png|html|ttf|ico|jpg|jpeg)$".extraConfig = ''
# try_files $uri /index.php$uri$is_args$args;
# access_log off;
# '';
# };
# extraConfig = ''
# add_header X-Content-Type-Options nosniff;
# add_header X-XSS-Protection "1; mode=block";
# add_header X-Robots-Tag none;
# add_header X-Download-Options noopen;
# add_header X-Permitted-Cross-Domain-Policies none;
# error_page 403 /core/templates/403.php;
# error_page 404 /core/templates/404.php;
# client_max_body_size 1024M;
# fastcgi_buffers 64 4K;
# gzip on;
# gzip_vary on;
# gzip_comp_level 4;
# gzip_min_length 256;
# gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
# gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
# '';
};
"git.ophanim.de" = {
enableACME = true;
forceSSL = true;
root = "/var/lib/gitea/public";
extraConfig = ''
location / {
try_files maintain.html $uri $uri/index.html @node;
}
location @node {
client_max_body_size 0;
proxy_pass http://localhost:3000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_max_temp_file_size 0;
proxy_redirect off;
proxy_read_timeout 120;
}
'';
};
};
};
# Nextcloud system cron
users.users.nginx.useDefaultShell = true;
systemd.services.nextcloudcron = {
description = "Nextcloud cron";
after = [ "network.target" ];
script = ''
${pkgs.php}/bin/php ${gitpkgs.nextcloud}/cron.php
${gitpkgs.nextcloud-news-updater}/bin/nextcloud-news-updater -t 2 -i 30 --mode singlerun ${gitpkgs.nextcloud}
'';
environment = { NEXTCLOUD_CONFIG_DIR = "/var/lib/nextcloud/config"; };
serviceConfig.User = "nginx";
};
systemd.timers.nextcloudcron = {
enable = true;
description = "Nextcloud cron timer";
wantedBy = [ "timers.target" ];
partOf = [ "Nextcloudcron.service" ];
timerConfig = {
RandomizedDelaySec = "5min";
OnCalendar = "*-*-* *:00,30:00"; # every 1/2h
Persistent = true;
};
};
services.uwsgi = {
enable = true;
user = "nginx";
group = "nginx";
instance = {
type = "emperor";
vassals = {
php = {
type = "normal";
socket = "/run/uwsgi/php.sock";
master = true;
vacuum = true;
processes = 16;
cheaper = 1;
php-sapi-name = "apache"; # opcode caching tweak
php-allowed-ext = [ ".php" ".inc" ];
socket-modifier1 = 14;
php-index = "index.php";
php-set = "date.timezone=Europe/Berlin";
env = [
"NEXTCLOUD_CONFIG_DIR=/var/lib/nextcloud/config"
];
plugins = [ "php" ];
};
};
};
plugins = [ "php" ];
};
}

14
services/openssh.nix Normal file
View file

@ -0,0 +1,14 @@
{ config, lib, pkgs, ... }:
{
services.openssh = {
enable = true;
startWhenNeeded = true;
challengeResponseAuthentication = false;
passwordAuthentication = false;
permitRootLogin = "no";
extraConfig = ''
AllowUsers derped git
'';
};
}

30
services/prosody.nix Normal file
View file

@ -0,0 +1,30 @@
{ config, pkgs, ... }:
{
services.prosody = {
enable = true;
admins = [ "derped@ophanim.de" ];
allowRegistration = false;
extraConfig = ''
use_libevent = true
s2s_require_encryption = true
c2s_require_encryption = true
'';
extraModules = [ "private" "vcard" "privacy" "compression" "component" "muc" "pep" "adhoc" "lastactivity" "admin_adhoc" "blocklist"];
# modules.legacyauth = false;
ssl.cert = "/var/lib/acme/ophanim.de/fullchain.pem";
ssl.key = "/var/lib/acme/ophanim.de/key.pem";
virtualHosts = {
localhost = {
domain = "localhost";
enabled = true;
};
"ophanim.de" = {
domain = "ophanim.de";
enabled = true;
};
};
};
}

32
services/udev.nix Normal file
View file

@ -0,0 +1,32 @@
{ config, lib, pkgs, ... }:
{
services.udev.extraRules = ''
Valve USB devices
SUBSYSTEM=="usb", ATTRS{idVendor}=="28de", TAG+="uaccess", TAG+="udev-acl"
# Steam Controller udev write access
KERNEL=="uinput", SUBSYSTEM=="misc", TAG+="uaccess", TAG+="udev-acl"
# Valve HID devices over USB hidraw
KERNEL=="hidraw*", ATTRS{idVendor}=="28de", TAG+="uaccess", TAG+="udev-acl"
# Valve HID devices over bluetooth hidraw
KERNEL=="hidraw*", KERNELS=="*28DE:*", TAG+="uaccess", TAG+="udev-acl"
# DualShock 4 over USB hidraw
KERNEL=="hidraw*", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="05c4", TAG+="uaccess", TAG+="udev-acl"
# DualShock 4 wireless adapter over USB hidraw
KERNEL=="hidraw*", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0ba0", TAG+="uaccess", TAG+="udev-acl"
# DualShock 4 Slim over USB hidraw
KERNEL=="hidraw*", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="09cc", TAG+="uaccess", TAG+="udev-acl"
# DualShock 4 over bluetooth hidraw
KERNEL=="hidraw*", KERNELS=="*054C:05C4*", TAG+="uaccess", TAG+="udev-acl"
# DualShock 4 Slim over bluetooth hidraw
KERNEL=="hidraw*", KERNELS=="*054C:09CC*", TAG+="uaccess", TAG+="udev-acl"
'';
}

32
services/xserver.nix Normal file
View file

@ -0,0 +1,32 @@
{ config, lib, pkgs, ... }:
{
services.gnome3.gvfs.enable = true;
services.xserver = {
enable = true;
layout = "de";
videoDrivers = [ "intel" ];
windowManager = {
i3 = {
enable = true;
configFile = ../config/etc/i3/config;
extraPackages = with pkgs; [
dmenu
file
i3lock
i3status
];
};
default = "i3";
};
# add switch for Lilim
libinput = {
enable = true;
tapping = true;
disableWhileTyping = false;
naturalScrolling = false;
horizontalScrolling =true;
};
dpi = 192;
};
}