summaryrefslogtreecommitdiff
path: root/modules/nixfiles/vscode.nix
blob: 7175b3661e877dc53c3251aab8449939469e9534 (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
{
  config,
  lib,
  pkgs,
  ...
}:
with lib; let
  cfg = config.nixfiles.modules.vscode;
in {
  options.nixfiles.modules.vscode = {
    enable = mkEnableOption "VSCode";

    package = with pkgs;
      mkOption {
        type = types.enum [vscodium vscode vscode-fhs];
        default = vscodium;
        description = "Which package to use as a VSCode implementation.";
      };

    vim.enable = mkOption {
      type = types.bool;
      default = true;
      description = "Whether to enable Vim emulation.";
    };
  };

  config = mkIf cfg.enable {
    hm.programs.vscode = with config.nixfiles;
    with modules;
    with profiles; {
      enable = true;

      inherit (cfg) package;

      extensions = with pkgs;
      with vscode-extensions;
        [editorconfig.editorconfig file-icons.file-icons redhat.vscode-yaml]
        ++ optional cfg.vim.enable vscodevim.vim
        ++ vscode-utils.extensionsFromVscodeMarketplace [
          {
            name = "vscode-xml";
            publisher = "redhat";
            version = "0.20.0";
            hash = "sha256-GKBrf9s8n7Wv14RSfwyDma1dM0fGMvRkU/7v2DAcB9A=";
          }
        ];

      userSettings = let
        font = config.fontScheme.monospaceFont;
        fontFamily = font.family;
        fontSize = font.size;
      in {
        editor =
          {
            inherit fontFamily fontSize;
            inlayHints = {inherit fontFamily fontSize;};
            codeLens = false;
            cursorStyle = "block";
            detectIndentation = true;
            minimap.enabled = false;
            renderWhitespace = "trailing";
            rulers = [80 120];
            smoothScrolling = false;
            tabCompletion = true;
          }
          // (let
            surround = 10;
          in {
            cursorSurroundingLines = surround;
            scrollBeyondLastColumn = surround;
          });

        keyboard.dispatch = "keyCode";

        diffEditor.codeLens = false;

        files = {
          autoSave = "off";
          enableTrash = false;
        };

        workbench = {
          activityBar.visible = false;
          editor.highlightModifiedTabs = true;
          enableExperiments = false;
          settings.enableNaturalLanguageSearch = false;
          startupEditor = "none";
          tips.enabled = false;
          tree.indent = 4;
          welcomePage = {
            walkthroughs.openOnInstall = false;
            preferReducedMotion = true;
          };
        };

        debug.console = {inherit fontFamily fontSize;};

        scm = {
          inputFontFamily = fontFamily;
          inputFontSize = fontSize;
        };

        extensions = {
          autoCheckUpdates = false;
          autoUpdate = false;
          ignoreRecommendations = true;
        };

        terminal = {
          external.linuxExec =
            if alacritty.enable
            then "${pkgs.alacritty}/bin/alacritty"
            else "${pkgs.xterm}/bin/xterm}";

          integrated = {
            inherit fontFamily fontSize;
            enableBell = true;
          };
        };

        update = {
          mode = "none";
          showReleaseNotes = false;
        };

        telemetry = {
          enableCrashReporter = false;
          enableTelemetry = false;
        };

        security.workspace.trust.enabled = false;

        git.allowForcePush = true;

        vim = let
          applyInputMethod = {
            "ibus" = let
              bin = "${pkgs.ibus}/bin/ibus";
            in {
              enable = true;
              defaultIM = "xkb:us::eng";
              obtainIMCmd = "${bin} engine";
              switchIMCmd = "${bin} engine {im}";
            };
            "fcitx" = let
              bin = "${pkgs.fcitx}/bin/fcitx-remote";
            in {
              enable = true;
              defaultIM = "1";
              obtainIMCmd = bin;
              switchIMCmd = "${bin} -t {im}";
            };
          };
        in
          mkIf cfg.vim.enable rec {
            easymotion = true;
            easymotionMarkerFontFamily = fontFamily;
            easymotionMarkerFontSize = fontSize;

            leader = " ";

            useSystemClipboard = true;

            autoSwitchInputMethod = let
              inputMethod = config.i18n.inputMethod.enabled;
            in
              mkIf (inputMethod != null) applyInputMethod.${inputMethod};
          };
      };
    };
  };
}