diff options
author | Ben Sima <ben@bsima.me> | 2019-02-22 15:22:49 -0800 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2019-02-23 13:25:47 -0800 |
commit | 9b2b49e9063d805e68acbef40989075f1b1a6576 (patch) | |
tree | c2c5464bb2b6b3bf2c9109d6a2218d9a6d62b222 | |
parent | 3b90927e818729f2983ae7ebe5ab65c0b96bcd2a (diff) |
Package and deploy fathom
-rw-r--r-- | configuration.nix | 19 | ||||
-rw-r--r-- | modules/fathom.nix | 93 | ||||
-rw-r--r-- | nixos.nix | 1 | ||||
-rw-r--r-- | pack/default.nix | 6 | ||||
-rw-r--r-- | pack/fathom.nix | 18 |
5 files changed, 134 insertions, 3 deletions
diff --git a/configuration.nix b/configuration.nix index a5cd2c6..83c449b 100644 --- a/configuration.nix +++ b/configuration.nix @@ -3,12 +3,13 @@ let bensIp = "68.107.97.20"; ibbPort = "3000"; + fathomPort = "3030"; in { nixpkgs.config.allowUnfree = true; - nixpkgs.config.packageOverrides = pkgs: { - ibb = import ./ibb/default.nix {}; - }; + nixpkgs.overlays = [ + (import ./pack/default.nix) + ]; networking.firewall.allowedTCPPorts = [ 22 80 443 ]; @@ -19,6 +20,12 @@ in port = ibbPort; }; + fathom = { + enable = true; + port = fathomPort; + dataDir = "/var/lib/fathom"; + }; + nginx = { enable = true; recommendedGzipSettings = true; @@ -30,6 +37,12 @@ in "dev.simatime.com".locations."/".proxyPass = "http://${bensIp}:${ibbPort}"; "hero.simatime.com".locations."/".proxyPass = "http://${bensIp}:3001"; "tv.simatime.com".locations."/".proxyPass = "http://${bensIp}:8096"; # emby runs on port 8096 + + "stats.simatime.com" = { + locations."/".proxyPass = "http://localhost:${fathomPort}"; + forceSSL = true; + enableACME = true; + }; "influencedbybooks.com" = { forceSSL = true; enableACME = true; diff --git a/modules/fathom.nix b/modules/fathom.nix new file mode 100644 index 0000000..dee34b9 --- /dev/null +++ b/modules/fathom.nix @@ -0,0 +1,93 @@ +{ options +, lib +, config +, pkgs +, modulesPath +}: + +with lib; + +let + cfg = config.services.fathom; +in +{ + options.services.fathom = { + enable = lib.mkEnableOption "Enable the Fathom Analytics service"; + + port = mkOption { + type = types.string; + default = "3000"; + description = '' + The port on which Fathom will listen for + incoming HTTP traffic. + ''; + }; + + gzip = mkOption { + type = types.bool; + default = true; + description = "Whether or not to enable gzip compression."; + }; + + debug = mkOption { + type = types.bool; + default = false; + description = "Whether or not to enable debug mode."; + }; + + dataDir = mkOption { + type = types.path; + default = "/var/lib/fathom"; + description = "Fathom data directory"; + }; + }; + + config = mkIf cfg.enable { + systemd.services.fathom = { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + environment = { + FATHOM_SERVER_ADDR = cfg.port; + FATHOM_GZIP = builtins.toString cfg.gzip; + FATHOM_DEBUG = builtins.toString cfg.debug; + FATHOM_DATABASE_DRIVER = "sqlite3"; + FATHOM_DATABASE_NAME = "${cfg.dataDir}/fathom.db"; + FATHOM_SECRET = "random-secret-string"; + }; + preStart = '' + echo "[fathom] creating ${cfg.dataDir}" + mkdir -p ${cfg.dataDir} + chown -R fathom:fathom ${cfg.dataDir} + echo "[fathom]" creating ${cfg.dataDir}/.env + env | grep "^FATHOM" > ${cfg.dataDir}/.env + ''; + description = '' + Fathom Analytics + ''; + + serviceConfig = { + Type = "simple"; + User = "fathom"; + Group = "fathom"; + ExecStart = "${pkgs.fathom}/bin/fathom server"; + KillSignal = "INT"; + WorkingDirectory = cfg.dataDir; + Restart = "on-failure"; + RestartSec = "10"; + PermissionsStartOnly = "true"; + }; + }; + + environment.systemPackages = [ pkgs.fathom ]; + + users = { + groups = { fathom = {}; }; + users.fathom = { + description = "Fathom daemon user"; + home = cfg.dataDir; + group = "fathom"; + }; + }; + }; +} @@ -15,6 +15,7 @@ import "${nixpkgs}/nixos" { # our modules ./modules/ibb.nix + ./modules/fathom.nix # third party (builtins.fetchTarball { diff --git a/pack/default.nix b/pack/default.nix new file mode 100644 index 0000000..6c218bb --- /dev/null +++ b/pack/default.nix @@ -0,0 +1,6 @@ +self: super: + +{ + fathom = import ./fathom.nix { nixpkgs = super; }; + ibb = import ../ibb/default.nix { }; +} diff --git a/pack/fathom.nix b/pack/fathom.nix new file mode 100644 index 0000000..a845eb6 --- /dev/null +++ b/pack/fathom.nix @@ -0,0 +1,18 @@ +{ nixpkgs }: +with nixpkgs; +stdenv.mkDerivation rec { + name = "fathom-v${version}"; + version = "1.2.1"; + src = builtins.fetchurl { + url = "https://github.com/usefathom/fathom/releases/download/v${version}/fathom_${version}_linux_amd64.tar.gz"; + sha256 = "0sfpxh2xrvz992k0ynib57zzpcr0ikga60552i14m13wppw836nh"; + }; + sourceRoot = "."; + dontBuild = true; + installPhase = '' + mkdir -p $out/bin + cp fathom $out/bin + cp LICENSE $out + cp README.md $out + ''; +} |