summaryrefslogtreecommitdiff
path: root/machines/work.nix
blob: 38c1978b84e3a9baed218d1436416ed6d82e41b7 (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
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
{ self, config, pkgs, lib, ... }: with lib; {
  options = {
    virtualisation = mkSinkUndeclaredOptions {};
    programs = {
      virt-manager = mkSinkUndeclaredOptions {};
      steam = mkSinkUndeclaredOptions {};
    };
    hardware = mkSinkUndeclaredOptions {};
    services = {
      resolved = mkSinkUndeclaredOptions {};
      openssh.enable = mkOption {
        type = types.bool;
        default = false;
      };
    };
    security = {
      sudo.wheelNeedsPassword = mkSinkUndeclaredOptions {};
    };
    systemd = mkSinkUndeclaredOptions {};
    users.users = mkOption {
      type = types.attrsOf (types.submodule ({...}: {
        options = {
          extraGroups = mkSinkUndeclaredOptions {};
          isNormalUser = mkSinkUndeclaredOptions {};
        };
        config = {
          home = "/Users/${ivi.username}";
        };
      }));
    };
  };
  config = {
    # List packages installed in system profile. To search by name, run:
    # $ nix-env -qaP | grep wget
    environment.systemPackages =
      [ pkgs.qemu
        pkgs.kitty
        pkgs.openssh
        pkgs.python311
        pkgs.mpv
        pkgs.kubelogin
        pkgs.zsh
        pkgs.bashInteractive
        pkgs.awscli2
        pkgs.skhd
        pkgs.act
        pkgs.yubikey-manager
        pkgs.gomplate
     ];
    hm = {
      home = {
        sessionPath = [
          "/opt/homebrew/bin"
        ];
        file."gpg-agent.conf" = {
          text = ''
            pinentry-program /opt/homebrew/bin/pinentry-mac
          '';
          target = ".gnupg/gpg-agent.conf";
        };
      };
      programs.kitty = {
        enable = true;
        shellIntegration = {
          enableZshIntegration = true;
        };
        extraConfig = ''
          allow_remote_control yes
          cursor_shape block
          font_family      JetBrainsMono Nerd Font Mono
          text_composition_strategy platform
          cursor_blink_interval 0
          draw_minimal_borders yes
          hide_window_decorations no
          confirm_os_window_close 0
          macos_option_as_alt yes
          linux_display_server x11

          clear_all_shortcuts yes
          kitty_mod alt
          mouse_map right press ungrabbed mouse_select_command_output
          map kitty_mod+v mouse_select_command_output
          scrollback_pager less --chop-long-lines --RAW-CONTROL-CHARS +INPUT_LINE_NUMBER

          map kitty_mod+shift+k change_font_size all +2.0
          map kitty_mod+shift+j change_font_size all -2.0

          map kitty_mod+k scroll_to_prompt -1
          map kitty_mod+j scroll_to_prompt 1
          map kitty_mod+l show_last_visited_command_output
          map kitty_mod+shift+l show_scrollback

          map kitty_mod+w>p show_last_visited_command_output
          map kitty_mod+w>shift+p show_first_command_output_on_screen

          map kitty_mod+w>_ toggle_layout stack
          map kitty_mod+w>= goto_layout fat
          map kitty_mod+w>g goto_layout grid

          map kitty_mod+w>c close_window
          map kitty_mod+w>j neighboring_window bottom
          map kitty_mod+w>k neighboring_window top
          map kitty_mod+w>h neighboring_window left
          map kitty_mod+w>l neighboring_window right
          map kitty_mod+w>e open_url_with_hints
          map kitty_mod+w>space move_window_to_top
          map kitty_mod+w>shift+k move_window_forward
          map kitty_mod+w>shift+j move_window_backward

          map kitty_mod+enter new_window
          map kitty_mod+r load_config_file
          map cmd+c copy_to_clipboard
          map cmd+v paste_from_clipboard
          map cmd+q quit

          ## name: Kanagawa
          ## license: MIT
          ## author: Tommaso Laurenzi
          ## upstream: https://github.com/rebelot/kanagawa.nvim/


          background #1F1F28
          foreground #DCD7BA
          selection_background #2D4F67
          selection_foreground #C8C093
          url_color #72A7BC
          cursor #C8C093

          # Tabs
          active_tab_background #1F1F28
          active_tab_foreground #C8C093
          inactive_tab_background  #1F1F28
          inactive_tab_foreground #727169
          #tab_bar_background #15161E

          # normal
          color0 #16161D
          color1 #C34043
          color2 #76946A
          color3 #C0A36E
          color4 #7E9CD8
          color5 #957FB8
          color6 #6A9589
          color7 #C8C093

          # bright
          color8  #727169
          color9  #E82424
          color10 #98BB6C
          color11 #E6C384
          color12 #7FB4CA
          color13 #938AA9
          color14 #7AA89F
          color15 #DCD7BA


          # extended colors
          color16 #FFA066
          color17 #FF5D62
        '';
      };
    };

    networking.hostName = "work";
    sops.age.keyFile = "${config.hm.xdg.configHome}/sops/age/keys.txt";
    homebrew = {
      enable = true;
      brews = [
        "pinentry-mac"
      ];
      casks = [
        "docker"
      ];
      masApps = {
        tailscale = 1475387142;
        slack = 803453959;
      };
    };
    services.syncthing = {
      cert = builtins.toFile "syncthing-cert" ''
        -----BEGIN CERTIFICATE-----
        MIICHDCCAaKgAwIBAgIICf/IfhEqojIwCgYIKoZIzj0EAwIwSjESMBAGA1UEChMJ
        U3luY3RoaW5nMSAwHgYDVQQLExdBdXRvbWF0aWNhbGx5IEdlbmVyYXRlZDESMBAG
        A1UEAxMJc3luY3RoaW5nMB4XDTI0MDIwOTAwMDAwMFoXDTQ0MDIwNDAwMDAwMFow
        SjESMBAGA1UEChMJU3luY3RoaW5nMSAwHgYDVQQLExdBdXRvbWF0aWNhbGx5IEdl
        bmVyYXRlZDESMBAGA1UEAxMJc3luY3RoaW5nMHYwEAYHKoZIzj0CAQYFK4EEACID
        YgAEB3N4kE5gTlpCt8W/ocQQbDZMvIzmNghcl0tsc+EVPXCTnpinIB48jOxGNkPr
        rm0o3EEPrI8O+cJqSydeyeSVMKYCjNswP6LiYNWaWua+SXjz25FurJxV21LXYMhc
        1egPo1UwUzAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG
        AQUFBwMCMAwGA1UdEwEB/wQCMAAwFAYDVR0RBA0wC4IJc3luY3RoaW5nMAoGCCqG
        SM49BAMCA2gAMGUCMEOYa4HZKLy4WimWlAIpXU/joYvpIPS3dJP50VQIkKFj/eL8
        p8+rG7+7P03W7J4E6AIxANp5CxwCtTlh1a1+8Kdvfc7ZvFuMwPlM3d8EFk9y9aRZ
        jurkqKKyl7EUOk0ufvUaQQ==
        -----END CERTIFICATE-----
      '';
    };
    services.skhd = {
      enable = true;
      skhdConfig = ''
        cmd - 1 : osascript -e 'tell application "alacritty" to activate'
        cmd - 2 : osascript -e 'tell application "Google Chrome" to activate'
        cmd - 3 : osascript -e 'tell application "slack" to activate'
        cmd - 4 : osascript -e 'tell application "Microsoft Teams (work or school)" to activate'
        cmd - 5 : osascript -e 'tell application "calendar" to activate'
        cmd - 6 : osascript -e 'tell application "mail" to activate'
        cmd - k : ${pkgs.writers.writeBash "cycle_cclockwise" ''
          if ! yabai -m window --focus prev &>/dev/null; then
            yabai -m window --focus last
          fi
        ''}
        cmd - j : ${pkgs.writers.writeBash "cycle_clockwise" ''
          if ! yabai -m window --focus next &>/dev/null; then
            yabai -m window --focus first
          fi
        ''}
        cmd + shift - k : ${pkgs.writers.writeBash "swap_cclockwise" ''
          win=$(yabai -m query --windows --window first | jq '.id')

          while : ; do
              yabai -m window $win --swap next &> /dev/null
              if [[ $? -eq 1 ]]; then
                  break
              fi
          done
        ''}
        cmd + shift - j : ${pkgs.writers.writeBash "swap_clockwise" ''
          win=$(yabai -m query --windows --window last | jq '.id')

          while : ; do
              yabai -m window $win --swap prev &> /dev/null
              if [[ $? -eq 1 ]]; then
                  break
              fi
          done
        ''}
        cmd - w [
          "Google Chrome" ~
          * : osascript -e 'tell application "Google Chrome" to activate'
        ]
        cmd - e : osascript -e 'tell application "mail" to activate'
        cmd - m : osascript -e 'tell application "Slack" to activate'
        cmd + shift - m : osascript -e 'tell application "Microsoft Teams (work or school)" to activate'
        cmd - return : /Applications/Alacritty.app/Contents/MacOS/alacritty
        cmd - space : yabai -m window --swap first
        cmd + shift - space : yabai -m window --toggle float
        cmd - d : ${pkgs.writers.writeBash "passautotype" ''
          shopt -s nullglob globstar

          dmenu="/opt/homebrew/bin/dmenu-mac"

          (
              export PASSWORD_STORE_DIR="$HOME/sync/password-store"
              prefix="$PASSWORD_STORE_DIR"
              echo "prefix: $prefix"
              password_files=( "$prefix"/**/*.gpg )
              password_files=( "''${password_files[@]#"$prefix"/}" )
              password_files=( "''${password_files[@]%.gpg}" )
              echo "password_files: ''${password_files[*]}"

              password="$(printf '%s\n' "''${password_files[@]}" | "$dmenu" "$@")"
              echo "password: $password"

              [[ -n $password ]] || exit

              /Applications/Hammerspoon.app/Contents/Frameworks/hs/hs -c "hs.loadSpoon([[PassAutotype]]):autotype([[$password]])"
          ) >/tmp/debug 2>&1
        ''}
        cmd + shift - d : ${pkgs.writers.writeBash "passmenu" ''
          shopt -s nullglob globstar

          dmenu="/opt/homebrew/bin/dmenu-mac"

          (
              export PASSWORD_STORE_DIR="$HOME/sync/password-store"
              prefix="$PASSWORD_STORE_DIR"
              echo "prefix: $prefix"
              password_files=( "$prefix"/**/*.gpg )
              password_files=( "''${password_files[@]#"$prefix"/}" )
              password_files=( "''${password_files[@]%.gpg}" )
              echo "password_files: ''${password_files[*]}"

              password="$(printf '%s\n' "''${password_files[@]}" | "$dmenu" "$@")"
              echo "password: $password"

              [[ -n $password ]] || exit

              ${pkgs.pass}/bin/pass show -c "$password"
          ) >/tmp/debug 2>&1
        ''}
      '';
    };
    services.sketchybar.enable = true;
    services.yabai = {
      enable = true;
      package = pkgs.yabai;
      enableScriptingAddition = true;
      config = {
        focus_follows_mouse          = "off";
        mouse_follows_focus          = "off";
        window_placement             = "first_child";
        window_opacity               = "off";
        window_opacity_duration      = "0.0";
        window_border                = "on";
        window_border_placement      = "inset";
        window_border_width          = 2;
        window_border_radius         = 3;
        active_window_border_topmost = "off";
        window_topmost               = "on";
        window_shadow                = "float";
        active_window_border_color   = "0xff5c7e81";
        normal_window_border_color   = "0xff505050";
        insert_window_border_color   = "0xffd75f5f";
        active_window_opacity        = "1.0";
        normal_window_opacity        = "1.0";
        split_ratio                  = "0.50";
        split_type                   = "horizontal";
        auto_balance                 = "off";
        mouse_modifier               = "fn";
        mouse_action1                = "move";
        mouse_action2                = "resize";
        layout                       = "bsp";
        window_origin_display        = "focused";
        display_arrangement_order    = "vertical";
        top_padding                  = 10;
        bottom_padding               = 10;
        left_padding                 = 10;
        right_padding                = 10;
        window_gap                   = 10;
      };

      extraConfig = ''
          # rules
          yabai -m rule --add app='System Settings' manage=off
          yabai -m rule --add app='alacritty' title='dap' display='2'
          yabai -m signal --add event=display_changed action=${pkgs.writers.writeBash "padding" ''
            if ! yabai -m window --focus prev &>/dev/null; then
              yabai -m window --focus last
            fi
          ''}

          # Any other arbitrary config here
        '';
    };
    # Auto upgrade nix package and the daemon service.
    services.nix-daemon.enable = true;
    # nix.package = pkgs.nix;

    # Necessary for using flakes on this system.
    nix.settings.experimental-features = "nix-command flakes";

    nix.extraOptions = ''extra-platforms = x86_64-darwin aarch64-darwin '';

    # Set Git commit hash for darwin-version.
    system.configurationRevision = self.rev or self.dirtyRev or null;

    # Used for backwards compatibility, please read the changelog before changing.
    # $ darwin-rebuild changelog
    system.stateVersion = 4;

    # The platform the configuration will be used on.
    nixpkgs.hostPlatform = "aarch64-darwin";
    users.users.${ivi.username} = {
      shell = pkgs.zsh;
    };
    environment.shells = [pkgs.bashInteractive pkgs.zsh];
    environment.pathsToLink = [ "/share/zsh" ];
    environment.variables = {
      SLACK_NO_AUTO_UPDATES = "1";
    };
    programs.zsh.enable = true;
  };
}