Further work

This commit is contained in:
Bryan Ramos 2023-06-05 12:23:49 -04:00
parent 70da3fe0b5
commit 64235f2775
3 changed files with 278 additions and 118 deletions

View file

@ -43,119 +43,38 @@
programs = {
sway = {
enable = true;
extraPackages = with pkgs; [
rofi-wayland
grim
slurp
wl-clipboard
xdg-utils
fontconfig
qogir-icon-theme
emote
pavucontrol
];
};
xwayland = {
enable = true;
};
bash = {
enable = true;
enableCompletion = true;
enableLsColors = true;
blesh.enable = true;
shellInit = ''
extraPackages = with pkgs; [
rofi-wayland
grim
slurp
wl-clipboard
xdg-utils
fontconfig
qogir-icon-theme
emote
pavucontrol
];
extraSessionCommands = ''
if [ -z "$DISPLAY" ] && [ "$(tty)" = "/dev/tty1" ]; then
exec sway
fi
if [ "$XDG_CURRENT_DESKTOP" = "sway" ] ; then
# https://github.com/swaywm/sway/issues/595
export _JAVA_AWT_WM_NONREPARENTING=1
fi
export EDITOR=nvim
eval "$(direnv hook bash)"
'';
promptInit = ''
# Check if the current shell is an SSH session
is_ssh_session() {
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
return 0
else
return 1
fi
}
# PS1 Config
function set_ps1_prompt() {
local git_branch=""
local flake_icon=""
local cur_dir=""
# Check if we're inside a git repository
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
# If we are, get the current branch name
git_branch="$(git symbolic-ref --short HEAD 2>/dev/null)"
# If the command failed, we're in a detached HEAD state, so get the short SHA
if [ $? -ne 0 ]; then
git_branch="$(git rev-parse --short HEAD 2>/dev/null)"
fi
# Wrap the branch name and : in braces and color it red
git_branch=" \[\033[01;31m\]$git_branch󰘬:\[\033[00m\]"
# Check if flake.nix file exists
if [ -f "$(git rev-parse --show-toplevel)/flake.nix" ]; then
# If it exists, set the flake icon and color it blue
flake_icon="\[\033[01;34m\] \[\033[00m\]"
fi
# Get the root directory of the git repository
git_root="$(basename "$(git rev-parse --show-toplevel)")"
# Get the current directory relative to the Git root
cur_dir=$(realpath --relative-to=$(git rev-parse --show-toplevel) .)
if [ "$cur_dir" == "." ]; then
cur_dir="\[\033[01;34m\] $git_root\[\033[00m\]"
else
cur_dir="\[\033[01;34m\] $git_root/$cur_dir\[\033[00m\]"
fi
else
# If not in a Git repository, just show the normal path
cur_dir="\[\033[01;34m\]\w\[\033[00m\]"
fi
if [ -n "${IN_NIX_SHELL:+x}" ]; then
PS1="$cur_dir\n$flake_icon\[\033[01;32m\]nixShell>$git_branch\[\033[00m\]"
else
if ! is_ssh_session; then
PS1="\n$cur_dir\n$flake_icon\[\033[01;32m\]>$git_branch\[\033[00m\]"
else
PS1="\n\[\033[01;34m\]\w\[\033[00m\]\n\[\033[01;32m\]\u@\h:\[\033[00m\] "
fi
fi
unset flake_icon
}
PROMPT_COMMAND="set_ps1_prompt; $PROMPT_COMMAND"
'';
shellAliases = {
ls = "lsd";
hmup="home-manager switch --flake '$HOME/Documents/projects/nixos#bryan'";
nixup="sudo nixos-rebuild switch --flake '$HOME/Documents/projects/nixos#socrates'";
};
};
xwayland = {
enable = true;
};
xdg.portal.wlr.enable = true;
gnupg = {
agent = {
enable = true;
@ -165,6 +84,18 @@
git.enable = true;
};
services.pipewire = {
enable = true;
audio.enable = true;
wireplumber.enable = true;
pulse.enable = true;
jack.enable = true;
alsa.enable = true;
alsa.support32Bit = true;
};
fonts = {
fonts = with pkgs; [
@ -177,21 +108,7 @@
emojione
];
};
xdg.portal.wlr.enable = true;
services.pipewire = {
enable = true;
audio.enable = true;
wireplumber.enable = true;
pulse.enable = true;
jack.enable = true;
alsa.enable = true;
alsa.support32Bit = true;
};
services = {
trezord.enable = true;

189
modules/bash/default.nix Normal file
View file

@ -0,0 +1,189 @@
{ pkgs, lib, config, ... }:
with lib;
let cfg = config.modules.bash;
in {
options.modules.bash = { enable = mkEnableOption "bash"; };
config = mkIf cfg.enable {
programs.bash = {
enable = true;
enableCompletion = true;
initExtra = ''
eval "$(direnv hook bash)"
is_ssh_session() {
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
return 0
else
return 1
fi
}
function set_ps1_prompt() {
local git_branch=""
local flake_icon=""
local cur_dir=""
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
git_branch="$(git symbolic-ref --short HEAD 2>/dev/null)"
if [ $? -ne 0 ]; then
git_branch="$(git rev-parse --short HEAD 2>/dev/null)"
fi
git_branch=" \[\033[01;31m\]$git_branch󰘬:\[\033[00m\]"
if [ -f "$(git rev-parse --show-toplevel)/flake.nix" ]; then
# If it exists, set the flake icon and color it blue
flake_icon="\[\033[01;34m\] \[\033[00m\]"
fi
git_root="$(basename "$(git rev-parse --show-toplevel)")"
cur_dir=$(realpath --relative-to=$(git rev-parse --show-toplevel) .)
if [ "$cur_dir" == "." ]; then
cur_dir="\[\033[01;34m\] $git_root\[\033[00m\]"
else
cur_dir="\[\033[01;34m\] $git_root/$cur_dir\[\033[00m\]"
fi
else
cur_dir="\[\033[01;34m\]\w\[\033[00m\]"
fi
if [ -n "${IN_NIX_SHELL:+x}" ]; then
PS1="$cur_dir\n$flake_icon\[\033[01;32m\]nixShell>$git_branch\[\033[00m\]"
else
if ! is_ssh_session; then
PS1="\n$cur_dir\n$flake_icon\[\033[01;32m\]>$git_branch\[\033[00m\]"
else
PS1="\n\[\033[01;34m\]\w\[\033[00m\]\n\[\033[01;32m\]\u@\h:\[\033[00m\] "
fi
fi
unset flake_icon
}
PROMPT_COMMAND="set_ps1_prompt; $PROMPT_COMMAND"
function cdg() {
if [[ $1 == "--help" ]]; then
echo "A simple utility for navigating to the root of a git repo"
return 0
fi
# Check for invalid command
if [[ -n "$1" ]]; then
echo "Invalid command: $1. Try 'cdg --help'."
return 1
fi
local root_dir
root_dir=$(git rev-parse --show-toplevel 2>/dev/null)
local git_status=$?
if [ $git_status -ne 0 ]; then
echo "Error: Not a git repo."
return 1
fi
cd "$root_dir"
}
function ldv() {
if [[ $1 == "help" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
cat << EOF
ldv
A simple utility for setting up development environments effortlessly.
Commands:
ldv Start a preconfigured nix shell.
init Create a new dev template in the current working directory.
help Show available commands and options.
Contributions welcome: https://github.com/itme-brain/ldv
EOF
elif [[ $1 == "init" ]] || [[ $1 == "-i" ]] || [[ $1 == "--init" ]]; then
if [[ -e ./shell.nix ]] || [[ -e ./.envrc ]]; then
cat << EOF
Existing environment found.
Initialization cancelled.
EOF
return
fi
cat << EOF
Initializing a new environment...
Select an environment:
1. Web
2. Elixir
3. Haskell
EOF
read -p "Enter the number of your choice: " choice
case $choice in
1)
wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/shells/web.nix -O shell.nix
wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/flake -O flake.nix
wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/envrc -O .envrc
direnv allow
;;
2)
wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/shells/elixir.nix -O shell.nix
wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/flake -O flake.nix
wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/envrc -O .envrc
direnv allow
;;
3)
wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/shells/haskell.nix -O shell.nix
wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/flake -O flake.nix
wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/envrc -O .envrc
direnv allow
;;
*)
echo "Invalid choice."
;;
esac
elif [[ -z $1 ]]; then
cat << EOF
Select an environment:
1. Web
2. Elixir
3. Haskell
EOF
read -p "Enter the number of your choice: " choice
case $choice in
1)
(nix develop github:itme-brain/ldv#web)
;;
2)
(nix develop github:itme-brain/ldv#elixir)
;;
3)
(nix develop github:itme-brain/ldv#haskell)
;;
# Add more cases here...
*)
echo "Invalid choice."
;;
esac
else
echo "Error: Invalid command. Try 'ldv --help'"
fi
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
ldv "$@"
fi
'';
shellAliases = {
ls = "lsd";
hmup = "home-manager switch --flake '$HOME/Documents/projects/nixos#bryan'";
nixup = "sudo nixos-rebuild switch --flake '$HOME/Documents/projects/nixos#socrates'";
};
};
};
}

View file

@ -15,16 +15,70 @@ let cfg = config.modules.neovim;
in {
options.modules.neovim = { enable = mkEnableOption "neovim"; };
config = mkIf cfg.enable {
home.file.".config/nvim" = {
source = ./nvim;
recursive = true;
};
programs.neovim = {
enable = true;
viAlias = true;
vimAlias = true;
plugins = with pkgs.vimPlugins; [
{
plugin = github-theme;
config = ''
lua << EOF
vim.cmd('colorscheme github_dark_high_contrast')
EOF
'';
}
lazygit.nvim
{
plugin = LazyVim;
config = ''
lua << EOF
return {
{'williamboman/mason.nvim', enabled = false },
{'nvim-treesitter/nvim-treesitter', enabled = false },
}
EOF
'';
}
{
plugin = lsp-zero-nvim;
config = ''
lua << EOF
branch = 'v2.x'
requires = {
{'neovim/nvim-lspconfig'},
{'hrsh7th/nvim-cmp'},
{'hrsh7th/cmp-nvim-lsp'},
{'L3MON4D3/LuaSnip'},
}
'';
}
{
plugin = nvim-treesitter.withAllGrammars
config = ''
lua << EOF
EOF
'';
}
];
};
home.packages = with pkgs; [
nil nixfmt
sumneko-lua-language-server stylua
haskell-language-server hlint
];
};
};
}