nixos-config/home/rachel.nix

697 lines
20 KiB
Nix
Raw Normal View History

2024-03-05 20:44:17 +01:00
{ pkgs, cornelis, cornelis-vim, agda, slippi-netplay, ... }:
2023-07-31 14:18:02 +02:00
let username = "rachel";
homeDir = "/home/${username}";
2023-11-18 23:30:05 +01:00
SAX2NF = import ../shared/sax2nf.nix { inherit pkgs; };
2023-10-15 13:10:57 +02:00
hpkgs = pkgs.haskellPackages;
hls_wrapper = pkgs.writeScript "hls" ''
export PATH="${hpkgs.haskell-language-server}/bin:$PATH"
exec ${hpkgs.haskell-language-server}/bin/haskell-language-server-wrapper "$@"
'';
2023-12-01 20:46:27 +01:00
rzk = hpkgs.rzk;
2024-03-12 10:42:17 +01:00
vol = pkgs.writeScript "vol" (builtins.readFile ./vol.sh);
light = pkgs.writeScript "light" (builtins.readFile ./light.sh);
in rec {
2023-07-31 14:18:02 +02:00
home = {
username = username;
homeDirectory = homeDir;
packages = with pkgs; [
unzip
zip
xz
gzip
bzip2
p7zip
usbutils
pciutils
nettools
nmap
arp-scan
2023-09-12 21:28:31 +02:00
julia-bin
2023-11-06 16:11:24 +01:00
(python3.withPackages (ps: with ps; [
ipython
matplotlib
numpy
scipy
]))
2023-10-15 13:10:57 +02:00
hpkgs.ghc
2023-07-31 14:18:02 +02:00
firefox
gnupg
agda
discord
dig
xxd
zoom-us
slack
imagemagick
ffmpeg
sl
cowsay
lolcat
fortune
banner
yt-dlp
libreoffice
protonmail-bridge
pass
2023-12-09 23:18:30 +01:00
protonvpn-cli_2
2023-07-31 14:18:02 +02:00
thunderbird
tidal-hifi
signal-desktop
transmission-gtk
xclip
clinfo
glxinfo
vulkan-tools
obs-studio
file
gimp
2023-11-18 23:30:05 +01:00
SAX2NF
2023-07-31 14:18:02 +02:00
twemoji-color-font
bat
steam
steam-run
2023-08-13 10:57:39 +02:00
rmapi
2023-08-19 22:19:49 +02:00
lutris
2023-09-25 12:10:43 +02:00
texlive.combined.scheme-full
2023-10-12 23:24:36 +02:00
cornelis
2023-10-24 20:06:09 +02:00
zulip
2023-11-06 16:11:24 +01:00
rink
2023-11-06 16:15:34 +01:00
sage
2023-11-10 14:44:02 +01:00
typst
2023-11-11 00:03:41 +01:00
ttyper
2023-11-11 22:18:59 +01:00
idris2
2023-11-26 11:31:59 +01:00
prismlauncher
2023-11-27 20:56:28 +01:00
vimv
2023-12-01 20:46:27 +01:00
rzk
2024-01-03 17:22:32 +01:00
whalebird
2024-01-20 20:43:40 +01:00
lean4
2024-03-05 20:44:17 +01:00
slippi-netplay
2024-03-09 20:27:49 +01:00
xwallpaper
2024-03-12 10:42:17 +01:00
blueberry
pulseaudio
brightnessctl
maim
2023-07-31 14:18:02 +02:00
];
2024-03-09 20:27:49 +01:00
file.".config/berry/autostart" = {
source = ./berry_config;
};
2024-03-12 14:42:43 +01:00
file.".config/polybar/scripts/polywin.sh" = {
source = pkgs.writeScript "polywin.sh" ''
PATH="$PATH:${pkgs.lib.makeBinPath [
pkgs.wmctrl
pkgs.gawk
pkgs.coreutils-full
]}"
2024-03-12 14:56:28 +01:00
current_display=$(wmctrl -d 2>/dev/null |awk '/*/ {print $1}')
2024-03-12 14:42:43 +01:00
2024-03-12 14:52:40 +01:00
out=$(
2024-03-12 14:56:28 +01:00
wmctrl -lx 2>/dev/null |
2024-03-12 14:42:43 +01:00
awk -v current_display="$current_display" '{
if ($2==current_display) {
split($3,window_title,".")
printf "%s ", "["tolower(window_title[2])"]"
}
}'
2024-03-12 14:52:40 +01:00
)
# workaround for clearing on empty output
printf '%s\n' "$out"
2024-03-12 14:42:43 +01:00
'';
executable = true;
};
2023-12-01 17:00:30 +01:00
stateVersion = "23.11";
2023-07-31 14:18:02 +02:00
};
xdg.userDirs = {
enable = true;
createDirectories = true;
desktop = "${homeDir}";
documents = "${homeDir}/doc";
download = "${homeDir}/dwn";
music = "${homeDir}/music";
pictures = "${homeDir}/img";
publicShare = "${homeDir}/srv";
templates = "${homeDir}/doc/templates";
videos = "${homeDir}/vid";
};
programs = {
bash = {
enable = true;
2023-12-14 15:44:54 +01:00
enableCompletion = false;
2023-07-31 14:18:02 +02:00
historyFile = "/dev/null";
sessionVariables = {
PS1 ="\\033[1m\\u\\033[0m@\\033[1m\\h\\033[0m: \\w\nλ ";
BROWSER = "firefox";
XINITRC = "${homeDir}/bin/xinitrc";
XAUTHORITY = "${homeDir}/.local/share/Xauthority";
PASH_KEYID = "3E4A909C8FEF6E3783699C79DFC26EF8EDAD6D71";
QT_AUTO_SCREEN_FACTOR = 1;
PATH = "${homeDir}/bin:$PATH";
};
shellAliases = {
x = "startx";
rm = "rm -i";
cal = "cal -m";
};
initExtra = ''
source ~/.profile
set -o vi
2024-03-18 15:59:56 +01:00
norm_name() {
ret="$1"
[ "$ret" = "''${ret#*\#}" ] && ret="nixpkgs#$ret"
printf '%s\n' "$ret"
}
run() {
prog="$1"
shift
nix run "$(norm_name $prog)" "$@"
}
shell() {
i=0
while [ $i -lt $# ]; do
prog="$1"
shift
set -- "$@" "$(norm_name $prog)"
: $(( i++ ))
done
nix shell "$@"
}
2023-07-31 14:18:02 +02:00
'';
};
2023-08-25 14:40:08 +02:00
mpv = {
enable = true;
config = {
hwdec = "auto-safe";
vo = "gpu";
profile = "gpu-hq";
};
};
2023-09-01 15:21:19 +02:00
rofi = {
enable = true;
2023-11-18 23:30:53 +01:00
theme = "gruvbox-dark-soft";
2023-09-01 15:21:19 +02:00
};
2023-07-31 14:18:02 +02:00
git = {
enable = true;
userName = "Rachel Lambda Samuelsson";
userEmail = "depsterr@protonmail.com";
extraConfig = {
init.defaultBranch = "master";
};
};
neovim = {
defaultEditor = true;
enable = true;
vimAlias = true;
extraLuaConfig = ''
2023-11-11 22:31:07 +01:00
require('tmux').setup({ copy_sync = { redirect_to_clipboard = true } });
require('Comment').setup()
2023-11-11 22:31:07 +01:00
require('nvim-surround').setup()
2023-11-27 20:56:28 +01:00
require('numb').setup()
2023-10-15 13:10:57 +02:00
local lspcfg = require('lspconfig')
lspcfg.typst_lsp.setup({
2023-10-18 18:55:59 +02:00
cmd = { '${pkgs.typst-lsp}/bin/typst-lsp' },
2023-10-15 13:10:57 +02:00
})
2023-12-09 23:18:46 +01:00
lspcfg.rust_analyzer.setup({})
2023-10-15 13:10:57 +02:00
lspcfg.hls.setup({
2023-10-18 18:55:59 +02:00
cmd = { '${hls_wrapper}', 'lsp' },
2023-10-15 13:10:57 +02:00
})
lspcfg.pyright.setup({
2023-10-18 18:55:59 +02:00
cmd = { '${pkgs.nodePackages.pyright}/bin/pyright-langserver', '--stdio' },
2023-10-15 13:10:57 +02:00
})
2023-12-01 20:51:43 +01:00
lspcfg.nixd.setup({
cmd = { '${pkgs.nixd}/bin/nixd' },
})
2023-12-01 21:06:12 +01:00
lspcfg.ltex.setup({
cmd = { '${pkgs.ltex-ls}/bin/ltex-ls' },
filetypes = { 'bib', 'gitcommit', 'markdown', 'plaintext', 'tex', 'pandoc', 'typst' },
settings = {
ltex = {
2024-01-24 20:46:51 +01:00
language = 'en-US'
2023-12-01 21:06:12 +01:00
}
}
})
2023-12-19 17:17:18 +01:00
require('orgmode').setup_ts_grammar()
require('nvim-treesitter.configs').setup({
highlight = {
enable = true,
2024-03-14 15:03:28 +01:00
disable = { "c", "lua" },
2023-12-19 17:17:18 +01:00
additional_vim_regex_highlighting = {'org'},
},
})
require('orgmode').setup({})
2024-01-20 20:43:40 +01:00
require('lean').setup({
mappings = true,
2024-01-23 20:32:48 +01:00
})
2024-03-14 15:03:28 +01:00
require('lualine').setup {
options = {
icons_enabled = true,
theme = 'gruvbox',
component_separators = { left = "", right = ""},
section_separators = { left = "", right = ""},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {'mode'},
2024-03-16 16:18:52 +01:00
lualine_b = { {
'diagnostics',
always_visible = true,
on_click = function(n,b,m)
vim.diagnostic.goto_next()
end
} },
2024-03-14 15:03:28 +01:00
lualine_c = {'filename'},
lualine_x = {'encoding', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
}
2023-10-15 13:10:57 +02:00
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
2023-10-18 18:55:59 +02:00
local opts = { buffer = args.buf }
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', '<localleader>r', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<localleader>a', vim.lsp.buf.code_action, opts)
2024-03-16 16:18:52 +01:00
vim.keymap.set('n', '<localleader>gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', '<localleader>gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<localleader>gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<localleader>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<localleader>n', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<localleader>N', vim.diagnostic.goto_prev, opts)
2023-10-18 18:55:59 +02:00
vim.keymap.set('i', '<C-n>', vim.lsp.omnifunc, opts)
2023-10-15 13:10:57 +02:00
end,
})
2023-10-15 21:45:49 +02:00
vim.api.nvim_create_autocmd({ "BufNew"
, "TextChanged"
, "TextChangedI"
, "TextChangedP"
, "TextChangedT"
}, {
callback = function(args)
vim.diagnostic.disable(args.buf)
end
})
vim.api.nvim_create_autocmd({"BufWrite"}, {
callback = function(args)
vim.diagnostic.enable(args.buf)
end
})
2023-12-01 20:46:27 +01:00
vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
pattern = { "*.rzk" },
callback = function(arg)
vim.lsp.start({
name = 'rzk-lsp',
cmd = { "${rzk}/bin/rzk", "lsp" },
root_dir = vim.fs.dirname(vim.fs.find('rzk.yaml', { upward = true })[1]),
})
end
})
'';
extraConfig = ''
set rnu nu
set ts=2 sw=2 expandtab
set clipboard=unnamedplus
2023-10-09 12:09:40 +02:00
set laststatus=3 noshowmode
2023-10-15 13:10:57 +02:00
set signcolumn=no
2023-11-14 23:08:35 +01:00
set linebreak
2023-10-06 12:01:35 +02:00
let g:cornelis_use_global_binary = 1
2023-12-19 17:17:18 +01:00
set conceallevel=2 concealcursor=nc
colorscheme gruvbox
hi Normal guibg=NONE ctermbg=NONE
2023-11-05 10:36:06 +01:00
let maplocalleader="!"
2024-03-05 20:43:23 +01:00
let g:bqn_prefix_key="!"
2023-10-15 13:10:57 +02:00
runtime agda-input.vim
2024-03-05 20:43:23 +01:00
call cornelis#bind_input(" ", "!")
call cornelis#bind_input("exc", "!")
2023-10-15 13:10:57 +02:00
2023-11-05 10:36:06 +01:00
inoremap <C-Space> <Esc>
2023-11-14 23:08:35 +01:00
nnoremap j gj
nnoremap k gk
nnoremap gj j
nnoremap gk k
2023-10-07 14:12:43 +02:00
au BufRead,BufNewFile *.agda call AgdaFiletype()
au BufRead,BufNewFile *.lagda.* call AgdaFiletype()
function! AgdaFiletype()
2023-10-10 21:12:48 +02:00
nnoremap <buffer> <C-c><C-l> :CornelisLoad<CR>
nnoremap <buffer> <C-c><C-r> :CornelisRefine<CR>
nnoremap <buffer> <C-c><C-c> :CornelisMakeCase<CR>
nnoremap <buffer> <C-c>, :CornelisTypeContext<CR>
nnoremap <buffer> <C-c>. :CornelisTypeContextInfer<CR>
2023-10-10 21:12:48 +02:00
nnoremap <buffer> <C-c><C-d> :CornelisTypeInfer<CR>
nnoremap <buffer> <C-c><C-s> :CornelisSolve<CR>
nnoremap <buffer> <C-c><C-a> :CornelisAuto<CR>
nnoremap <buffer> gd :CornelisGoToDefinition<CR>
nnoremap <buffer> <C-c><C-b> :CornelisPrevGoal<CR>
nnoremap <buffer> <C-c><C-f> :CornelisNextGoal<CR>
nnoremap <buffer> <C-c><C-u> :CornelisIgnoreAbstract<CR>
nnoremap <buffer> <C-c><space> :CornelisGive<CR>
2023-10-07 14:12:43 +02:00
endfunction
'';
2024-03-05 20:43:23 +01:00
plugins = let
bqn-vim = pkgs.vimUtils.buildVimPlugin {
name = "bqn-vim";
src = "${pkgs.fetchFromGitHub {
owner = "mlochbaum";
repo = "BQN";
rev = "f4b09b675386c789c8296c96874871916a3abdcf";
hash = "sha256-rvsageS5sYF9QvWuoRutjx5i0ngrfhGvIPRO834pwwM=";
}}/editors/vim";
};
bqn-nvim = pkgs.vimUtils.buildVimPlugin {
name = "bqn-nvim";
src = pkgs.fetchFromSourcehut {
owner = "~detegr";
repo = "nvim-bqn";
rev = "52d8b49f3ebc32d340e2e2b8dba1f6bbd1873b78";
hash = "sha256-5wITedTuUn9BKLqmQtPWeFNOa8dXfPIRpUvPSkNJcas=";
};
};
in
with pkgs.vimPlugins; [
2023-11-11 22:31:07 +01:00
nvim-surround
comment-nvim
vimtex
gruvbox-nvim
tmux-nvim
2023-10-12 23:24:36 +02:00
cornelis-vim
2023-10-15 13:10:57 +02:00
nvim-lspconfig
2023-11-11 22:18:59 +01:00
idris2-vim
2023-11-27 20:56:28 +01:00
numb-nvim
2023-12-01 20:46:43 +01:00
typst-vim
2023-12-19 17:17:18 +01:00
orgmode
(nvim-treesitter.withPlugins (p: with p; [
org
]))
2023-12-25 16:42:36 +01:00
vim-obsession
2024-01-20 20:43:40 +01:00
lean-nvim
2024-03-05 20:43:23 +01:00
bqn-vim
bqn-nvim
2024-03-14 15:03:28 +01:00
lualine-nvim
];
};
tmux = {
enable = true;
clock24 = true;
escapeTime = 0;
keyMode = "vi";
mouse = false;
shortcut = "a";
extraConfig = ''
bind h split -hb -c '#{pane_current_path}'
bind j split -v -c '#{pane_current_path}'
bind k split -vb -c '#{pane_current_path}'
bind l split -h -c '#{pane_current_path}'
is_vim="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?\.?(view|n?vim?x?)(-wrapped)?(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind -n 'M-h' if-shell "$is_vim" 'send-keys M-h' 'resize-pane -L 1'
bind -n 'M-j' if-shell "$is_vim" 'send-keys M-j' 'resize-pane -D 1'
bind -n 'M-k' if-shell "$is_vim" 'send-keys M-k' 'resize-pane -U 1'
bind -n 'M-l' if-shell "$is_vim" 'send-keys M-l' 'resize-pane -R 1'
bind-key -T copy-mode-vi M-h resize-pane -L 1
bind-key -T copy-mode-vi M-j resize-pane -D 1
bind-key -T copy-mode-vi M-k resize-pane -U 1
bind-key -T copy-mode-vi M-l resize-pane -R 1
2023-10-06 10:45:30 +02:00
set -g pane-border-style bg=default
set -g pane-border-style fg="#1D1F21"
set -g pane-active-border-style bg=default
set -g pane-active-border-style fg="#333333"
set-option -g status on
set-option -g status-style bg=default
2023-10-07 14:12:31 +02:00
set-option -g status-style fg="#ef7627"
set-option -g status-interval 2
set-option -g status-justify "centre"
set-option -g status-right " λ "
set -g status-interval 1
set-window-option -g window-status-separator "-"
2023-10-07 14:12:31 +02:00
set-window-option -g window-status-current-format " #[fg=#b55690 bold]!![ #{b:pane_current_path}/ ] #{b:window_index} $ #{b:pane_current_command}!! "
set-window-option -g window-status-format " #{b:window_index} [ #{b:pane_current_path}/ ] #{b:pane_current_command} "
2023-12-25 16:42:36 +01:00
set -g @resurrect-strategy-nvim 'session'
set -g @resurrect-capture-pane-contents 'on'
'';
2023-12-25 16:42:36 +01:00
plugins = with pkgs.tmuxPlugins; [
resurrect
];
};
2023-10-06 12:01:45 +02:00
hyfetch = {
enable = true;
settings = {
preset = "lesbian";
mode = "rgb";
color_align = {
mode = "horizontal";
};
};
};
2023-10-16 23:08:52 +02:00
direnv = {
enable = true;
nix-direnv.enable = true;
};
alacritty = {
enable = true;
settings = {
window = {
padding.x = 5;
padding.y = 5;
decoration = "none";
};
dynamic_title = false;
mouse_hide_when_typing = true;
draw_bold_text_with_bright_colors = false;
scrolling.history = 0;
font = {
2023-11-18 23:30:05 +01:00
normal.family = "SAX2 Nerd Font";
2024-03-09 20:27:49 +01:00
size = 8;
};
2023-10-06 10:45:30 +02:00
colors = {
background = "#1d1f21";
foreground = "#c5c8c6";
};
shell.program =
let tmux-menu = pkgs.writeScript "tmux-menu" ''
s="$(tmux ls 2>/dev/null)"
[ "$s" ] && s="$s
"
c=$(${pkgs.fzf}/bin/fzf -1 <<-EOF
''${s}New Session
Raw Shell
EOF
) || exit
case "$c" in
"New Session")
read -p "Name? " -r n
${pkgs.tmux}/bin/tmux new -s "$n" ;;
"Raw Shell")
2023-10-15 13:10:57 +02:00
${pkgs.bash}/bin/bash --login ;;
*)
${pkgs.tmux}/bin/tmux attach-session -t "''${c%%:*}" ;;
esac
''; in "${tmux-menu}";
};
};
2023-10-18 18:56:29 +02:00
ssh = {
enable = true;
matchBlocks = {
remarkable = {
hostname = "10.11.99.1";
user = "root";
};
lazarus = {
hostname = "rachel.cafe";
user = "deppy";
};
};
};
2024-03-18 15:59:56 +01:00
autorandr = {
enable = true;
hooks.postswitch = {
wall = "xwallpaper --zoom \"$HOME\"/img/wallpaper";
bar = "systemctl restart --user polybar";
};
profiles = {
};
};
2023-07-31 14:18:02 +02:00
};
2023-12-01 22:45:08 +01:00
services = {
gpg-agent = {
enable = true;
pinentryFlavor = "qt";
};
2024-03-09 20:27:49 +01:00
sxhkd = {
enable = true;
2024-03-12 10:42:17 +01:00
package = pkgs.sxhkd;
extraOptions = [ "-m 1" ];
2024-03-09 20:27:49 +01:00
keybindings = {
"super + Return" = "alacritty";
"super + BackSpace" = "firefox";
2024-03-12 10:42:17 +01:00
"super + r" = "rofi -show drun";
2024-03-09 20:27:49 +01:00
"super + p" = "cpypsk";
"super + l" = "betterlockscreen -l";
"super + Left" = "berryc snap_left";
"super + Right" = "berryc snap_right";
"super + m" = "berryc window_monocle";
"super + {1,2,3,4}" = "berryc switch_workspace {0,1,2,3}";
"super + shift + {1,2,3,4}" = "berryc send_to_workspace {0,1,2,3}";
"super + f" = "berryc fullscreen_state";
"alt + Tab" = "berryc cycle_focus";
"~button1" = "berryc pointer_focus";
2024-03-12 14:42:43 +01:00
"~button2" = "berryc pointer_focus";
"~button3" = "berryc pointer_focus";
2024-03-12 10:42:17 +01:00
"~Escape" = "dunstctl close-all";
2024-03-16 16:18:52 +01:00
"Print" = "maim -s ~/img/scrot/$(date +%s).png";
2024-03-12 10:42:17 +01:00
"XF86AudioMute" = "${vol} mute";
"XF86AudioRaiseVolume" = "${vol} +5%";
"XF86AudioLowerVolume" = "${vol} -5%";
"XF86MonBrightnessUp" = "${light} 5%+";
"XF86MonBrightnessDown" = "${light} 5%-";
2024-03-09 20:27:49 +01:00
};
};
polybar = {
enable = true;
config = ./polybar.ini;
script = "polybar bar &";
package = pkgs.polybarFull;
};
picom = {
enable = true;
};
dunst = {
enable = true;
2024-03-12 10:42:17 +01:00
settings = {
volume = {
appname = "changeVolume";
history_ignore = "yes";
};
light = {
appname = "changeLight";
history_ignore = "yes";
};
};
};
2024-03-12 14:42:43 +01:00
redshift = {
enable = true;
latitude = "57.70";
longitude = "11.97";
};
2024-03-12 12:22:46 +01:00
network-manager-applet.enable = true;
2024-03-12 12:41:50 +01:00
blueman-applet.enable = true;
2024-03-12 12:22:46 +01:00
betterlockscreen.enable = true;
gnome-keyring.enable = true;
2024-03-18 15:59:56 +01:00
autorandr.enable = true;
2024-03-12 12:41:50 +01:00
2023-12-01 22:45:08 +01:00
};
2024-03-12 11:59:27 +01:00
2024-03-12 12:20:46 +01:00
xsession = {
enable = true;
initExtra = ''
xwallpaper --zoom "$HOME"/img/wallpaper
'';
scriptPath = "bin/xinitrc";
windowManager.command = "${pkgs.berry}/bin/berry";
};
2024-03-12 11:59:27 +01:00
systemd.user= {
timers = {
battery-check = {
Unit.Description = "Warn at low battery levels";
Timer = {
OnBootSec = "1min";
OnUnitActiveSec = "30s";
Unit = "battery-check.service";
};
2024-03-12 12:20:46 +01:00
Install.WantedBy = [ "graphical-session.target" ];
2024-03-12 11:59:27 +01:00
};
};
services = {
battery-check = {
Unit.Description = "Warn at low battery levels";
2024-03-15 11:59:56 +01:00
Service = let batMon = pkgs.writeShellScript "batMon" ''
2024-03-12 11:59:27 +01:00
PATH="$PATH:${pkgs.lib.makeBinPath [
pkgs.acpi
pkgs.dunst
pkgs.gnugrep
pkgs.gawk
pkgs.systemd
]}"
acpi -b | grep "Battery 0" | awk -F'[,:%]' '{print $2, $3}' | {
read -r status capacity
2024-03-14 16:35:36 +01:00
if [ "$status" = Discharging -a "$capacity" -le 2 ]; then
2024-03-12 11:59:27 +01:00
dunstify -u critical -a batMon \
-h string:x-dunst-stack-tag:batMon \
-h int:value:"$capacity" "Battery Critical: ''${capacity}%
Hibernating"
sleep 5
systemctl hibernate
2024-03-14 16:35:36 +01:00
elif [ "$status" = Discharging -a "$capacity" -le 5 ]; then
2024-03-12 11:59:27 +01:00
dunstify -u critical -a batMon \
-h string:x-dunst-stack-tag:batMon \
-h int:value:"$capacity" "Battery Critical: ''${capacity}%"
fi
}
'';
in {
ExecStart = "${batMon}";
};
};
};
};
2023-07-31 14:18:02 +02:00
}