nixfiles/home-manager/modules/ezpcusr.nix

749 lines
23 KiB
Nix
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

inputs:
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.ezpcusr;
lockCommand = "${pkgs.swaylock-effects}/bin/swaylock --clock --indicator --screenshots --effect-scale 0.5 --effect-blur 5x2 --effect-vignette 0.2:0.5 --fade-in 1 --datestr %Y-%m-%e";
selshot = pkgs.writeScript "selshot.sh" ''
#!${pkgs.zsh}/bin/zsh
${pkgs.grim}/bin/grim -g "$(${pkgs.slurp}/bin/slurp)" $1
'';
selvid = pkgs.writeScript "selvid.sh" ''
#!${pkgs.zsh}/bin/zsh
${pkgs.wf-recorder}/bin/wf-recorder -g "$(${pkgs.slurp}/bin/slurp)" -f $1
'';
getscrloc = pkgs.writeScript "getscrloc.sh" ''
#!${pkgs.zsh}/bin/zsh
mkdir -p "$HOME/Pictures/Screenshots"
echo "$HOME/Pictures/Screenshots/$(date +%F_%T).''${1:-png}"
'';
scrsaveclip = pkgs.writeScript "scr-save-clip.sh" ''
#!${pkgs.zsh}/bin/zsh
LOC=$(${getscrloc})
${selshot} $LOC
${pkgs.wl-clipboard}/bin/wl-copy -t image/png < $LOC
'';
scrsaveup =
if cfg.uploadScript != null then
pkgs.writeScript "scr-save-up.sh" ''
#!${pkgs.zsh}/bin/zsh
LOC=$(${getscrloc})
${selshot} $LOC
${cfg.uploadScript} $LOC | xargs echo -n | ${pkgs.wl-clipboard}/bin/wl-copy
notify-send "Screenshot Uploaded!"
''
else
null;
scrvidsaveclip = pkgs.writeScript "scr-vid-save-clip.sh" ''
#!${pkgs.zsh}/bin/zsh
LOC=$(${getscrloc} mp4)
${selvid} $LOC
${pkgs.wl-clipboard}/bin/wl-copy -t video/mp4 < $LOC
'';
scrvidsaveup =
if cfg.uploadScript != null then
pkgs.writeScript "scr-vid-save-up.sh" ''
#!${pkgs.zsh}/bin/zsh
LOC=$(${getscrloc} mp4)
${selvid} $LOC
${cfg.uploadScript} $LOC | ${pkgs.findutils}/bin/xargs echo -n | ${pkgs.wl-clipboard}/bin/wl-copy
notify-send "Screen Recording Uploaded!"
''
else
null;
scrvidstop = pkgs.writeScript "scr-vid-stop.sh" ''
#!${pkgs.zsh}/bin/zsh
${pkgs.procps}/bin/pkill -2 wf-recorder
'';
um = pkgs.writeScript "update-music.sh" ''
#!${pkgs.bash}/bin/bash
${pkgs.mpc_cli}/bin/mpc update --wait && ${pkgs.mpc_cli}/bin/mpc clear && ${pkgs.mpc_cli}/bin/mpc ls | ${pkgs.mpc_cli}/bin/mpc add
'';
ezDrv = pkgs.runCommand "ez-commands" { } (''
mkdir -p $out/bin
ln -s ${selshot} $out/bin/selshot
ln -s ${selvid} $out/bin/selvid
ln -s ${getscrloc} $out/bin/getscrloc
ln -s ${scrsaveclip} $out/bin/scrsaveclip
ln -s ${scrvidsaveclip} $out/bin/scrvidsaveclip
ln -s ${scrvidstop} $out/bin/scrvidstop
ln -s ${um} $out/bin/um
'' + (
if cfg.uploadScript != null then ''
ln -s ${cfg.uploadScript} $out/bin/upload_file
ln -s ${scrsaveup} $out/bin/scrsaveup
ln -s ${scrvidsaveup} $out/bin/scrvidsaveup
'' else ""
)
);
in
{
options.ezpcusr = {
enable = mkEnableOption "Enable simple PC user config";
newWine = mkOption {
type = types.bool;
default = false;
description = "If you want to include wine-staging as new-wine";
};
flatSteam = mkOption {
type = types.bool;
default = false;
description = "If you use the flatpak Steam instead of NixOS";
};
babybar = mkOption {
default = false;
description = ''Switch to using the "baby" swaybar rather than waybar'';
};
uploadScript = mkOption {
type = types.nullOr types.package;
default = null;
description =
"A path to a script that takes a path to a file and returns a URL";
};
bitwardenSession = mkOption {
description = "Session key for bitwarden";
default = "";
type = types.str;
};
outputOptions = mkOption {
description = "Additional output options";
default = { };
type = types.attrsOf (types.attrsOf types.str);
};
waybarConfig = mkOption {
description = "Waybar config";
default = { };
};
makoArgs = mkOption {
description = "Args for mako notification displayer";
default = "";
type = types.str;
};
screensaver = mkOption {
description = "ezpcusr screensaver";
default = { };
type = types.submodule {
options = {
enable = mkOption {
type = types.bool;
default = true;
description = "Enable ezpcusr's screensaver";
};
lockTime = mkOption {
type = types.int;
default = 300;
description = "Time until your screen locks";
};
offTime = mkOption {
type = types.int;
default = 600;
description = "Time until your screen turns off";
};
};
};
};
favIcons = mkOption {
description = "Your favourite icons pack";
default = { };
type = types.submodule {
options = {
name = mkOption {
type = types.str;
default = "Papirus-Dark";
description = "Name of your icon pack";
};
package = mkOption {
type = types.package;
default = pkgs.papirus-icon-theme;
description = "Package for your icon pack";
};
};
};
};
gaming = mkOption {
type = types.bool;
default = false;
description = "If this PC is used for gaming";
};
bluetooth = mkOption {
type = types.bool;
default = false;
description = "If this PC has bluetooth support";
};
battery = mkOption {
type = types.bool;
default = false;
description = "If this PC has a battery";
};
location = mkOption {
description = "Your location (used for weather)";
example = "US-12345";
default = "";
type = types.str;
};
};
config = lib.mkIf cfg.enable {
wayland.windowManager.sway = {
enable = lib.mkDefault true;
systemdIntegration = lib.mkDefault true;
wrapperFeatures.gtk = lib.mkDefault true;
extraConfig = ''
exec swayidle -w \
timeout ${toString cfg.screensaver.lockTime} '${lockCommand}' \
timeout ${toString cfg.screensaver.offTime} '${pkgs.sway}/bin/swaymsg "output * dpms off"' \
resume '${pkgs.sway}/bin/swaymsg "output * dpms on"' \
before-sleep '${lockCommand}'
'';
config = {
terminal = lib.mkDefault "kitty";
modifier = lib.mkDefault "Mod4";
keybindings =
let
musicRofi = pkgs.writeScript "music-rofi" ''
#!${pkgs.fish}/bin/fish
${pkgs.mpc_cli}/bin/mpc -f "%position% - %artist% - %album% - %title%" playlist | ${pkgs.rofi}/bin/rofi -dmenu -i | ${pkgs.coreutils}/bin/cut -d " " -f 1 | ${pkgs.findutils}/bin/xargs ${pkgs.mpc_cli}/bin/mpc play
'';
# ugly stupid way of doing things but im lazy
bwRofi = pkgs.writeScript "bw-rofi" ''
#!${pkgs.bash}/bin/bash
export BW_SESSION="${cfg.bitwardenSession}"
LIST=$(${pkgs.bitwarden-cli}/bin/bw list items)
USERLIST=$(echo "$LIST" | ${pkgs.jq}/bin/jq -r '.[] | "\(.name) - \(.login.username)"')
CHOSEN=$(echo "$USERLIST" | ${pkgs.rofi}/bin/rofi -dmenu -i)
NUMBER=$(echo "$USERLIST" | grep -n "^$CHOSEN$" | cut -d':' -f1)
NTH=$(expr $NUMBER - 1)
echo "$LIST" | ${pkgs.jq}/bin/jq -j -r ".[$NTH].login.password" | ${pkgs.wl-clipboard}/bin/wl-copy
'';
# very ugly stupid way of doing things but im still lazy
bwRofiOtp = pkgs.writeScript "bw-rofi-otp" ''
#!${pkgs.bash}/bin/bash
export BW_SESSION="${cfg.bitwardenSession}"
LIST=$(${pkgs.bitwarden-cli}/bin/bw list items)
USERLIST=$(echo "$LIST" | ${pkgs.jq}/bin/jq -r '.[] | "\(.name) - \(.login.username)"')
CHOSEN=$(echo "$USERLIST" | ${pkgs.rofi}/bin/rofi -dmenu -i)
NUMBER=$(echo "$USERLIST" | grep -n "^$CHOSEN$" | cut -d':' -f1)
NTH=$(expr $NUMBER - 1)
ID=$(echo "$LIST" | ${pkgs.jq}/bin/jq -j -r ".[$NTH].id")
${pkgs.bitwarden-cli}/bin/bw get totp $ID | ${pkgs.wl-clipboard}/bin/wl-copy
'';
emojiRofi = pkgs.writeScript "rofi-emoji" ''
line=$(${pkgs.coreutils}/bin/cat ${toString ../data/emojis.txt} | ${pkgs.rofi}/bin/rofi -dmenu -i)
${pkgs.coreutils}/bin/echo ''${line::1} | ${pkgs.wl-clipboard}/bin/wl-copy
'';
modifier = config.wayland.windowManager.sway.config.modifier;
alphabet = [ "Ctrl" "Alt" "Ctrl+Alt" ];
genKeyAttrs = move: lib.listToAttrs (
map
(
n: {
name = "${modifier}${if move then "+Shift" else ""}+${builtins.elemAt alphabet ((n - 11) / 10)}+${
toString (lib.mod n 10)
}";
value = "${if move then "move container to " else ""}workspace ${toString n}";
}
)
(lib.lists.range 11 (10 * (builtins.length alphabet) + 10))
);
in
lib.mkOptionDefault (
genKeyAttrs true // genKeyAttrs false // (
let
volumeUp = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ +5%";
volumeDown = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ -5%";
in
{
"Print" = "exec ${scrsaveclip}";
"Shift+Print" = if cfg.uploadScript != null then "exec ${scrsaveup}" else "nop";
"Ctrl+Print" = "exec ${scrvidsaveclip}";
"Ctrl+Alt+Print" = "exec ${scrvidstop}";
"${modifier}+minus" = volumeDown;
"${modifier}+equal" = volumeUp;
"XF86AudioRaiseVolume" = volumeUp;
"XF86AudioLowerVolume" = volumeDown;
"XF86AudioMute" =
"exec ${pkgs.pulseaudio}/bin/pactl set-sink-mute @DEFAULT_SINK@ toggle";
"XF86AudioMicMute" =
"exec ${pkgs.pulseaudio}/bin/pactl set-source-mute @DEFAULT_SOURCE@ toggle";
"XF86MonBrightnessDown" = "exec ${pkgs.light}/bin/light -U 10";
"XF86MonBrightnessUp" = "exec ${pkgs.light}/bin/light -A 10";
"${modifier}+semicolon" = "exec ${pkgs.light}/bin/light -U 10";
"${modifier}+apostrophe" = "exec ${pkgs.light}/bin/light -A 10";
# Previous/next but change the shuffle/random state before action (and change back afterwards)
"${modifier}+Shift+bracketright" =
"exec ${pkgs.mpc_cli}/bin/mpc random && ${pkgs.mpc_cli}/bin/mpc next && ${pkgs.mpc_cli}/bin/mpc random";
"${modifier}+Shift+bracketleft" =
"exec ${pkgs.mpc_cli}/bin/mpc random && ${pkgs.mpc_cli}/bin/mpc prev && ${pkgs.mpc_cli}/bin/mpc random";
"Shift+XF86AudioNext" =
"exec ${pkgs.mpc_cli}/bin/mpc random && ${pkgs.mpc_cli}/bin/mpc next && ${pkgs.mpc_cli}/bin/mpc random";
# Previous/next
"${modifier}+bracketright" = "exec ${pkgs.mpc_cli}/bin/mpc next";
"${modifier}+bracketleft" = "exec ${pkgs.mpc_cli}/bin/mpc prev";
"XF86AudioNext" = "exec ${pkgs.mpc_cli}/bin/mpc next";
"XF86AudioPrev" = "exec ${pkgs.mpc_cli}/bin/mpc prev";
# Toggle play/pause
"XF86AudioPlay" = "exec ${pkgs.mpc_cli}/bin/mpc toggle";
"XF86AudioPause" = "exec ${pkgs.mpc_cli}/bin/mpc toggle";
"${modifier}+backslash" = "exec ${pkgs.mpc_cli}/bin/mpc toggle";
"${modifier}+m" = "exec ${musicRofi}";
"${modifier}+p" = "exec ${bwRofi}";
"${modifier}+t" = "exec ${bwRofiOtp}";
"${modifier}+o" = "exec ${emojiRofi}";
"${modifier}+0" = "workspace 10";
"${modifier}+Shift+0" = "move container to workspace 10";
"Ctrl+Alt+l" = "exec ${lockCommand}";
}
)
);
menu = "${pkgs.rofi}/bin/rofi -show drun -show-icons -run-command '${pkgs.sway}/bin/swaymsg exec -- {cmd}'";
bars = lib.optional cfg.babybar {
position = "top";
colors = config.colors.i3BarColors;
};
gaps = {
smartGaps = lib.mkDefault true;
smartBorders = lib.mkDefault "on";
inner = lib.mkDefault 10;
outer = lib.mkDefault 0;
};
};
};
home.sessionVariables = {
QT_QPA_PLATFORM = "wayland-egl;xcb";
MOZ_ENABLE_WAYLAND = "1";
QT_WAYLAND_DISABLE_WINDOWDECORATION = "1";
ECORE_EVAS_ENGINE = "wayland_egl";
ELM_ENGINE = "wayland_egl";
_JAVA_AWT_WM_NONREPARENTING = "1";
};
programs.waybar = {
enable = lib.mkDefault (cfg.babybar != true);
systemd.enable = lib.mkDefault true;
settings = [
({
position = "left";
height = null;
modules-left = [ "sway/workspaces" "custom/right-arrow-dark" "custom/right-arrow-light" "custom/weather-temp" "custom/weather-precip" "custom/weather-wind" "custom/right-arrow-dark" ];
modules-center = [ "custom/left-arrow-dark" "clock#1" "clock#2" "custom/left-arrow-light" "custom/left-arrow-dark" "mpd" "custom/right-arrow-dark" "custom/right-arrow-light" "clock#3" "custom/right-arrow-dark" ];
modules-right = [ "custom/left-arrow-dark" "pulseaudio" "custom/left-arrow-light" "custom/left-arrow-dark" "memory" "custom/left-arrow-light" "custom/left-arrow-dark" "cpu" "custom/left-arrow-light" "custom/left-arrow-dark" ] ++ lib.optionals cfg.battery [ "battery" "custom/left-arrow-light" "custom/left-arrow-dark" ] ++ [ "tray" ];
modules = {
"custom/left-arrow-dark" = {
format = "";
tooltip = false;
rotate = 270;
};
"custom/left-arrow-light" = {
format = "";
tooltip = false;
rotate = 270;
};
"custom/right-arrow-dark" = {
format = "";
tooltip = false;
rotate = 270;
};
"custom/right-arrow-light" = {
format = "";
tooltip = false;
rotate = 270;
};
"custom/weather-temp" = {
exec = "${pkgs.curl}/bin/curl 'wttr.in/${cfg.location}?format=%c+%t'";
on-click = "${pkgs.xdg-utils}/bin/xdg-open 'https://weather.com/weather/today/l/85625'";
on-click-right = "${pkgs.xdg-utils}/bin/xdg-open 'https://wttr.in/${cfg.location}'";
interval = 900;
};
"custom/weather-precip" = {
exec = "${pkgs.curl}/bin/curl 'wttr.in/${cfg.location}?format=🌧+%p'";
on-click = "${pkgs.xdg-utils}/bin/xdg-open 'https://www.lightningmaps.org/'";
on-click-right = "${pkgs.xdg-utils}/bin/xdg-open 'https://wttr.in/${cfg.location}'";
interval = 900;
};
"custom/weather-wind" = {
exec = "${pkgs.curl}/bin/curl 'wttr.in/${cfg.location}?format=🌬+%w'";
on-click = "${pkgs.xdg-utils}/bin/xdg-open 'https://www.ventusky.com/";
on-click-right = "${pkgs.xdg-utils}/bin/xdg-open 'https://wttr.in/${cfg.location}'";
interval = 900;
};
mpd = {
rotate = 90;
max-length = 60;
format = "{stateIcon} {artist} - {title}";
format-stopped = " STOPPED";
state-icons = {
paused = "";
playing = "";
};
};
"sway/workspaces" = {
disable-scroll = true;
};
"clock#1" = {
tooltip = false;
format = "{:%a}";
};
"clock#2" = {
tooltip = false;
format = "{:%m-%d}";
};
"clock#3" = {
tooltip = false;
format = "{:%I:%M %p}";
};
pulseaudio = {
format = "{icon} {volume}%";
format-bluetooth = "{icon} {volume}%";
format-muted = "MUTE";
format-icons = {
headphone = "";
default = "";
};
on-click = "${pkgs.pulseaudio}/bin/pactl set-source-mute @DEFAULT_SOURCE@ toggle";
on-click-right = "${pkgs.pavucontrol}/bin/pavucontrol";
};
memory = {
interval = 10;
format = " {}%";
};
cpu = {
interval = 10;
format = " {usage}%";
};
battery = {
states = {
good = 90;
warning = 25;
critical = 10;
};
format = "{icon} {capacity}%";
format-icons = [ "" "" "" "" "" ];
};
tray = {
icon-size = 18;
spacing = 5;
};
};
} // cfg.waybarConfig)
];
style = ''
window#waybar {
background: #${config.colors.base16.base01};
color: #${config.colors.base16.base06};
}
#custom-right-arrow-dark,
#custom-left-arrow-dark {
color: #${config.colors.base16.base00};
font-size: 15px;
}
#custom-right-arrow-light,
#custom-left-arrow-light {
color: #${config.colors.base16.base01};
background: #${config.colors.base16.base00};
font-size: 15px;
}
#workspaces,
#clock.1,
#clock.2,
#clock.3,
#pulseaudio,
#memory,
#cpu,
#battery,
#disk,
#tray,
#mode,
#custom-weather-temp,
#custom-weather-precip,
#custom-weather-wind,
#mpd {
background: #${config.colors.base16.base00};
padding: 5px 0;
}
#workspaces { padding: 0 0 5px 0; }
#clock.1 { padding: 5px 0 0 0; }
#clock.2 { padding: 0 0 5px 0; }
#custom-weather-temp { padding: 5px 0 0 0; }
#custom-weather-precip { padding: 5px 0; }
#custom-weather-wind { padding: 0 0 5px 0; }
#mpd.playing {
color: #${config.colors.base16.base0A};
}
#workspaces button.focused {
color: #${config.colors.base16.base0A};
}
#workspaces button:hover {
background: #${config.colors.base16.base02};
}
#pulseaudio {
color: #${config.colors.base16.base0B};
}
#memory {
color: #${config.colors.base16.base0C};
}
#cpu {
color: #${config.colors.base16.base0D};
}
#battery {
color: #${config.colors.base16.base0E};
}
* {
font-family: "${config.fonts.favFont.name}";
font-size: ${toString (config.fonts.favFont.size + 1)}px;
border-radius: 0;
border: none;
}
'';
};
programs.mako.enable = lib.mkDefault true;
programs.direnv = {
enable = lib.mkDefault true;
nix-direnv = {
enable = lib.mkDefault true;
enableFlakes = lib.mkDefault true;
};
stdlib = ''
: ''${XDG_CACHE_HOME:=$HOME/.cache}
declare -A direnv_layout_dirs
direnv_layout_dir() {
echo "''${direnv_layout_dirs[$PWD]:=$(
echo -n "$XDG_CACHE_HOME"/direnv/layouts/
echo -n "$PWD" | shasum | cut -d ' ' -f 1
)}"
}
'';
};
services.clipmenu.enable = lib.mkDefault true;
colors.enable = lib.mkDefault true;
fonts.enable = lib.mkDefault true;
programs.chromium = {
enable = lib.mkDefault true;
package = lib.mkDefault (pkgs.ungoogled-chromium.override {
commandLineArgs = "--enable-features=UseOzonePlatform --ozone-platform=wayland";
});
};
services.lorri.enable = lib.mkDefault true;
services.blueman-applet = {
enable = lib.mkDefault cfg.bluetooth;
};
services.mpris-proxy.enable = true;
home.sessionVariables = { BW_SESSION = cfg.bitwardenSession; };
services.mpd = {
enable = lib.mkDefault true;
musicDirectory = lib.mkDefault "${config.home.homeDirectory}/Music";
};
gtk = {
enable = lib.mkDefault true;
iconTheme = {
package = lib.mkDefault cfg.favIcons.package;
name = lib.mkDefault cfg.favIcons.name;
};
};
qt = {
enable = lib.mkDefault true;
platformTheme = lib.mkDefault "gtk";
};
programs.kitty = {
enable = lib.mkDefault true;
settings = {
background_opacity = lib.mkDefault "0.80";
dynamic_background_opacity = lib.mkDefault true;
};
};
xdg.configFile."neofetch/config.conf".text =
let
image = builtins.path {
name = "nixos_circlejerk.png";
path = ../data/nixos_circlejerk.png;
};
in
''
image_source="${image}"
image_backend="kitty"
'';
programs.mpv.config = {
enable = lib.mkDefault true;
profile = lib.mkDefault "gpu-hq";
ytdl-format = lib.mkDefault "bestvideo+bestaudio";
cache-default = lib.mkDefault 4000000;
};
fonts.fontconfig.enable = lib.mkDefault true;
home.packages = with pkgs;
let
steam = pkgs.steam.override { withJava = true; };
steam-run = steam.run;
newwine = (pkgs.wineFull.override { wineBuild = "wineWow"; wineRelease = "staging"; });
newwinetricks = pkgs.winetricks.override { wine = newwine; };
oldwine = pkgs.wineWowPackages.full;
oldwinetricks = pkgs.winetricks.override { wine = oldwine; };
in
[
waybar
wl-clipboard # important actually, for vim and other things
xwayland
libappindicator-gtk3
oldwine
oldwinetricks
jq
ezDrv
inputs.mudl.defaultPackage.${pkgs.system}
bitwarden-cli
kitty
pavucontrol
mpv
yt-dlp
maim
slop
ark
notify-osd
libnotify
ffmpeg
id3v2
imagemagick
mpc_cli
nix-index
gitAndTools.hub
nmap
nixpkgs-fmt
] ++ lib.optionals cfg.gaming [
xlibs.xf86inputjoystick
oldwine
oldwinetricks
] ++ lib.optionals (cfg.gaming && !cfg.flatSteam) [
steam
steam-run
(writeScriptBin "steam-run-native" ''
#!${pkgs.stdenv.shell}
${(steam.override { nativeOnly = true; }).run}/bin/steam-run $@
'')
] ++ lib.optionals (cfg.gaming && cfg.newWine) [
(
pkgs.runCommand "new-wine-stuff"
{ } ''
mkdir -p $out/bin
ln -s ${newwine}/bin/wine $out/bin/new-wine
ln -s ${newwine}/bin/winecfg $out/bin/new-winecfg
ln -s ${newwinetricks}/bin/winetricks $out/bin/new-winetricks
''
)
];
programs.rofi = {
enable = lib.mkDefault true;
terminal = lib.mkDefault "kitty";
borderWidth = lib.mkDefault 0;
lines = lib.mkDefault 30;
};
};
}