~jb55/citadel

ref: 0cffe2f1a4a83c13892392e8325dff4ab05be317 citadel/nix-config/machines/monad/default.nix -rw-r--r-- 12.7 KiB
0cffe2f1William Casarin monad: no pci hack for now 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
extra:
{ config, lib, pkgs, ... }:
let util = extra.util;
    nix-serve = extra.machine.nix-serve;
    zenstates = pkgs.fetchFromGitHub {
      owner  = "r4m0n";
      repo   = "ZenStates-Linux";
      rev    = "0bc27f4740e382f2a2896dc1dabfec1d0ac96818";
      sha256 = "1h1h2n50d2cwcyw3zp4lamfvrdjy1gjghffvl3qrp6arfsfa615y";
    };
    email-notify = util.writeBash "email-notify-user" ''
      export HOME=/home/jb55
      export PATH=${lib.makeBinPath (with pkgs; [ eject libnotify muchsync notmuch openssh ])}:$PATH
      (
        flock -x -w 100 200 || exit 1

        muchsync charon

        #DISPLAY=:0 notify-send --category=email "you got mail"

      ) 200>/tmp/email-notify.lock
    '';

in
{
  imports = [
    ./hardware
    # ./contracts/commit
    # ./contracts/plastiq

    #(import ../../misc/dnsmasq-adblock.nix)
    (import ../../misc/msmtp extra)
    (import ./networking extra)
    (import ../../misc/imap-notifier extra)
  ] ++ (if !extra.is-minimal then [ (import ./bitcoin extra) ] else []);

  hardware.steam-hardware.enable = true;

  boot.kernelPackages = pkgs.linuxPackages_latest;

  services.prometheus.enable = false;
  # services.prometheus.dataDir = "/zbig/data/prometheus";
  services.grafana.enable = false;
  services.grafana.port = 3005;
  services.grafana.provision.datasources = [
    { name = "bitcoin";
      type = "prometheus";
      access = "direct";
      isDefault = true;
    }
  ];

  # services.guix.enable = true;
  services.synergy.server.enable = if extra.is-minimal then false else true;
  services.synergy.server.autoStart = true;
  services.synergy.server.screenName = "desktop";
  services.synergy.server.configFile = pkgs.writeText "barrier-cfg" ''
    section: screens
      desktop:
      mac:
      win:
    end
    section: aliases
        desktop:
          192.168.86.26
        mac:
          10.100.0.4
        win:
          192.168.122.218
    end
    section: links
      desktop:
          left = mac
          right = win
      mac:
          right = desktop
      win:
          left = desktop
    end
    section: options
      keystroke(alt+control+h) = switchInDirection(left)
      keystroke(alt+control+l) = switchInDirection(right)
    end
  '';

  services.bitlbee.enable = if extra.is-minimal then false else true;
  services.bitlbee.libpurple_plugins = with pkgs; [
    pidgin-skypeweb
    purple-facebook
    purple-hangouts
    telegram-purple
    purple-matrix
  ];

  # services.thelounge.enable = true;
  # services.thelounge.theme = "thelounge-theme-mininapse";
  # services.thelounge.port = 9002;

  services.dnscrypt-proxy2.enable = false;
  services.dnscrypt-proxy2.settings = {

    listen_addresses = [ "127.0.0.1:43" ];
    server_names = ["cs-ca2" "ev-to"];
    fallback_resolver = "1.1.1.1:53";
    sources = {
      public-resolvers = {
        urls = ["https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v2/public-resolvers.md"
                "https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md"
               ];
        cache_file = "public-resolvers.md";
        minisign_key = "RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3";
        refresh_delay = 71;
      };

      relays = {
        urls = ["https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v2/relays.md"];
        cache_file = "relays.md";
        minisign_key = "RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3";
        refresh_delay = 71;
      };
    };
    anonymized_dns.routes = [
      { server_name="cs-ca2"; via=["anon-ev-va"]; }
      { server_name="ev-to"; via=["anon-cs-ca2"]; }
    ];
  };

  services.dnsmasq.enable = true;
  services.dnsmasq.resolveLocalQueries = true;
  #services.dnsmasq.servers = ["127.0.0.1#43"];
  # services.dnsmasq.servers = ["127.0.0.1#43" "1.1.1.1" "8.8.8.8"];
  services.dnsmasq.servers = ["1.1.1.1" "8.8.8.8"];
  services.dnsmasq.extraConfig = ''
    cache-size=10000
    addn-hosts=/var/hosts
    conf-file=/var/dnsmasq-hosts
    conf-file=/var/distracting-hosts
  '';


  services.bitlbee.plugins = with pkgs; [
    bitlbee-mastodon
  ];

  # shitcoin vendor
  services.keybase.enable = false;

  systemd.services.block-distracting-hosts = {
    description = "Block Distracting Hosts";

    path = with pkgs; [ systemd procps ];

    serviceConfig.ExecStart = util.writeBash "block-distracting-hosts" ''
      set -e
      cp /var/undistracting-hosts /var/distracting-hosts

      # crude way to clear the cache...
      systemctl restart dnsmasq
      pkill qutebrowser
    '';

    startAt = "Mon..Fri *-*-* 09:00:00";
  };

  systemd.user.services.stop-spotify-bedtime = {
    enable      = if extra.is-minimal then false else true;
    description = "Stop spotify when Elliott goes to bed";
    wantedBy    = [ "graphical-session.target" ];
    after       = [ "graphical-session.target" ];
    serviceConfig.ExecStart = "${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop";

    startAt = "*-*-* 19:30:00";
  };

  systemd.services.unblock-distracting-hosts = {
    enable = if extra.is-minimal then false else true;

    description = "Unblock Distracting Hosts";

    path = with pkgs; [ systemd ];

    serviceConfig.ExecStart = util.writeBash "unblock-distracting-hosts" ''
      set -e
      echo "" > /var/distracting-hosts
      systemctl restart dnsmasq
    '';

    startAt = "Mon..Fri *-*-* 17:00:00";
  };

  virtualisation.docker.enable = if extra.is-minimal then false else true;

  boot.kernelPatches = [
    {
      name = "nintendo-hid";
      patch = (pkgs.fetchurl {
                url = "https://jb55.com/s/2020-03-24-HID-nintendo-add-nintendo-switch-controller-driver.patch";
                sha256 = "660302c88b797df6a89e5e715388ab22144dedfc0174597221a03a987a496a2e";
              });
      extraConfig = ''
        NINTENDO_FF y
      '';
    }
    #{ # pci acs hack, not really safe or a good idea
    #  name = "acs-overrides";
    #  patch = pkgs.fetchurl {
    #    url = "https://aur.archlinux.org/cgit/aur.git/plain/add-acs-overrides.patch?h=linux-vfio";
    #    sha256 = "1b1qjlqkbwpv82aja48pj9vpi9p6jggc8g92p4rg7zjjjs2ldp24";
    #  };
    #}
  ];
  boot.kernelParams = [ "pcie_acs_override=downstream" ];

  virtualisation.libvirtd.enable = true;
  virtualisation.libvirtd.qemuOvmf = true;
  virtualisation.libvirtd.qemuVerbatimConfig = ''
    user = "jb55"
    group = "kvm"
    cgroup_device_acl = [
      "/dev/input/by-id/usb-Topre_Corporation_Realforce-event-kbd",
      "/dev/input/by-id/usb-Razer_Razer_DeathAdder_2013-event-mouse",
      "/dev/null", "/dev/full", "/dev/zero",
      "/dev/random", "/dev/urandom",
      "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
      "/dev/rtc","/dev/hpet", "/dev/sev"
    ]
  '';

  services.samba = {
  };

  systemd.tmpfiles.rules = [
    "f /dev/shm/looking-glass 0660 jb55 qemu-libvirtd -"
    "f /dev/shm/scream 0660 jb55 qemu-libvirtd -"
  ];

  systemd.user.services.scream-ivshmem = {
    enable = true;
    description = "Scream IVSHMEM";
    serviceConfig = {
      ExecStart = "${pkgs.scream-receivers}/bin/scream-ivshmem-pulse /dev/shm/scream";
      Restart = "always";
    };
    wantedBy = [ "multi-user.target" ];
    requires = [ "pulseaudio.service" ];
  };

  systemd.user.services.btc-ban-aws = {
    enable   = if extra.is-minimal then false else true;
    description = "Ban Bitcoin EC2 nodes";
    wantedBy = [ "bitcoind-mainnet.service" ];
    after    = [ "bitcoind-mainnet.service" ];
    serviceConfig.ExecStart = util.writeBash "btc-ban-ec2" ''
      # lets chill for a bit before we do this
      ${pkgs.curl}/bin/curl -s 'https://ip-ranges.amazonaws.com/ip-ranges.json' |
      ${pkgs.jq}/bin/jq -rc '.prefixes[].ip_prefix | {"jsonrpc": "1.0", "id":"aws-banscript", method: "setban", "params": [., "add", 3450]}' |
      ${pkgs.jq}/bin/jq -s  |
      ${pkgs.curl}/bin/curl -s -u ${extra.private.btc-user}:${extra.private.btc-pass} --data-binary @/dev/stdin -H 'content-type: text/plain' ${extra.private.btc-rpc-host}:${extra.private.btc-rpc-port}
    '';
    startAt = "*-*-* *:00:00"; #hourly
  };

  environment.systemPackages = [ pkgs.virt-manager ];

  virtualisation.virtualbox.host.enable = false;#if extra.is-minimal then false else true;
  virtualisation.virtualbox.host.enableHardening = false;
  #virtualization.virtualbox.host.enableExtensionPack = true;

  users.extraUsers.jb55.extraGroups = [ "vboxusers" "bitcoin" "kvm" "input" ];

  services.xserver.videoDrivers = [ ];

  users.extraGroups.tor.members = [ "jb55" "nginx" ];
  users.extraGroups.bitcoin.members = [ "jb55" ];
  users.extraGroups.nginx.members = [ "jb55" ];
  users.extraGroups.transmission.members = [ "nginx" "jb55" ];

  programs.mosh.enable = false;
  programs.adb.enable = true;

  documentation.nixos.enable = false;

  # services.trezord.enable = if extra.is-minimal then false else true;
  services.redis.enable = if extra.is-minimal then false else true;

  services.zeronet.enable = false;
  #services.zeronet.trackers = ''
  #  http://tracker.nyap2p.com:8080/announce
  #  http://tracker3.itzmx.com:6961/announce
  #  http://tracker1.itzmx.com:8080/announce
  #  https://trakx.herokuapp.com:443/announce
  #  udp://ultra.zt.ua:6969/announce
  #'';

  services.mongodb.enable = if extra.is-minimal then false else false;

  services.tor.enable = if extra.is-minimal then false else true;
  services.tor.controlPort = 9051;
  services.tor.client.enable = true;
  services.tor.extraConfig = extra.private.tor.extraConfig;

  services.fcgiwrap.enable = if extra.is-minimal then false else true;

  services.nix-serve.enable = false;
  services.nix-serve.bindAddress = nix-serve.bindAddress;
  services.nix-serve.port = nix-serve.port;

  services.xserver.screenSection = ''
    Option "metamodes" "1920x1080_144 +0+0"
    Option "dpi" "96 x 96"
  '';

  services.nginx.enable = if extra.is-minimal then false else true;
  services.nginx.httpConfig = ''
      server {
        listen      80 default_server;
        server_name _;
        root /www/public;
        index index.html index.htm;
        location / {
          try_files $uri $uri/ =404;
        }
      }

    '' + (if config.services.nix-serve.enable then ''
      server {
        listen ${nix-serve.bindAddress}:80;
        server_name cache.monad.jb55.com;

        location / {
          proxy_pass  http://${nix-serve.bindAddress}:${toString nix-serve.port};
          proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
          proxy_redirect off;
          proxy_buffering off;
          proxy_set_header        Host            $host;
          proxy_set_header        X-Real-IP       $remote_addr;
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
      }
    '' else "") + (if config.services.tor.enable then extra.private.tor.nginx else "");

  # services.footswitch = {
  #   enable = false;
  #   enable-led = true;
  #   led = "input5::numlock";
  # };

  systemd.services.disable-c6 = {
    description = "Ryzen Disable C6 State";

    wantedBy = [ "basic.target" ];
    after = [ "sysinit.target" "local-fs.target" ];

    serviceConfig.Type = "oneshot";
    serviceConfig.ExecStart = util.writeBash "disable-c6-state" ''
      ${pkgs.kmod}/bin/modprobe msr
      ${pkgs.python2}/bin/python ${zenstates}/zenstates.py --c6-disable --list
    '';
  };

  services.mysql.enable = false;
  services.mysql.package = pkgs.mariadb;

  # services.postgresql = {
  #   dataDir = "/var/db/postgresql/100/";
  #   enable = true;
  #   package = pkgs.postgresql_10;
  #   # extraPlugins = with pkgs; [ pgmp ];
  #   authentication = pkgs.lib.mkForce ''
  #     # type db  user address            method
  #     local  all all                     trust
  #     host   all all  127.0.0.1/32       trust
  #     host   all all  192.168.86.0/24    trust
  #   '';
  #   extraConfig = ''
  #     listen_addresses = '0.0.0.0'
  #   '';
  # };

  # services.postgresql = {
  #   dataDir = "/var/db/postgresql/96/";
  #   enable = true;
  #   package = pkgs.postgresql96;
  #   # extraPlugins = with pkgs; [ pgmp ];
  #   authentication = pkgs.lib.mkForce ''
  #     # type db  user address            method
  #     local  all all                     trust
  #     host   all all  127.0.0.1/32       trust
  #     host   all all  192.168.86.0/24    trust
  #   '';
  #   extraConfig = ''
  #     listen_addresses = '0.0.0.0'
  #   '';
  # };

  # security.pam.u2f = {
  #   enable = true;
  #   interactive = true;
  #   cue = true;
  #   control = "sufficient";
  #   authfile = "${pkgs.writeText "pam-u2f-config" ''
  #     jb55:vMXUgYb1ytYmOVgqFDwVOxJmvVI9F3gdSJVbvsi1A1VA-3mftTUhgARo4Kmm_8SAH6IJJ8p3LSXPSbtTSXMIpQ,04d8c1542a7391ee83112a577db968b84351f0090a9abe7c75bedcd94777cf15727c68ce4ac8858ff2812ded3c86d978efc5893b25cf906032632019fe792d3ec4
  #   ''}";
  # };

}