+/config

my dotfiles and nix configuration

git clone https://git.julia.blue/+/config

Julia RyanUpdate minecraft server8dbea4b

main
7.5 KiB243 linesraw
1{ pkgs, config, lib, ... }: let
2  email = "juliaryan3.14@gmail.com";
3in {
4  networking.firewall = {
5    allowedTCPPorts = [
6      22 28     # ssh
7      80 443    # http(s)
8      2283      # immich
9      22000     # syncthing
10      8080 8443 # testing
11      8123 21063 # home-assistant
12      5580 # matter server
13    ] ++ lib.lists.range 9000 9020 # testing
14      ++ lib.lists.range 1714 1764; # kde connect
15    allowedUDPPorts = [
16      5353        # mdns
17      22000 21027 # syncthing + discovery
18    ]; 
19  };
20
21  age.secrets = {
22    porkbun-api.file = ../../secrets/porkbun-api.age;
23    porkbun-secret.file = ../../secrets/porkbun-secret.age;
24    password = {
25      file = ../../secrets/cortana-service-password.age;
26      group = "grafana"; mode = "660";
27    };
28    caddy-env.file = ../../secrets/caddy.age;
29  };
30
31  environment.systemPackages = with pkgs; [
32    caddy
33    prometheus.cli
34  ];
35
36  services = let home-config = config.home-manager.users.julia; in {
37    caddy = { enable = true;
38      configFile = home-config.lib.file.mkOutOfStoreSymlink
39        (home-config.home.sessionVariables.CONF_DIR + "/machines/cortana/Caddyfile");
40      environmentFile = config.age.secrets.caddy-env.path;
41      # TODO: ipban or ratelimit?
42      package = pkgs.caddy.withPlugins { plugins = [
43        "github.com/mholt/caddy-l4@v0.1.2"
44      ]; hash = "sha256-orq1LkXp8KeBLsp1eoRQ+dHGeM9t+R47Be58s0/irWI="; };
45    };
46
47    openssh = { enable = true;
48      ports = [ 28 ];
49      settings.PasswordAuthentication = false;
50      # TODO: watch /run/utmp and export to prometheus, or just read ssh log?
51    };
52
53    endlessh-go = { enable = true;
54      port = 22;
55      prometheus = { enable = true; port = 9100; };
56      extraOptions = [ "-alsologtostderr" "-geoip_supplier" "ip-api" ];
57      # TODO: use maxmind csv for offline geoip (just download it manually)
58    };
59
60    grafana = { enable = true;
61      settings = {
62        server = {
63          http_addr = "127.0.0.1";
64          http_port = 9001;
65          domain = "stats.pineapple.computer";
66        };
67        security = {
68          admin_email = "julia";
69          admin_password = "$__file{${config.age.secrets.password.path}}";
70          secret_key = "SW2YcwTIb9zpOOhoPsMm";
71        };
72      };
73    };
74
75    prometheus = { enable = true;
76      exporters.node = {
77        enable = true;
78        enabledCollectors = [ "systemd" ];
79        port = 9101;
80      };
81      scrapeConfigs = [{
82        job_name = "prometheus";
83        static_configs = [{ targets = [
84          "localhost:2019" # caddy
85          "localhost:9100" # endlessh
86          "localhost:9101" # node
87          "localhost:9003" # syncthing
88          "localhost:9006" # harmonia
89          # TODO: atuin
90          # TODO: btrfs if it's not in node
91          # TODO: home assistant
92        ]; }];
93      }];
94    };
95
96    atuin = { enable = true;
97      port = 9002;
98      openRegistration = true; # TODO: how to add my user statically?
99    };
100
101    syncthing = { enable = true;
102      guiAddress = "127.0.0.1:9003";
103      dataDir = "/syncthing";
104      overrideDevices = true; overrideFolders = true;
105      settings.options.localAnnounceEnabled = true;
106      settings = {
107        devices = {
108             HAL.id = "ON6QDIA-Q76YZPP-2QDT5KI-DOJVPXS-6757LVB-P2FKJAS-LOMDKIW-JT36XQ6";
109            WOPR.id = "R6XKQSK-3XE7J2H-LSELK56-HVO6PTF-5PX2HZP-775JTZO-ETP2BR3-5QZ6YAF";
110          dragon.id = "6TN3KGX-JU2KQEA-B6VKVCK-AJFAWQG-W2CLE5Q-2WYDPEN-YV3YKXU-HJV6UQL";
111        };
112        folders = (builtins.mapAttrs (n: d: { path = "/syncthing/${n}"; devices = d; }) {
113                notes = [ "HAL" "WOPR" "dragon" ];
114                music = [ "HAL" "WOPR" "dragon" ];
115              recipes = [ "HAL" "WOPR" "dragon" ];
116             torrents = [ "HAL" "WOPR" ];
117          screenshots = [ "HAL" "WOPR" ];
118        });
119        gui.insecureSkipHostcheck = true; # expose web dashboard
120      };
121    };
122
123    pgadmin = { # enable = true;
124      port = 9004;
125      initialEmail = email;
126      initialPasswordFile = config.age.secrets.password.path;
127      # TODO: disable admin password once http auth works
128    };
129
130    chhoto-url = { # enable = true;
131      settings = {
132        site_url = "https://l.julia.blue";
133        port = 9005;
134        try_longer_slugs = true;
135        public_mode = true;
136      };
137    };
138
139    # TODO: hook up grafana dashboard from the repo
140    harmonia.cache = { enable = true; settings.bind = "[::]:9006"; };
141
142    immich = { enable = true;
143      # TODO: figure out how i'm gonna setup uploads, do initial immich-go takeout batch,
144      # and configure public-proxy
145      port = 9007;
146      mediaLocation = "/photos";
147      accelerationDevices = [ "/dev/dri/renderD128" ];
148    };
149
150    home-assistant = { enable = true;
151      extraPackages = python3packages: with python3packages; [ gtts zlib-ng isal ];
152      config.default_config = {};
153    };
154    matterjs-server.enable = true;
155    matterjs-server.listenAddress = "::";
156
157    sorcery = { enable = true;
158      name = "git.julia.blue";
159      url_base = "https://git.julia.blue";
160      repositories = "/git";
161      keys = let c = config.users.users; in
162        c.julia.openssh.authorizedKeys.keys ++ c.rahul.openssh.authorizedKeys.keys;
163      };
164
165    # TODO: vaultwarden
166
167    qbittorrent = { enable = true; webuiPort = 9008; };
168
169    ntfy-sh = { enable = true;
170      settings = { listen-http = ":9009"; base-url = "https://notif.julia.blue"; };
171    };
172
173    porkbun-ddns = { enable = true;
174      secret-key = config.age.secrets.porkbun-secret.path;
175      api-key = config.age.secrets.porkbun-api.path;
176      ipv6 = true;
177      domains = [ "pineapple.computer" "julia.blue" ];
178    };
179  };
180
181  systemd.services = {
182    chhoto-url.environment = {
183      slug_style = lib.mkForce "UNICODE";
184      slug_length = lib.mkForce "2";
185      CHHOTO_SQLITE_USE_WAL_MODE="True";
186    };
187
188    rahul-gists = {
189      description = "Grab rahuls gists (until he makes a blog)";
190      startAt = "0 0 */2 * *"; # every 2 days
191      path = with pkgs; [ bash gh jq sd ];
192      script = ''
193        ~/.local/bin/gist-rss \
194          rrbutani rahul https://rahul.red > /website/feeds/rahul;
195      '';
196      serviceConfig = { User = "julia"; Group = "users"; };
197    };
198
199    rsspls = {
200      description = "Extract rss feeds from web pages";
201      startAt = "00,12:00"; # twice a day
202      serviceConfig = {
203        ExecStart = "${lib.getExe pkgs.rsspls} -o /website/feeds";
204        User = "julia"; Group = "users";
205      };
206    };
207
208    rssfetch = let
209      blogs = builtins.toFile "blogs.json" (builtins.toJSON (import ./blogs.nix));
210    in {
211      description = "Update https://julia.blue/read";
212      startAt = "01,13:00"; # twice a day
213      path = with pkgs; [ rssfetch jq zstd gzip ];
214      script = let
215        out = "/website/posts.json";
216        blogs_out = "/website/blogs.json";
217      in ''
218        cp ${blogs} ${blogs_out}
219        rssfetch <(jq '.[]' ${blogs} -c) |
220          jq -sc '. |= sort_by(.date) | reverse' > ${out}
221        zstd ${blogs} -f -10 -o ${blogs_out}.zst
222        zstd ${out}   -f -10
223        gzip -c ${blogs} > ${blogs_out}.gz
224        gzip -c   ${out} >   ${out}.gz
225      '';
226    };
227  };
228
229  # caddy needs to read files in /home, /syncthing, and /git
230  systemd.services = {
231    caddy.serviceConfig.ProtectHome = lib.mkForce false;
232    immich-server.serviceConfig.UMask = lib.mkForce "0027";
233  };
234  users.users = {
235    caddy.extraGroups = [ "users" "syncthing" "git" ];
236    syncthing.homeMode = "750";
237    qbittorrent.extraGroups = [ "users" "syncthing" ];
238    julia = {
239      homeMode = "750";
240      extraGroups = [ "syncthing" "caddy" "immich" "git" "postgres" "minecraft" ];
241    };
242  };
243}