2020-02-23 19:55:28 +01:00
|
|
|
let
|
2020-08-17 11:08:32 +02:00
|
|
|
briefcase = import <briefcase> {};
|
2020-08-16 16:42:16 +02:00
|
|
|
pkgs = briefcase.third_party.pkgs;
|
2020-02-23 19:55:28 +01:00
|
|
|
trimNewline = x: pkgs.lib.removeSuffix "\n" x;
|
|
|
|
readSecret = x: trimNewline (builtins.readFile ("/etc/secrets/" + x));
|
2020-03-07 16:07:32 +01:00
|
|
|
in {
|
2020-02-22 19:44:44 +01:00
|
|
|
imports = [ ./hardware.nix ];
|
2020-02-20 20:49:15 +01:00
|
|
|
|
2020-02-22 19:44:44 +01:00
|
|
|
# Use the systemd-boot EFI boot loader.
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
2020-02-20 20:49:15 +01:00
|
|
|
|
2020-02-22 19:44:44 +01:00
|
|
|
networking = {
|
|
|
|
hostName = "socrates";
|
|
|
|
# The global useDHCP flag is deprecated, therefore explicitly set to false
|
|
|
|
# here. Per-interface useDHCP will be mandatory in the future, so this
|
|
|
|
# generated config replicates the default behaviour.
|
|
|
|
useDHCP = false;
|
|
|
|
networkmanager.enable = true;
|
|
|
|
interfaces.enp2s0f1.useDHCP = true;
|
|
|
|
interfaces.wlp3s0.useDHCP = true;
|
2020-06-30 20:51:44 +02:00
|
|
|
firewall.allowedTCPPorts = [ 9418 80 443 6697 ];
|
2020-02-22 19:44:44 +01:00
|
|
|
};
|
2020-02-20 20:49:15 +01:00
|
|
|
|
|
|
|
time.timeZone = "UTC";
|
|
|
|
|
2020-02-22 19:44:44 +01:00
|
|
|
programs.fish.enable = true;
|
|
|
|
programs.mosh.enable = true;
|
|
|
|
|
2020-02-20 20:49:15 +01:00
|
|
|
environment.systemPackages = with pkgs; [
|
2020-02-22 19:44:44 +01:00
|
|
|
curl
|
|
|
|
direnv
|
|
|
|
emacs26-nox
|
|
|
|
gnupg
|
|
|
|
htop
|
|
|
|
pass
|
|
|
|
vim
|
|
|
|
certbot
|
|
|
|
tree
|
|
|
|
git
|
2020-02-20 20:49:15 +01:00
|
|
|
];
|
|
|
|
|
2020-02-22 19:44:44 +01:00
|
|
|
users = {
|
|
|
|
# I need a git group to run the git server.
|
|
|
|
groups.git = {};
|
|
|
|
|
|
|
|
users.wpcarro = {
|
|
|
|
isNormalUser = true;
|
|
|
|
extraGroups = [ "git" "wheel" ];
|
|
|
|
shell = pkgs.fish;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.git = {
|
|
|
|
group = "git";
|
|
|
|
isNormalUser = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
nix = {
|
2020-08-17 10:48:47 +02:00
|
|
|
nixPath = [];
|
2020-02-22 19:44:44 +01:00
|
|
|
trustedUsers = [ "root" "wpcarro" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
# Services
|
|
|
|
##############################################################################
|
2020-03-11 00:06:03 +01:00
|
|
|
|
2020-06-30 20:51:44 +02:00
|
|
|
systemd.services.bitlbee-stunnel = {
|
|
|
|
description = "Provides TLS termination for Bitlbee.";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
unitConfig = {
|
|
|
|
Restart = "always";
|
|
|
|
User = "nginx"; # This is a hack to easily get certificate access.
|
|
|
|
};
|
|
|
|
script = let configFile = builtins.toFile "stunnel.conf" ''
|
|
|
|
foreground = yes
|
|
|
|
debug = 7
|
|
|
|
|
|
|
|
[ircs]
|
|
|
|
accept = 0.0.0.0:6697
|
|
|
|
connect = 6667
|
|
|
|
cert = /var/lib/acme/wpcarro.dev/full.pem
|
|
|
|
''; in "${pkgs.stunnel}/bin/stunnel ${configFile}";
|
|
|
|
};
|
|
|
|
|
2020-06-30 18:55:11 +02:00
|
|
|
nixpkgs.config.bitlbee.enableLibPurple = true;
|
|
|
|
services.bitlbee = {
|
2020-06-30 19:35:15 +02:00
|
|
|
interface = "0.0.0.0";
|
2020-06-30 18:55:11 +02:00
|
|
|
enable = true;
|
|
|
|
libpurple_plugins = [
|
|
|
|
pkgs.telegram-purple
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2020-08-14 10:16:36 +02:00
|
|
|
services.journaldriver = {
|
|
|
|
enable = true;
|
|
|
|
logStream = "home";
|
|
|
|
googleCloudProject = "wpcarros-infrastructure";
|
|
|
|
applicationCredentials = "/etc/gcp/key.json";
|
|
|
|
};
|
|
|
|
|
2020-02-20 20:49:15 +01:00
|
|
|
services.openssh.enable = true;
|
|
|
|
|
2020-04-05 17:36:10 +02:00
|
|
|
services.gitea = {
|
|
|
|
enable = true;
|
|
|
|
# Without this the links to clone a repository like briefcase will be
|
|
|
|
# "http://localhost:3000/wpcarro/briefcase".
|
|
|
|
rootUrl = "https://git.wpcarro.dev/";
|
|
|
|
};
|
2020-03-11 00:06:03 +01:00
|
|
|
|
2020-08-17 18:33:56 +02:00
|
|
|
services.buildkite-agents = {
|
|
|
|
socrates = {
|
|
|
|
enable = true;
|
|
|
|
tokenPath = "/etc/secrets/buildkite-agent-token";
|
2020-08-17 21:05:22 +02:00
|
|
|
privateSshKeyPath = "/etc/ssh/buildkite_agent_id_rsa";
|
2020-08-17 18:33:56 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-08-13 23:26:29 +02:00
|
|
|
# systemd.services.monzo-token-server = {
|
|
|
|
# enable = true;
|
|
|
|
# description = "Ensure my Monzo access token is valid";
|
2020-08-17 11:44:55 +02:00
|
|
|
# script = "${briefcase.tools.monzo_ynab.tokens}/bin/token-server";
|
2020-08-13 23:26:29 +02:00
|
|
|
# # TODO(wpcarro): I'm unsure of the size of this security risk, but if a
|
|
|
|
# # non-root user runs `systemctl cat monzo-token-server`, they could read the
|
|
|
|
# # following, sensitive environment variables.
|
|
|
|
# environment = {
|
|
|
|
# store_path = "/var/cache/monzo_ynab";
|
|
|
|
# monzo_client_id = readSecret "monzo-client-id";
|
|
|
|
# monzo_client_secret = readSecret "monzo-client-secret";
|
|
|
|
# ynab_personal_access_token = readSecret "ynab-personal-access-token";
|
|
|
|
# ynab_account_id = readSecret "ynab-account-id";
|
|
|
|
# ynab_budget_id = readSecret "ynab-budget-id";
|
|
|
|
# };
|
|
|
|
# serviceConfig = {
|
|
|
|
# Type = "simple";
|
|
|
|
# };
|
|
|
|
# };
|
2020-02-22 19:44:44 +01:00
|
|
|
|
2020-08-14 13:50:32 +02:00
|
|
|
systemd.services.zoo = {
|
|
|
|
enable = true;
|
|
|
|
description = "Run my monoserver";
|
|
|
|
script = "${briefcase.zoo}/zoo";
|
|
|
|
environment = {};
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "always";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-02-22 19:44:44 +01:00
|
|
|
services.gitDaemon = {
|
|
|
|
enable = true;
|
|
|
|
basePath = "/srv/git";
|
|
|
|
exportAll = true;
|
|
|
|
repositories = [ "/srv/git/briefcase" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
# Since I'm using this laptop as a server in my flat, I'd prefer to close its
|
|
|
|
# lid.
|
|
|
|
services.logind.lidSwitch = "ignore";
|
|
|
|
|
2020-08-16 20:06:42 +02:00
|
|
|
security.polkit.extraConfig = ''
|
|
|
|
polkit.addRule(function(action, subject) {
|
|
|
|
polkit.log("subject.user: " + subject.user + " is attempting action.id: " + action.id);
|
|
|
|
});
|
|
|
|
'';
|
|
|
|
|
2020-02-22 19:44:44 +01:00
|
|
|
# Provision SSL certificates to support HTTPS connections.
|
|
|
|
security.acme.acceptTerms = true;
|
2020-03-07 16:08:11 +01:00
|
|
|
security.acme.email = "wpcarro@gmail.com";
|
2020-02-22 19:44:44 +01:00
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
enableReload = true;
|
|
|
|
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
|
|
|
|
commonHttpConfig = ''
|
|
|
|
log_format json_combined escape=json
|
|
|
|
'{'
|
|
|
|
'"remote_addr":"$remote_addr",'
|
2020-08-14 12:17:47 +02:00
|
|
|
'"method":"$request_method",'
|
2020-08-14 12:40:44 +02:00
|
|
|
'"host":"$host",'
|
2020-08-14 12:17:47 +02:00
|
|
|
'"uri":"$request_uri",'
|
|
|
|
'"status":$status,'
|
|
|
|
'"request_size":$request_length,'
|
|
|
|
'"response_size":$body_bytes_sent,'
|
|
|
|
'"response_time":$request_time,'
|
|
|
|
'"referrer":"$http_referer",'
|
|
|
|
'"user_agent":"$http_user_agent"'
|
2020-02-22 19:44:44 +01:00
|
|
|
'}';
|
2020-08-14 12:17:47 +02:00
|
|
|
|
|
|
|
access_log syslog:server=unix:/dev/log,nohostname json_combined;
|
2020-02-22 19:44:44 +01:00
|
|
|
'';
|
|
|
|
|
2020-03-07 16:08:11 +01:00
|
|
|
virtualHosts = {
|
2020-03-20 01:22:13 +01:00
|
|
|
"wpcarro.dev" = {
|
|
|
|
addSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
root = briefcase.website;
|
|
|
|
};
|
2020-03-07 16:08:11 +01:00
|
|
|
"learn.wpcarro.dev" = {
|
|
|
|
addSSL = true;
|
|
|
|
enableACME = true;
|
2020-03-20 01:47:21 +01:00
|
|
|
root = briefcase.website.learn;
|
2020-03-07 16:08:11 +01:00
|
|
|
};
|
2020-04-05 15:55:44 +02:00
|
|
|
"git.wpcarro.dev" = {
|
|
|
|
addSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://localhost:3000";
|
|
|
|
};
|
|
|
|
};
|
2020-03-07 16:08:11 +01:00
|
|
|
"blog.wpcarro.dev" = {
|
|
|
|
addSSL = true;
|
|
|
|
enableACME = true;
|
2020-03-20 01:46:29 +01:00
|
|
|
root = briefcase.website.blog;
|
2020-03-07 16:08:11 +01:00
|
|
|
};
|
2020-08-17 10:48:47 +02:00
|
|
|
# "sandbox.wpcarro.dev" = {
|
|
|
|
# addSSL = true;
|
|
|
|
# enableACME = true;
|
|
|
|
# root = briefcase.website.sandbox;
|
|
|
|
# };
|
|
|
|
# "learnpianochords.app" = {
|
|
|
|
# addSSL = true;
|
|
|
|
# enableACME = true;
|
|
|
|
# root = briefcase.website.sandbox.learnpianochords;
|
|
|
|
# };
|
2020-08-13 23:23:14 +02:00
|
|
|
"zoo.wpcarro.dev" = {
|
|
|
|
addSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://localhost:8000";
|
|
|
|
};
|
|
|
|
};
|
2020-02-22 19:44:44 +01:00
|
|
|
};
|
2020-02-20 20:49:15 +01:00
|
|
|
};
|
|
|
|
|
2020-03-19 12:53:57 +01:00
|
|
|
system.stateVersion = "20.09";
|
2020-03-07 16:07:32 +01:00
|
|
|
}
|