Kakoune IDE mode

This commit is contained in:
Riley Apeldoorn 2022-01-10 18:25:34 +00:00
parent 67073eb3de
commit fe0fdc63d9
18 changed files with 601 additions and 232 deletions

View file

@ -1,39 +0,0 @@
{ pkgs, config, ... }:
{
home-manager.users."riley" = {
programs.alacritty = {
enable = true;
settings = {
window.padding = { x = 8; y = 8; };
font = {
normal = { family = "Fira Code"; style = "Regular"; };
bold = { family = "Fira Code"; style = "Medium"; };
};
colors = let theme = (import ./colors.nix)."dark"; in {
primary = {
background = "#" + theme.background.primary;
foreground = "#" + theme.foreground.primary;
};
normal = {
red = "#" + theme.red.normal;
blue = "#" + theme.blue.normal;
magenta = "#" + theme.purple.normal;
};
bright = {
red = "#" + theme.red.bright;
blue = "#" + theme.blue.bright;
magenta = "#" + theme.purple.bright;
};
};
};
};
};
}

View file

@ -1,6 +1,6 @@
# Color schemes.
{
let inherit (builtins) mapAttrs map; in rec {
# A simple dark theme with vibrant colors.
"dark" = rec {
@ -57,45 +57,63 @@
red = {
normal = "ff6161";
bright = "ff3b3b";
pastel = "ff8787";
pastel = "ff5369";
};
green = {
normal = "";
bright = "";
bright = "29f26c";
normal = "8aff80";
pastel = "";
};
blue = {
normal = "3eafff";
bright = "30c7ff";
normal = "30c7ff";
bright = "00e1ff";
pastel = "";
};
yellow = {
normal = "";
bright = "";
normal = "fcfc51";
bright = "fcfc51";
pastel = "";
};
purple = {
normal = "bd78fa";
bright = "dda1ff";
pastel = "";
bright = "c97ffa";
pastel = "00e1ff";
};
cyan = {
normal = "";
bright = "";
normal = "29f8ff";
bright = "26e3fc";
pastel = "";
};
pink = {
normal = "f74ddb";
bright = "ff63e5";
pastel = "";
};
orange = {
normal = "";
bright = "";
normal = "ff5e69";
bright = "fca151";
pastel = "";
};
misc = {
blueGrey = "9ccdd9";
teal = "00ccad";
lime = "d5ff63";
};
hex = mapAttrs (name: value:
if name != "grayscales"
then mapAttrs (n: v: "#" + v) value
else map (v: "#" + v) value
) (dark);
};
}

View file

@ -1,128 +0,0 @@
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running nixos-help).
{ config, pkgs, ... }:
{
imports = [
# Home-manager modules
<home-manager/nixos>
./hardware-configuration.nix
# Programs
./kakoune.nix
./alacritty.nix
./git.nix
# Display server and related config
./display.nix
./fonts.nix
];
nixpkgs.config.allowUnfree = true;
nix.autoOptimiseStore = true;
nix.gc.automatic = true;
boot = {
loader.systemd-boot = {
enable = true;
editor = false;
configurationLimit = 10;
};
loader.efi.canTouchEfiVariables = true;
cleanTmpDir = true;
};
networking.hostName = "thor";
# Set your time zone.
time.timeZone = "Europe/Amsterdam";
# The global useDHCP flag is deprecated, therefore explicitly set to false here.
# Per-interface useDHCP will be mandatory in the future, so this generated config
# replicates the default behaviour.
networking.useDHCP = false;
networking.interfaces.enp9s0.useDHCP = true;
# Configure network proxy if necessary
# networking.proxy.default = "http://user:password@proxy:port/";
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
# Select internationalisation properties.
# i18n.defaultLocale = "en_US.UTF-8";
# console = {
# font = "Lat2-Terminus16";
# keyMap = "us";
# };
# Enable CUPS to print documents.
# services.printing.enable = true;
# Enable sound.
sound.enable = true;
hardware.pulseaudio.enable = true;
# Enable touchpad support (enabled default in most desktopManager).
# services.xserver.libinput.enable = true;
# Define a user account. Don't forget to set a password with passwd.
users.users."riley" = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable sudo for the user.
};
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs; [
# Some utils
wget
curl
git
# Modern coreutils
ripgrep
bottom
skim
exa
bat
lf
fd
];
# Some programs need SUID wrappers, can be configured further or are
# started in user sessions.
# programs.mtr.enable = true;
# programs.gnupg.agent = {
# enable = true;
# enableSSHSupport = true;
# };
# List services that you want to enable:
# Enable the OpenSSH daemon.
# services.openssh.enable = true;
# Open ports in the firewall.
# networking.firewall.allowedTCPPorts = [ ... ];
# networking.firewall.allowedUDPPorts = [ ... ];
# Or disable the firewall altogether.
# networking.firewall.enable = false;
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. Its perfectly fine and recommended to leave
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
system.stateVersion = "21.11"; # Did you read the comment?
}

87
configuration.nix.old Normal file
View file

@ -0,0 +1,87 @@
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running nixos-help).
{ config, pkgs, ... }:
{
config = {
imports = [
# Home-manager modules
<home-manager/nixos>
./hardware-configuration.nix
# Programs
./modules/kakoune
./alacritty.nix
./git.nix
# Display server and related config
./display.nix
./fonts.nix
];
nixpkgs.config.allowUnfree = true;
nix.autoOptimiseStore = true;
nix.gc.automatic = true;
boot = {
loader.systemd-boot = {
enable = true;
editor = false;
configurationLimit = 10;
};
loader.efi.canTouchEfiVariables = true;
cleanTmpDir = true;
};
networking.hostName = "thor";
# Set your time zone.
time.timeZone = "Europe/Amsterdam";
networking.useDHCP = false;
networking.interfaces.enp9s0.useDHCP = true;
sound.enable = true;
hardware.pulseaudio.enable = true;
# Define a user account. Don't forget to set a password with passwd.
users.users."riley" = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable sudo for the user.
};
environment.systemPackages = with pkgs; [
# Some utils
wget
curl
git
# Modern coreutils
ripgrep
bottom
skim
exa
bat
lf
fd
];
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. Its perfectly fine and recommended to leave
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
system.stateVersion = "21.11"; # Did you read the comment?
};
}

View file

@ -1,45 +0,0 @@
{ lib, pkgs, ... }:
let kakrc = pkgs.writeTextFile (rec {
name = "kakrc.kak";
destination = "/share/kak/autoload/${name}";
text = ''
add-highlighter global/ number-lines -separator ' ' -hlcursor
set-option global tabstop 4
set global ui_options ncurses_assistant=cat
map global normal <a-tab> :buffer-next<ret>
eval %sh{ kak-lsp --kakoune -s $kak_session }
'';
});
theme = let x = (import ./colors.nix)."dark"; in pkgs.writeTextFile (rec {
name = "theme.kak";
destination = "/share/kak/autoload/${name}";
text = ''
face global LineNumbers rgb:${x.background.slight}
face global BufferPadding rgb:${x.background.slight}
face global LineNumberCursor rgb:${x.foreground.primary}
face global crosshairs_line "default,rgb:${x.background.normal}"
face global MenuForeground "default,blue"
face global MenuBackground "default,rgb:313131"
face global InlayHint rgb:828282
face global comment rgb:${x.background.slight}
'';
});
in {
environment.systemPackages = with pkgs; [
(pkgs.kakoune.override {
plugins = with kakounePlugins; [
# Custom config
kakrc
theme
# Kakoune language server support
kak-lsp
];
})
rnix-lsp
];
}

View file

@ -0,0 +1,18 @@
{ config, lib, pkgs, ... }:
{
imports = [
./hardware-configuration.nix
../../modules
];
riley = {
ide = true;
gui = true;
};
networking = {
hostName = "thor";
interfaces.enp9s0.useDHCP = true;
};
}

45
modules/alacritty.nix Normal file
View file

@ -0,0 +1,45 @@
{ pkgs, config, ... }:
{
home-manager.users."riley" = {
programs.alacritty = {
enable = true;
settings = {
window.padding = { x = 8; y = 8; };
font = {
normal = { family = "Fira Code"; style = "Regular"; };
bold = { family = "Fira Code"; style = "Medium"; };
};
colors = with (import ../colors.nix)."dark".hex; {
primary = {
background = background.primary;
foreground = foreground.primary;
};
normal = {
red = red.normal;
green = green.normal;
blue = blue.normal;
magenta = purple.normal;
yellow = yellow.normal;
cyan = cyan.normal;
};
bright = {
red = red.bright;
green = green.bright;
blue = blue.bright;
magenta = purple.bright;
yellow = yellow.bright;
cyan = cyan.bright;
};
};
};
};
};
}

90
modules/default.nix Normal file
View file

@ -0,0 +1,90 @@
# Global config
{ config, lib, pkgs, ... }:
{
options.riley = with lib; {
ide = mkOption {
type = types.bool;
description = ''
Enable IDE-like plugins such as language servers for Rust, Haskell and
Nix in the editor, and configure accordingly.
'';
default = true;
};
gui = mkOption {
type = types.bool;
description = ''
Enables GUI applications, a display server, audio server and related services.
'';
default = true;
};
};
imports = [
<home-manager/nixos>
./kakoune
./display
./alacritty.nix
./fonts.nix
./git.nix
];
config = {
environment.systemPackages = with pkgs; [
# Web utils
wget
curl
git
# Coreutils
ripgrep
bottom
skim
exa
bat
lf
fd
];
boot = {
loader.systemd-boot = {
enable = true;
editor = false;
configurationLimit = 10;
};
loader.efi = {
canTouchEfiVariables = true;
};
cleanTmpDir = true;
};
networking = {
firewall.enable = false;
useDHCP = false;
};
nixpkgs.config.allowUnfree = true;
users.users."riley" = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable sudo for the user.
};
};
}

View file

@ -1,7 +1,6 @@
{ pkgs, config, lib, ... }:
let theme = (import ./colors.nix)."dark";
hex = (c: "#${c}");
let theme = (import ../../colors.nix)."dark".hex;
# Keybinds that launch an application.
launchers = ({ browser }: mod: {
@ -156,15 +155,15 @@ let theme = (import ./colors.nix)."dark";
colors = {
focused = rec {
background = hex (theme.background.normal);
text = hex (theme."red".bright);
background = theme.background.normal;
text = theme."red".bright;
border = background;
childBorder = border;
indicator = border;
};
unfocused = rec {
background = hex (theme.background.normal);
text = hex (theme.foreground.slight);
background = theme.background.normal;
text = theme.foreground.slight;
border = background;
childBorder = border;
indicator = border;

View file

@ -0,0 +1,19 @@
# Haskell text faces and other stuff related to syntax highlighting
# for Haskell in Kakoune, because I prefer different color arrangements
# per language.
{ theme, pkgs, ... }: pkgs.writeTextFile (rec {
name = "common.kak";
destination = "/share/kak/colors/${name}";
text = with theme; ''
face global value rgb:${yellow.bright}
face global string rgb:${green.normal}
face global variable +a
face global module rgb:${green.normal}
face global operator rgb:${cyan.bright}
face global type rgb:${yellow.normal}
face global function rgb:${cyan.bright}
face global keyword rgb:${blue.normal}+b
face global builtin +b
'';
})

View file

@ -0,0 +1,8 @@
# Import syntax themes
{ lib, theme, pkgs, ... }: [
(import ./haskell.nix { inherit lib theme pkgs; })
(import ./rust.nix { inherit lib theme pkgs; })
(import ./nix.nix { inherit lib theme pkgs; })
(import ./common.nix { inherit lib theme pkgs; })
]

View file

@ -0,0 +1,21 @@
# Haskell text faces and other stuff related to syntax highlighting
# for Haskell in Kakoune, because I prefer different color arrangements
# per language.
{ theme, pkgs, ... }: pkgs.writeTextFile (rec {
name = "haskell.kak";
destination = "/share/kak/colors/${name}";
text = with theme; ''
face global value rgb:${green.bright}
face global string rgb:${green.bright}
face global variable +b
face global module rgb:${green.normal}
face global meta rgb:${misc.lime}
face global operator rgb:${cyan.bright}
face global type rgb:${yellow.normal}
face global function rgb:${cyan.bright}
face global attribute rgb:${blue.normal}
face global keyword rgb:${blue.normal}
face global builtin +b
'';
})

View file

@ -0,0 +1,19 @@
# Haskell text faces and other stuff related to syntax highlighting
# for Haskell in Kakoune, because I prefer different color arrangements
# per language.
{ theme, pkgs, ... }: pkgs.writeTextFile (rec {
name = "nix.kak";
destination = "/share/kak/colors/${name}";
text = with theme; ''
add-highlighter buffer/ regex '\b\s*(=)' 1:operator
face global string rgb:${green.normal}
face global operator rgb:${yellow.bright}+b
face global keyword rgb:${blue.normal}+b
face global meta rgb:${purple.bright}
face global builtin rgb:${blue.bright}+b
'';
})

View file

@ -0,0 +1,44 @@
# Haskell text faces and other stuff related to syntax highlighting
# for Haskell in Kakoune, because I prefer different color arrangements
# per language.
{ theme, pkgs, ... }: pkgs.writeTextFile (rec {
name = "rust.kak";
destination = "/share/kak/colors/${name}";
text = with theme; ''
# Types
face global variant rgb:${green.bright}+b
face global enum rgb:${green.bright}+b
face global struct rgb:${red.pastel}+b
face global alias rgb:${orange.normal}+b
face global primitive rgb:${misc.teal}+b
face global trait rgb:${purple.bright}+b
face global union rgb:${misc.lime}+b
# Other Rust-specific syntax elements
face global lifetime rgb:${cyan.bright}
face global format rgb:${orange.bright}+b
face global macro rgb:fc4cbf+b
# Keywords
face global keyword rgb:${blue.normal}
# Literals
face global literal rgb:${yellow.bright}
face global string rgb:${yellow.bright}
# Items
face global function rgb:${green.normal}
face global method function
face global module rgb:${misc.blueGrey}
# Other stuff
face global attribute comment
face global variable rgb:${foreground.normal}
face global property rgb:${misc.lime}
face global operator rgb:${yellow.normal}
face global punctuation rgb:${foreground.normal}
'';
})

213
modules/kakoune/default.nix Normal file
View file

@ -0,0 +1,213 @@
{ lib, pkgs, config, ... }:
let kakrc = pkgs.writeTextFile (rec {
name = "kakrc.kak";
destination = "/share/kak/autoload/${name}";
text = with (import ../../colors.nix)."dark"; ''
# Line numbering
add-highlighter global/ number-lines -separator ' ' -hlcursor
# Setting the tabstop to 4 (even though I have an ultrawide monitor)
set-option global tabstop 4
set global ui_options ncurses_assistant=cat
# Use Alt-Tab to switch between open buffers
map global insert <a-tab> <esc>:buffer-next<ret>
map global normal <a-tab> :buffer-next<ret>
colorscheme common
face global LineNumbers rgb:${background.slight}
face global BufferPadding rgb:${background.slight}
face global LineNumberCursor rgb:${foreground.primary}
face global crosshairs_line "default,rgb:${background.normal}"
face global MenuForeground "default,blue"
face global MenuBackground "default,rgb:313131"
face global InlayHint rgb:828282
face global comment rgb:${foreground.slight}
'' + (lib.optionalString (config.riley.ide) ''
eval %sh{ kak-lsp --kakoune -s $kak_session }
hook global -group yeet ModuleLoaded rust %{
# Override the Rust highlighting with semantic
# tokens supplied by the LSP client
remove-hooks global rust-highlight
remove-highlighter shared/rust
# Request tokens
lsp-semantic-tokens
# Self-destruct this hook (it should only run once)
remove-hooks global yeet
}
# Load language-specific color schemes
hook global WinSetOption filetype=(haskell) %{
colorscheme haskell
lsp-enable-window
lsp-inlay-diagnostics-enable global
map global <tab> ': lsp-code-actions<ret>'
map global <ret> ': lsp-hover<ret>'
}
hook global WinSetOption filetype=(rust) %{
lsp-enable-window
lsp-inlay-diagnostics-enable window
colorscheme rust
hook window -group semtok BufReload .* lsp-semantic-tokens
hook window -group semtok NormalIdle .* lsp-semantic-tokens
hook window -group semtok InsertIdle .* lsp-semantic-tokens
hook -once -always window WinSetOption filetype=.* %{
remove-hooks window semtok
}
hook window ModeChange .*:.*:insert %{
remove-highlighter window/lsp_diagnostics
}
hook window ModeChange .*:insert:normal %{
lsp-inlay-diagnostics-enable window
}
set global lsp_inlay_diagnostic_sign '>'
map global normal <tab> ': lsp-code-actions<ret>'
map global normal <ret> ': lsp-hover<ret>'
}
hook global WinSetOption filetype=(nix) %{
colorscheme nix
lsp-enable-window
}
face global InlayDiagnosticWarning rgb:a39e31+f
face global InlayDiagnosticError rgb:ad494f+f
face global InlayDiagnosticHint rgb:4d965a+f
'');
});
# Syntax colors
colors = (import ./colors {
theme = (import ../../colors.nix)."dark";
inherit lib pkgs;
});
# Config for kak-lsp
kak-lsp-config = pkgs.writeTextFile (rec {
name = "kak-lsp.toml";
destination = "/share/kak-lsp/${name}";
text = let semTok = (name: value: ''
[[semantic_tokens]]
token = "${name}"
face = "${value}"
''); in ''
[language.rust]
filetypes = [ "rust" ]
roots = [ "Cargo.toml" ]
command = "rust-analyzer"
[language.rust.settings.rust-analyzer]
semanticTokens = true
diagnostics.enabled = [ "unresolved-proc-macro" ]
cargo.loadOutDirsFromCheck = true
procMacro.enable = false
[language.haskell]
filetypes = [ "haskell" ]
roots = [ "Setup.hs", "stack.yaml", "*.cabal" ]
command = "haskell-language-server-wrapper"
args = [ "--lsp" ]
[language.nix]
filetypes = [ "nix" ]
roots = [ "flake.nix", "shell.nix", ".git", ".hg" ]
command = "rnix-lsp"
${lib.concatStringsSep "\n" (lib.mapAttrsToList semTok {
"enumMember" = "variant";
"enum" = "enum";
"union" = "union";
"struct" = "struct";
"typeAlias" = "alias";
"builtinType" = "primitive";
"trait" = "trait";
"interface" = "trait";
"method" = "method";
"function" = "function";
"namespace" = "module";
"boolean" = "literal";
"character" = "literal";
"number" = "literal";
"string" = "string";
"keyword" = "keyword";
"documentation" = "comment";
"comment" = "comment";
"escapeSequence" = "format";
"formatSpecifier" = "format";
"operator" = "operator";
"arithmetic" = "operator";
"bitwise" = "operator";
"comparison" = "operator";
"logical" = "operator";
"macro" = "macro";
"lifetime" = "lifetime";
"variable" = "variable";
"attribute" = "attribute";
"punctuation" = "punctuation";
}) }
'';
});
in {
environment.systemPackages = with pkgs; [
(pkgs.kakoune.override {
plugins = with kakounePlugins; [
# Custom config
kakrc
# Kakoune language server support
(symlinkJoin {
paths = [
# The language server client
kak-lsp
# Include default language servers
rnix-lsp
haskell-language-server
# Overwrite kak-lsp.toml
kak-lsp-config
];
name = "kak-lsp-${kak-lsp.version}";
nativeBuildInputs = [ makeWrapper ];
postBuild = ''
wrapProgram $out/bin/kak-lsp --add-flags "--config $out/share/kak-lsp/kak-lsp.toml"
'';
})
] ++ colors;
})
];
}