summaryrefslogtreecommitdiff
path: root/bragi.nix
blob: e276cf103855630101d8c8ad99e14013e3b08bb3 (plain)
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
{ config, pkgs, ... }:

let
  inherit (pkgs) lib;
in rec {
  imports =
    [ ./musnix
      ./bragi/hw.nix
      ./custom/zsh.nix
      ./users.nix
      ./custom/unit-status-mail.nix
      ./custom/trivmix-service.nix
      ./custom/mpd.nix
      ./utils/nix/module.nix
    ];

  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;

  boot.kernelModules = [ "usblp" ];

  boot.tmpOnTmpfs = true;

  boot.supportedFilesystems = [ "cifs" ];

  networking = {
    hostName = "bragi";
    hostId = "2af11085";

    firewall.enable = false;

    defaultMailServer = {
      directDelivery = true;
      hostName = "ymir.niflheim.yggdrasil";
      useSTARTTLS = true;
      setSendmail = true;
    };
  };

  nixpkgs = {
    overlays = [
      (selfPkgs: superPkgs: {
        jack2Full = superPkgs.jack2Full.override { dbus = null; };
        mpd = superPkgs.mpd.override { gmeSupport = false; pulseaudioSupport = false; };
        haskellPackages = superPkgs.haskellPackages.extend (selfH: superH: {
          yaml = selfH.lib.dontCheck superH.yaml;
        });
      })
    ];

    config = {
      allowUnfree = true;
    };
  };

  environment.systemPackages = with pkgs; [
    git
    mosh
    rsync
    tmux
    nfs-utils
    jack2Full
    rebuild-system
  ];

  # List services that you want to enable:

  services.openssh = {
    enable = true;
  };

  services.journald = {
    rateLimitBurst = 0;
  };
    
  systemd.globalEnvironment = {
    JACK_PROMISCUOUS_SERVER = "1";
  };

  environment.sessionVariables = {
    JACK_PROMISCUOUS_SERVER = "1";
  };

  musnix = {
    enable = true;
    alsaSeq.enable = false;
    kernel = {
      packages = with pkgs; linuxPackages_latest_rt;
      optimize = true;
      realtime = true;
    };
  };

  systemd.services.jack = {
    wantedBy = [ "sound.target" ];
    serviceConfig = {
      Type = "simple";
      ExecStart = "${pkgs.jack2Full}/bin/jackd -d alsa -d 'hw:1' -M -H -r 96000";
      ExecStartPost = "${pkgs.jack2Full}/bin/jack_wait -w -t 5";
      User = "jack";
      Group = "audio";
      UMask = "0000";
      Nice = "-15";
      LimitRTPRIO = "95:95";
      LimitMEMLOCK = "infinity";
    };
  };

  services.trivmix = {
    fps = "20"; interval = "0.5";

    mixers = {
      "mpdmix0" = { connectOut = "outnode0:in"; group = "mpd"; initial = "-35dB"; };
      "mpdmix1" = { connectOut = "outnode1:in"; group = "mpd"; initial = "-35dB"; };

      "passmix0" = { connectOut = "outnode0:in"; connectIn = "system:capture_5"; group = "vali_out"; initial = "-5dB"; };
      "passmix1" = { connectOut = "outnode1:in"; connectIn = "system:capture_6"; group = "vali_out"; initial = "-5dB"; };

      "passmix2" = { connectOut = "system:playback_5"; connectIn = "system:capture_1"; group = "mic_out"; initial = "1"; };
      "passmix3" = { connectOut = "system:playback_6"; connectIn = "system:capture_1"; group = "mic_out"; initial = "1"; };

      "passmix4" = { connectOut = "outnode0:in"; connectIn = "system:capture_7"; group = "hel_out"; initial = "-5dB"; };
      "passmix5" = { connectOut = "outnode1:in"; connectIn = "system:capture_8"; group = "hel_out"; initial = "-5dB"; };

      "outnode0" = { initial = "1"; adjustable = false; };
      "outnode1" = { initial = "1"; adjustable = false; };

      "headphones0" = { connectOut = "system:playback_3"; connectIn = "outnode0:out"; group = "headphones"; initial = "1"; balance = "left"; };
      "headphones1" = { connectOut = "system:playback_4"; connectIn = "outnode1:out"; group = "headphones"; initial = "1"; balance = "right"; };

      "speakers0" = { connectOut = "system:playback_7"; connectIn = "outnode0:out"; group = "speakers"; initial = "0"; balance = "left"; };
      "speakers1" = { connectOut = "system:playback_8"; connectIn = "outnode1:out"; group = "speakers"; initial = "0"; balance = "right"; };
    };
  };

  services.mpd = {
    enable = true;
    musicDirectory = "smb://odin.asgard.yggdrasil/media/music";
    network.listenAddresses = [
      { address = "any"; }
      "/var/lib/mpd/socket"
    ];
    startWhenNeeded = true;
    extraConfig = ''
      audio_output {
        name "JACK"
        type "jack"
        client_name "mpd"
        destination_ports "mpdmix0:in,mpdmix1:in"
      }
    '';
    user = "mpd";
    group = "audio";
  };
  systemd.services."mpd".requires = [ "mpdmix0.service" "mpdmix1.service" ];
  systemd.services."mpd".after = [ "mpdmix0.service" "mpdmix1.service" ];
  systemd.services."mpd".serviceConfig = {
      LimitMEMLOCK = "infinity";
      Nice = "-5";
      LimitRTPRIO = lib.mkForce "95:95";
      UMask = "0000";
  };

  users.extraUsers.jack = {
    name = "jack";
    isSystemUser = true;
    group = "audio";
  };

  programs.bash.promptInit = ''
    PROMPT_COLOR="1;31m"
    return $UID && PROMPT_COLOR="1;32m"
    case "$TERM" in
      xterm*|rxvt*|kterm|aterm|gnome*) # Others can go here.
        PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]\\$\[\033[0m\] "
        if test "$TERM" = "xterm"; then
          PS1="\[\033]2;\h:\u:\w\007\]$PS1"
        fi
        ;;
      *)
        PS1="[\u@\h:\w]$ "
        ;;
    esac
  '';

  users.users.root = let
    template = (import users/gkleen.nix);
    in {
        inherit (template) shell;
        openssh.authorizedKeys.keyFiles = template.openssh.authorizedKeys.keyFiles;
      };

  nix = {
    daemonIONiceLevel = 3;
    daemonNiceLevel = 10;
    gc = {
      automatic = true;
      options = "--delete-older-than 21d";
    };
    autoOptimiseStore = true;
  };

  system.autoUpgrade.enable = true;
  system.stateVersion = "16.09";

  systemd.services."nixos-upgrade".path = with pkgs; [ git ];
  systemd.services."nixos-upgrade".preStart = ''
    git -C /etc/nixos pull
    git -C /etc/nixos submodule update
  '';

  systemd.status-mail = {
    recipient = "root@yggdrasil.li";
    onFailure = [ "nixos-upgrade" ];
  };
}