summaryrefslogtreecommitdiffstats
path: root/tv/2configs/xserver/default.nix
blob: f68e8e6814d32e9c11f2373487de53e83b0ccac1 (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
{ config, pkgs, ... }@args:
with import <stockholm/lib>;
let
  cfg = {
    cacheDir = cfg.dataDir;
    configDir = "/var/empty";
    dataDir = "/run/xdg/${cfg.user.name}/xmonad";
    user = config.krebs.build.user;
  };
in {

  environment.systemPackages = [
    pkgs.ff
    pkgs.font-size
    pkgs.gitAndTools.qgit
    pkgs.mpv
    pkgs.sxiv
    pkgs.xdotool
    pkgs.xsel
    pkgs.zathura
  ];

  fonts.fonts = [
    pkgs.xlibs.fontschumachermisc
  ];

  services.xserver = {

    # Don't install feh into systemPackages
    # refs <nixpkgs/nixos/modules/services/x11/desktop-managers>
    desktopManager.session = mkForce [];

    displayManager.lightdm.enable = mkForce false;
    displayManager.job.execCmd = mkForce "derp";

    enable = true;
    display = mkForce 11;
    tty = mkForce 11;

    synaptics = {
      enable = true;
      twoFingerScroll = true;
      accelFactor = "0.035";
    };
  };

  systemd.services.display-manager.enable = false;

  systemd.services.xmonad = let
    xmonad = "${pkgs.haskellPackages.xmonad-tv}/bin/xmonad";
    xmonad-prepare = pkgs.writeDash "xmonad-prepare" ''
      ${pkgs.coreutils}/bin/mkdir -p "$XMONAD_CACHE_DIR"
      ${pkgs.coreutils}/bin/mkdir -p "$XMONAD_CONFIG_DIR"
      ${pkgs.coreutils}/bin/mkdir -p "$XMONAD_DATA_DIR"
    '';
    xmonad-ready = pkgs.writeDash "xmonad-ready" ''
      {
        ${pkgs.xorg.xhost}/bin/xhost +SI:localuser:${cfg.user.name}
        ${pkgs.xorg.xhost}/bin/xhost -LOCAL:
      } &
      ${pkgs.xorg.xmodmap}/bin/xmodmap ${import ./Xmodmap.nix args} &
      ${pkgs.xorg.xrdb}/bin/xrdb ${import ./Xresources.nix args} &
      ${pkgs.xorg.xsetroot}/bin/xsetroot -solid '#1c1c1c' &
      wait
    '';
  in {
    wantedBy = [ "graphical.target" ];
    requires = [ "xserver.service" ];
    environment = {
      DISPLAY = ":${toString config.services.xserver.display}";
      FZMENU_FZF_DEFAULT_OPTS = toString [
        "--color=dark,border:126,bg+:090"
        "--inline-info"
      ];
      XMONAD_CACHE_DIR = cfg.cacheDir;
      XMONAD_CONFIG_DIR = cfg.configDir;
      XMONAD_DATA_DIR = cfg.dataDir;
      XMONAD_STARTUP_HOOK = xmonad-ready;
      XMONAD_WORKSPACES0_FILE = pkgs.writeJSON "xmonad-workspaces0.json" [
        "Dashboard" # we start here
        "23"
        "cr"
        "ff"
        "hack"
        "im"
        "mail"
        "stockholm"
        "za" "zh" "zj" "zs"
      ];
    };
    path = [
      config.tv.slock.package
      pkgs.fzmenu
      pkgs.pulseaudioLight.out
      pkgs.rxvt_unicode
      pkgs.xcalib
      "/run/wrappers" # for su
    ];
    serviceConfig = {
      ExecStartPre = "@${xmonad-prepare} xmonad-prepare";
      ExecStart = "@${xmonad} xmonad-${currentSystem}";
      ExecStop = "@${xmonad} xmonad-${currentSystem} --shutdown";
      SyslogIdentifier = "xmonad";
      User = cfg.user.name;
      WorkingDirectory = cfg.user.home;
    };
  };

  systemd.services.xserver = {
    after = [
      "acpid.service"
      "local-fs.target"
      "systemd-udev-settle.service"
    ];
    wants = [
      "systemd-udev-settle.service"
    ];
    restartIfChanged = false;
    environment = {
      LD_LIBRARY_PATH = concatStringsSep ":" ([ "/run/opengl-driver/lib" ]
        ++ concatLists (catAttrs "libPath" config.services.xserver.drivers));
    };
    serviceConfig = {
      SyslogIdentifier = "xserver";
      ExecStart = toString [
        "${pkgs.xorg.xorgserver}/bin/X"
        ":${toString config.services.xserver.display}"
        "vt${toString config.services.xserver.tty}"
        "-config ${import ./xserver.conf.nix args}"
        "-logfile /dev/null -logverbose 0 -verbose 3"
        "-nolisten tcp"
        "-xkbdir ${config.services.xserver.xkbDir}"
      ];
    };
  };

  systemd.services.urxvtd = {
    wantedBy = [ "graphical.target" ];
    restartIfChanged = false;
    serviceConfig = {
      SyslogIdentifier = "urxvtd";
      ExecStart = "${pkgs.rxvt_unicode}/bin/urxvtd";
      Restart = "always";
      RestartSec = "2s";
      StartLimitBurst = 0;
      User = cfg.user.name;
    };
  };

  tv.slock = {
    enable = true;
    user = cfg.user;
  };
}