nixr: nix repl that loads .repl.nix
parent
e4ae633a1d
commit
331183b182
|
@ -0,0 +1,5 @@
|
|||
# usage: `nix repl --file .repl.nix`
|
||||
rec {
|
||||
pkgs = import <nixpkgs> {};
|
||||
inherit (pkgs) lib;
|
||||
}
|
|
@ -223,15 +223,18 @@ do -- selective concealing/ligature {{{
|
|||
|
||||
local group_handler = {
|
||||
[g_docs] = function(_ft, _group)
|
||||
vim.notify("group_handler: " .. vim.inspect({ _ft, _group }))
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
vim.notify("group_handler: " .. vim.inspect({ buf, _ft, _group }))
|
||||
vim.opt_local.concealcursor = "n"
|
||||
-- HACK: seems to be some lifetime racing issues here
|
||||
-- Putting this inside `vim.schedule` puts this at the end of the
|
||||
-- queue, so under the assumption that aucommands are done in an
|
||||
-- event loop, we're sure that the current augroup invocation
|
||||
-- would be done before syn is set
|
||||
-- would be done before syn is set.
|
||||
-- The important part is we're strictly setting this in the
|
||||
-- correct bufnr
|
||||
vim.schedule(function()
|
||||
vim.opt_local.syn = "tex"
|
||||
vim.api.nvim_set_option_value('syntax', 'tex', { buf = buf })
|
||||
end)
|
||||
end
|
||||
}
|
||||
|
|
|
@ -1,136 +0,0 @@
|
|||
# Configurations for shell stuffs.
|
||||
# Should probably be decoupled even more for each feature
|
||||
{
|
||||
config,
|
||||
proj_root,
|
||||
myLib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
cfg = config.base.shells;
|
||||
in {
|
||||
options.base.shells = {
|
||||
enable = myLib.mkOption {
|
||||
type = myLib.types.bool;
|
||||
description = "Enable umbrella shell configuration";
|
||||
default = true;
|
||||
example = false;
|
||||
};
|
||||
# TODO: Support shell-specific init
|
||||
shellInitExtra = myLib.mkOption {
|
||||
type = myLib.types.str;
|
||||
description = "Extra shell init. The syntax should be sh-compliant";
|
||||
default = "";
|
||||
example = ''
|
||||
# X11 support for WSL
|
||||
export DISPLAY=$(ip route list default | awk '{print $3}'):0
|
||||
export LIBGL_ALWAYS_INDIRECT=1
|
||||
'';
|
||||
};
|
||||
shellAliases = myLib.mkOption {
|
||||
type = myLib.types.attrs;
|
||||
description = "Shell command aliases";
|
||||
default = {};
|
||||
example = {
|
||||
nixGL = "nixGLIntel";
|
||||
};
|
||||
};
|
||||
};
|
||||
config = myLib.mkIf cfg.enable {
|
||||
# nix: Propagates the environment with packages and vars when enter (children of)
|
||||
# a directory with shell.nix-compatible and .envrc
|
||||
programs.direnv = {
|
||||
enable = true;
|
||||
nix-direnv.enable = true;
|
||||
# nix-direnv.enableFlakes = true; # must remove. this will always be supported.
|
||||
};
|
||||
# z <path> as smarter cd
|
||||
programs.zoxide = {
|
||||
enable = true;
|
||||
enableZshIntegration = true;
|
||||
};
|
||||
programs.tmux = {
|
||||
enable = true;
|
||||
# extraConfigBeforePlugin = builtins.readFile "${proj_root.config.path}/tmux/tmux.conf";
|
||||
plugins = let inherit (pkgs.tmuxPlugins) cpu net-speed; in [cpu net-speed];
|
||||
extraConfig = builtins.readFile "${proj_root.config.path}/tmux/tmux.conf";
|
||||
};
|
||||
xdg.configFile."tmux/tmux.conf".text = myLib.mkOrder 600 ''
|
||||
set -g status-right '#{cpu_bg_color} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M '
|
||||
'';
|
||||
# Colored ls
|
||||
programs.exa = {
|
||||
enable = true;
|
||||
enableAliases = true;
|
||||
};
|
||||
# Make the shell look beautiful
|
||||
programs.starship = {
|
||||
enable = true;
|
||||
enableZshIntegration = true;
|
||||
settings = let
|
||||
native = builtins.fromTOML (builtins.readFile "${proj_root.config.path}/starship/starship.toml");
|
||||
patch-nix = pkgs.lib.recursiveUpdate native {
|
||||
# WARNING: home-manager fails on here for some reason. Likely not at the
|
||||
# validation phase (type-checking), but at evaluation phaase (stringify)
|
||||
# c.commands = [
|
||||
# ["nix" "run" "nixpkgs#clang" "--" "--version"]
|
||||
# ["nix" "run" "nixpkgs#gcc" "--" "--version"]
|
||||
# ];
|
||||
c.commands = "fuk";
|
||||
};
|
||||
in
|
||||
patch-nix;
|
||||
};
|
||||
# Fuzzy finder. `fzf` for TUI, `fzf -f '<fuzzy query>'` for UNIX piping
|
||||
programs.fzf.enable = true;
|
||||
programs.bash = {
|
||||
enable = true;
|
||||
enableCompletion = true;
|
||||
initExtra = cfg.shellInitExtra or "";
|
||||
};
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
enableCompletion = true;
|
||||
enableAutosuggestions = true;
|
||||
shellAliases =
|
||||
{
|
||||
nix-rebuild = "sudo nixos-rebuild switch";
|
||||
hm-switch = "home-manager switch --flake";
|
||||
hm-switch-u = "home-manager switch --flake .#$${USER}";
|
||||
}
|
||||
// (cfg.shellAliases or {});
|
||||
history = {
|
||||
size = 10000;
|
||||
path = "${config.xdg.dataHome}/zsh/history";
|
||||
};
|
||||
oh-my-zsh = {
|
||||
enable = true;
|
||||
plugins = [
|
||||
"git" # git command aliases: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git#aliases
|
||||
# "sudo" # double-escape to prepend sudo # UPDATE: just use vi-mode lol
|
||||
"command-not-found" # suggests which package to install; does not support nixos (we have solution already)
|
||||
"gitignore" # `gi list` -> `gi java >>.gitignore`
|
||||
"ripgrep" # adds completion for `rg`
|
||||
"rust" # compe for rustc/cargo
|
||||
"poetry" # compe for poetry - Python's cargo
|
||||
# "vi-mode" # edit promps with vi motions :)
|
||||
];
|
||||
};
|
||||
sessionVariables = {
|
||||
# Vim mode on the terminal
|
||||
|
||||
# VI_MODE_RESET_PROMPT_ON_MODE_CHANGE = true;
|
||||
# VI_MODE_SET_CURSOR = true;
|
||||
# ZVM_VI_ESCAPE_BINDKEY = "";
|
||||
ZVM_READKEY_ENGINE = "$ZVM_READKEY_ENGINE_NEX";
|
||||
ZVM_KEYTIMEOUT = 0.004; # 40ms, or subtly around 25 FPS. I'm a gamer :)
|
||||
ZVM_ESCAPE_KEYTIMEOUT = 0.004; # 40ms, or subtly around 25 FPS. I'm a gamer :)
|
||||
};
|
||||
initExtra =
|
||||
(cfg.shellInitExtra or "")
|
||||
+ ''
|
||||
source ${pkgs.zsh-vi-mode}/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
|
@ -30,11 +30,7 @@
|
|||
{config.programs.home-manager.enable = true;}
|
||||
# home-profiles.nix-index
|
||||
home-profiles.neovim
|
||||
{
|
||||
config.repo.shells.shellAliases = {
|
||||
nixr = "if [ -f $(pwd)/.nix-replrc ]; then nix repl $(pwd)/.nix-replrc; elif [ -f ~/.config/.nix-replrc ]; then nix repl ~/.config/.nix-replrc; else nix repl; fi";
|
||||
};
|
||||
}
|
||||
{home.packages = [cell.packages.nixr];}
|
||||
];
|
||||
in {
|
||||
homeConfigurations.htran = home-config {
|
||||
|
|
|
@ -69,14 +69,6 @@ in {
|
|||
settings = let
|
||||
native = builtins.fromTOML (builtins.readFile "${inputs.self}/native_configs/starship/starship.toml");
|
||||
patch-nix = pkgs.lib.recursiveUpdate native {
|
||||
# WARNING: home-manager fails on here for some reason. Likely not at the
|
||||
# validation phase (type-checking), but at evaluation phaase (stringify)
|
||||
# I'm thinking when `settings` are evaluated, it has some sort of
|
||||
# recursive processing before it gets turned into a toml
|
||||
# c.commands = [
|
||||
# ["nix" "run" "nixpkgs#clang" "--" "--version"]
|
||||
# ["nix" "run" "nixpkgs#gcc" "--" "--version"]
|
||||
# ];
|
||||
c.disabled = true;
|
||||
};
|
||||
in
|
||||
|
@ -112,12 +104,10 @@ in {
|
|||
"git" # git command aliases: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git#aliases
|
||||
# DEPRECATION: potentially smelly plugin with nix
|
||||
# "command-not-found" # suggests which package to install; does not support nixos (we have solution already)
|
||||
|
||||
# DEPRECATION: 0 usage, mostly because I don't have a use for it
|
||||
# "gitignore" # `gi list` -> `gi java >>.gitignore`
|
||||
"ripgrep" # adds completion for `rg`
|
||||
"rust" # compe for rustc/cargo
|
||||
"poetry" # compe for poetry - Python's cargo
|
||||
# "gitignore", allows gi CLI interaction
|
||||
"ripgrep" # adds completion for ripgrep
|
||||
"rust"
|
||||
"poetry"
|
||||
];
|
||||
};
|
||||
sessionVariables = {
|
||||
|
|
|
@ -42,6 +42,7 @@ in {
|
|||
|
||||
nil = inputs.nixpkgs.nil;
|
||||
|
||||
# These should probably go to dotfiles {{{
|
||||
git-plus = pkgs.symlinkJoin {
|
||||
name = "pegasust-git-plus";
|
||||
paths = [
|
||||
|
@ -79,4 +80,29 @@ in {
|
|||
'')
|
||||
];
|
||||
};
|
||||
|
||||
nixr = pkgs.writeShellScriptBin "nixr" ''
|
||||
rc_path=""
|
||||
|
||||
p0="$(pwd)/.repl.nix"
|
||||
p1=~/.config/.repl.nix
|
||||
if [ -f $p0 ]; then
|
||||
echo "[nixr]: trying $p0"
|
||||
rc_path="$p0"
|
||||
elif [ -f $p1 ]; then
|
||||
echo "[nixr]: trying $p1"
|
||||
rc_path="$p1"
|
||||
fi
|
||||
|
||||
if [ -n "$rc_path" ]; then
|
||||
echo "nix-repl: sourcing from $rc_path; content:"
|
||||
echo '```'
|
||||
cat $rc_path
|
||||
echo '```'
|
||||
nix repl --file "$rc_path"
|
||||
else
|
||||
nix repl
|
||||
fi
|
||||
'';
|
||||
# }}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue