summary refs log tree commit diff
path: root/modules/home/code.nix
blob: 334b367328f318bf06170870c73089bd7ed4b70d (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
{
  config,
  pkgs,
  unstablePkgs,
  lib,
  ...
}:

let
  inherit (lib)
    elem
    head
    range
    versions
    removePrefix
    stringAsChars
    ;

  # filters characters from string `s` according to funciton `f`.
  # NOTE: this could probably be a util.
  filterString = f: s: stringAsChars (c: if f c then c else "") s;

  extensions = with unstablePkgs.vscode-extensions; [
    # Microsoft vendor extensions
    ms-vscode.hexeditor
    ms-vscode-remote.remote-containers
    ms-vscode-remote.remote-ssh
    ms-azuretools.vscode-docker
    github.codespaces

    # Usability
    vscodevim.vim
    waderyan.gitblame
    mkhl.direnv
    alefragnani.bookmarks

    # Dumb AI stuff, for evaluation
    github.copilot
    github.copilot-chat
    continue.continue

    # Language support
    ms-vscode.makefile-tools
    ms-vscode.cpptools
    ms-vscode.cpptools-extension-pack
    mesonbuild.mesonbuild
    ms-python.python
    ms-python.debugpy
    charliermarsh.ruff
    golang.go
    jnoortheen.nix-ide
    rust-lang.rust-analyzer
    haskell.haskell
    justusadam.language-haskell
    elixir-lsp.vscode-elixir-ls

    # Pretty :3
    aaron-bond.better-comments
    catppuccin.catppuccin-vsc-icons
    catppuccin.catppuccin-vsc
    jdinhlife.gruvbox
  ];

  externalExtensions = with pkgs.open-vsx; [
    # Extensions that aren't included in nixpkgs
    espressif.esp-idf-extension
    geequlim.godot-tools
    miguelsolorio.fluent-icons
    tonybaloney.vscode-pets
  ];

  newVendorExtensions = with pkgs.vscode-marketplace; [
    # Quick editing and viewing of ad-hoc repos and pull request
    ms-vscode.remote-repositories
    github.remotehub
    # Extra extension for PlatformIO tools
    platformio.platformio-ide
  ];

  inherit (pkgs) esp-idf-full;
  esp-idf-python-env = head esp-idf-full.propagatedBuildInputs;

  digits = map toString (range 0 9);
  filterVersionString = v: filterString (c: elem c digits || c == ".") v;
  mkVersion = v: versions.majorMinor (filterVersionString v);

  # the ESP-IDF extension for VSCode for some reason
  # really wants a python environment under this path in `tools/`...
  espIdfV = mkVersion esp-idf-full.version;
  pyEnvV = mkVersion (removePrefix "python3" esp-idf-python-env.name);
  pythonEnvFolderName = "idf${espIdfV}_py${pyEnvV}_env";

  esp-idf = esp-idf-full.overrideAttrs (attrs: {
    installPhase =
      (attrs.installPhase or "")
      + ''
        mkdir -p $out/tools/python_env
        ln -s ${esp-idf-python-env} $out/tools/python_env/${pythonEnvFolderName}

        # for some reason the tools script likes doubling up
        # the tools folder, fix that.
        substituteInPlace $out/tools/idf_tools.py \
          --replace-fail \
            "os.path.join(g.idf_tools_path, 'tools'," \
            "os.path.join(g.idf_tools_path,"
      '';
  });

  settings = import ./../../configs/vscode/settings.nix { inherit pkgs lib esp-idf; };
  keybindings = import ./../../configs/vscode/keybindings.nix { };

in
{
  programs.vscode = {
    enable = true;
    enableUpdateCheck = false;
    enableExtensionUpdateCheck = false;
    mutableExtensionsDir = false;
    package = unstablePkgs.vscodium-fhs;

    extensions = extensions ++ externalExtensions ++ newVendorExtensions;
    keybindings = keybindings;
    userSettings = settings;
  };

  # also make the user-settings file mutable, since most
  # vscode extensions don't like read-only configuration files.
  home.file."${config.xdg.configHome}/VSCodium/User/settings.json" = {
    mutable = true;
    force = true;
  };
}