Files
nix/users/configs/vscode/default.nix
2024-06-21 23:39:18 +03:00

103 lines
3.9 KiB
Nix

{ user ? throw "user argument is required" }: { inputs, lib, pkgs, ... }:
let
configDir = ".config/Code";
cacheDirs = [
".config/Code/Cache"
".config/Code/CachedConfigurations"
".config/Code/CachedData"
".config/Code/CachedExtensionVSIXs"
".config/Code/CachedExtensions"
".config/Code/CachedProfilesData"
".config/Code/Code Cache"
".config/Code/DawnCache"
".config/Code/GPUCache"
".config/Code/Service Worker/CacheStorage"
".config/Code/Service Worker/ScriptCache"
];
inherit (pkgs.callPackage "${inputs.impermanence}/lib.nix" { }) sanitizeName concatPaths;
in {
home-manager.users."${user.name}" = {
programs.vscode = {
enable = true;
mutableExtensionsDir = false;
userSettings = {
"editor.accessibilitySupport" = "off";
"editor.cursorBlinking" = "phase";
"editor.cursorSmoothCaretAnimation" = "on";
"editor.formatOnPaste" = true;
"editor.formatOnSave" = true;
"editor.formatOnType" = true;
"editor.indentSize" = "tabSize";
"editor.inlineSuggest.enabled" = true;
"editor.largeFileOptimizations" = false;
"editor.linkedEditing" = true;
"editor.renderFinalNewline" = "on";
"editor.smoothScrolling" = true;
"editor.stickyScroll.enabled" = true;
"editor.suggestSelection" = "first";
"editor.unicodeHighlight.includeComments" = true;
"editor.unicodeHighlight.nonBasicASCII" = true;
"explorer.confirmDelete" = false;
"explorer.confirmDragAndDrop" = false;
"explorer.confirmPasteNative" = false;
"files.autoSave" = "afterDelay";
"files.eol" = "\n";
"files.insertFinalNewline" = true;
"files.trimFinalNewlines" = true;
"files.trimTrailingWhitespace" = true;
"git.allowForcePush" = true;
"git.alwaysSignOff" = true;
"git.autofetch" = "all";
"git.closeDiffOnOperation" = true;
"git.confirmForcePush" = false;
"git.confirmSync" = false;
"git.enableCommitSigning" = true;
"git.enableSmartCommit" = true;
"git.ignoreRebaseWarning" = true;
"git.openRepositoryInParentFolders" = "always";
"git.path" = "${pkgs.git}/bin/git";
"mergeEditor.diffAlgorithm" = "advanced";
"open-in-browser.default" = "firefox";
"security.workspace.trust.enabled" = false;
"telemetry.telemetryLevel" = "off";
"terminal.external.linuxExec" = "kitty";
"terminal.integrated.confirmOnExit" = "hasChildProcesses";
"terminal.integrated.copyOnSelection" = true;
"window.autoDetectHighContrast" = false;
"window.menuBarVisibility" = "toggle";
"workbench.editor.historyBasedLanguageDetection" = true;
"workbench.list.smoothScrolling" = true;
};
};
imports = [
./langs/nix.nix
];
home.persistence = {
"/persist${user.home}".directories = [ configDir ];
# Bastard: https://github.com/microsoft/vscode/issues/3884
"/cache${user.home}".directories = cacheDirs;
};
# Some filthy fucking shit below, be warned.
# Microsoft stores cache under .config/Code instead of .cache/Code like normal people.
# Sometimes a race condition is caused if the cache bind mounts are created before the config one.
# So we do this. Sorry.
# https://github.com/nix-community/impermanence/blob/27979f1c3a0d3b9617a3563e2839114ba7d48d3f/home-manager.nix#L238
systemd.user.services = let
configDirService = "bindMount-${sanitizeName (lib.strings.escapeShellArg (concatPaths [ "/persist${user.home}" configDir ]))}.service";
in
builtins.listToAttrs (builtins.map (dir: {
name = "bindMount-${sanitizeName (lib.strings.escapeShellArg (concatPaths [ "/cache${user.home}" dir ]))}";
value = {
Unit = {
Requires = [ configDirService ];
After = [ configDirService ];
};
};
}) cacheDirs);
};
}