diff --git a/custom/brave-nightly/default.nix b/custom/brave-nightly/default.nix new file mode 100644 index 0000000..989baff --- /dev/null +++ b/custom/brave-nightly/default.nix @@ -0,0 +1,209 @@ +{ lib, stdenv, fetchurl, wrapGAppsHook, makeWrapper +, dpkg +, alsa-lib +, at-spi2-atk +, at-spi2-core +, atk +, cairo +, cups +, dbus +, expat +, fontconfig +, freetype +, gdk-pixbuf +, glib +, gnome +, gsettings-desktop-schemas +, gtk3 +, libuuid +, libdrm +, libX11 +, libXcomposite +, libXcursor +, libXdamage +, libXext +, libXfixes +, libXi +, libxkbcommon +, libXrandr +, libXrender +, libXScrnSaver +, libxshmfence +, libXtst +, mesa +, nspr +, nss +, pango +, pipewire +, udev +, wayland +, xorg +, zlib +, xdg-utils +, snappy + +# command line arguments which are always set e.g "--disable-gpu" +, commandLineArgs ? "" + +# Necessary for USB audio devices. +, pulseSupport ? stdenv.isLinux +, libpulseaudio + +# For GPU acceleration support on Wayland (without the lib it doesn't seem to work) +, libGL + +# For video acceleration via VA-API (--enable-features=VaapiVideoDecoder,VaapiVideoEncoder) +, libvaSupport ? stdenv.isLinux +, libva +, enableVideoAcceleration ? libvaSupport + +# For Vulkan support (--enable-features=Vulkan); disabled by default as it seems to break VA-API +, vulkanSupport ? false +, addOpenGLRunpath +, enableVulkan ? vulkanSupport +}: + +let + inherit (lib) optional optionals makeLibraryPath makeSearchPathOutput makeBinPath + optionalString strings escapeShellArg; + + deps = [ + alsa-lib at-spi2-atk at-spi2-core atk cairo cups dbus expat + fontconfig freetype gdk-pixbuf glib gtk3 libdrm libX11 libGL + libxkbcommon libXScrnSaver libXcomposite libXcursor libXdamage + libXext libXfixes libXi libXrandr libXrender libxshmfence + libXtst libuuid mesa nspr nss pango pipewire udev wayland + xorg.libxcb zlib snappy + ] + ++ optional pulseSupport libpulseaudio + ++ optional libvaSupport libva; + + rpath = makeLibraryPath deps + ":" + makeSearchPathOutput "lib" "lib64" deps; + binpath = makeBinPath deps; + + enableFeatures = optionals enableVideoAcceleration [ "VaapiVideoDecoder" "VaapiVideoEncoder" ] + ++ optional enableVulkan "Vulkan"; + + # The feature disable is needed for VAAPI to work correctly: https://github.com/brave/brave-browser/issues/20935 + disableFeatures = optional enableVideoAcceleration "UseChromeOSDirectVideoDecoder"; +in + +stdenv.mkDerivation rec { + pname = "brave-nightly"; + version = "1.52.54"; + + src = fetchurl { + url = "https://github.com/brave/brave-browser/releases/download/v${version}/brave-browser-nightly_${version}_amd64.deb"; + sha256 = "sha256-k9Vxk9e9514II78pe0FPRNNXwSHKRqLigqefSOmNVjg="; + }; + + dontConfigure = true; + dontBuild = true; + dontPatchELF = true; + doInstallCheck = true; + + nativeBuildInputs = [ + dpkg + (wrapGAppsHook.override { inherit makeWrapper; }) + ]; + + buildInputs = [ + # needed for GSETTINGS_SCHEMAS_PATH + glib gsettings-desktop-schemas gtk3 + + # needed for XDG_ICON_DIRS + gnome.adwaita-icon-theme + ]; + + unpackPhase = "dpkg-deb --fsys-tarfile $src | tar -x --no-same-permissions --no-same-owner"; + + installPhase = '' + runHook preInstall + + mkdir -p $out $out/bin + + cp -R usr/share $out + cp -R opt/ $out/opt + + export BINARYWRAPPER=$out/opt/brave.com/brave-nightly/brave-browser-nightly + + # Fix path to bash in $BINARYWRAPPER + substituteInPlace $BINARYWRAPPER \ + --replace /bin/bash ${stdenv.shell} + + ln -sf $BINARYWRAPPER $out/bin/brave-nightly + + for exe in $out/opt/brave.com/brave-nightly/{brave,chrome_crashpad_handler}; do + patchelf \ + --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ + --set-rpath "${rpath}" $exe + done + + # Fix paths + substituteInPlace $out/share/applications/brave-browser-nightly.desktop \ + --replace /usr/bin/brave-browser-nightly $out/bin/brave-nightly + substituteInPlace $out/share/gnome-control-center/default-apps/brave-browser-nightly.xml \ + --replace /opt/brave.com $out/opt/brave.com + substituteInPlace $out/share/menu/brave-browser-nightly.menu \ + --replace /opt/brave.com $out/opt/brave.com + substituteInPlace $out/opt/brave.com/brave-nightly/default-app-block \ + --replace /opt/brave.com $out/opt/brave.com + + # Correct icons location + icon_sizes=("16" "24" "32" "48" "64" "128" "256") + + for icon in ''${icon_sizes[*]} + do + mkdir -p $out/share/icons/hicolor/$icon\x$icon/apps + ln -s $out/opt/brave.com/brave-nightly/product_logo_$icon.png $out/share/icons/hicolor/$icon\x$icon/apps/brave-browser-nightly.png + done + + # Replace xdg-settings and xdg-mime + ln -sf ${xdg-utils}/bin/xdg-settings $out/opt/brave.com/brave-nightly/xdg-settings + ln -sf ${xdg-utils}/bin/xdg-mime $out/opt/brave.com/brave-nightly/xdg-mime + + runHook postInstall + ''; + + preFixup = '' + # Add command line args to wrapGApp. + gappsWrapperArgs+=( + --prefix LD_LIBRARY_PATH : ${rpath} + --prefix PATH : ${binpath} + --suffix PATH : ${lib.makeBinPath [ xdg-utils ]} + ${optionalString (enableFeatures != []) '' + --add-flags "--enable-features=${strings.concatStringsSep "," enableFeatures}" + ''} + ${optionalString (disableFeatures != []) '' + --add-flags "--disable-features=${strings.concatStringsSep "," disableFeatures}" + ''} + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" + ${optionalString vulkanSupport '' + --prefix XDG_DATA_DIRS : "${addOpenGLRunpath.driverLink}/share" + ''} + --add-flags ${escapeShellArg commandLineArgs} + ) + ''; + + installCheckPhase = '' + # Bypass upstream wrapper which suppresses errors + $out/opt/brave.com/brave-nightly/brave-browser-nightly --version + ''; + + passthru.updateScript = ./update.sh; + + meta = with lib; { + homepage = "https://brave.com/"; + description = "Privacy-oriented browser for Desktop and Laptop computers"; + changelog = "https://github.com/brave/brave-browser/blob/master/CHANGELOG_DESKTOP.md#" + replaceStrings [ "." ] [ "" ] version; + longDescription = '' + Brave browser blocks the ads and trackers that slow you down, + chew up your bandwidth, and invade your privacy. Brave lets you + contribute to your favorite creators automatically. + ''; + sourceProvenance = with sourceTypes; [ binaryNativeCode ]; + license = licenses.mpl20; + maintainers = with maintainers; [ uskudnik rht jefflabonte nasirhm ]; + platforms = [ "x86_64-linux" ]; + }; +} \ No newline at end of file diff --git a/custom/lf-sixel/default.nix b/custom/lf-sixel/default.nix new file mode 100644 index 0000000..5bd2977 --- /dev/null +++ b/custom/lf-sixel/default.nix @@ -0,0 +1,49 @@ +{ lib +, stdenv +, buildGoModule +, fetchFromGitHub +, installShellFiles +}: + +buildGoModule rec { + pname = "lf"; + version = "28-1"; + + src = fetchFromGitHub { + owner = "horriblename"; + repo = "lf"; + rev = "r${version}"; + hash = "sha256-FBjvZueSh9+grdDrD8DTOlJb6GaCQuJhrsOXRwlpDSQ="; + }; + + vendorSha256 = "sha256-oIIyQbw42+B6T6Qn6nIV62Xr+8ms3tatfFI8ocYNr0A="; + + nativeBuildInputs = [ installShellFiles ]; + + ldflags = [ "-s" "-w" "-X main.gVersion=r${version}" ]; + + # Force the use of the pure-go implementation of the os/user library. + # Relevant issue: https://github.com/gokcehan/lf/issues/191 + tags = lib.optionals (!stdenv.isDarwin) [ "osusergo" ]; + + postInstall = '' + install -D --mode=444 lf.desktop $out/share/applications/lf.desktop + installManPage lf.1 + installShellCompletion etc/lf.{bash,zsh,fish} + ''; + + meta = with lib; { + description = "A terminal file manager written in Go and heavily inspired by ranger"; + longDescription = '' + lf (as in "list files") is a terminal file manager written in Go. It is + heavily inspired by ranger with some missing and extra features. Some of + the missing features are deliberately omitted since it is better if they + are handled by external tools. + ''; + homepage = "https://godoc.org/github.com/gokcehan/lf"; + changelog = "https://github.com/gokcehan/lf/releases/tag/r${version}"; + license = licenses.mit; + platforms = platforms.unix; + maintainers = with maintainers; [ dotlambda ]; + }; +} \ No newline at end of file diff --git a/system/global/home.nix b/system/global/home.nix index 0603ea6..86137c2 100644 --- a/system/global/home.nix +++ b/system/global/home.nix @@ -1,5 +1,64 @@ { config, pkgs, user, name, ... }: # https://nix-community.github.io/home-manager/options.html +let + my-deps = { + notify-send = "${pkgs.libnotify}/bin/notify-send"; + playerctl = "${pkgs.playerctl}/bin/playerctl"; + grim = "${pkgs.grim}/bin/grim"; + slurp = "${pkgs.slurp}/bin/slurp"; + amixer = "${pkgs.alsa-utils}/bin/amixer"; + swaybg = "${pkgs.swaybg}/bin/swaybg"; + terminal = "${pkgs.foot}/bin/foot"; + chafa = "${pkgs.chafa}/bin/chafa"; + exiftool = "${pkgs.exiftool}/bin/exiftool"; + }; + my-scripts = [ + ( pkgs.writeShellScriptBin "menu" '' + wofi --dmenu + '' ) + + ( pkgs.writeShellScriptBin "play-pause" '' + if [ "$(${my-deps.playerctl} --list-all | wc -l)" -lt 2 ] + then + ${my-deps.playerctl} play-pause + else + ${ my-deps.playerctl } --list-all | \ + xargs -I _ ${ my-deps.playerctl } --player _ metadata --format '_ - {{title}}' | \ + menu | awk '{print $1}' | \ + xargs -I _ ${ my-deps.playerctl } --player _ play-pause + fi + '' ) + + ( pkgs.writeShellScriptBin "bwmenu" '' + items="$(rbw list)" + echo "$items" | menu | xargs -I_ rbw get _ | wl-copy + '' ) + + ( pkgs.writeShellScriptBin "screenshot" '' + OUT_DIR=~/Pictures/Screenshots + mkdir -p "$OUT_DIR" + FILE=$OUT_DIR/$(date +"%Y-%m-%dT%H:%M:%SZ").png + + ${ my-deps.grim } -g "$(${ my-deps.slurp } -o)" "$FILE" + ${my-deps.notify-send} "Screenshot Taken" "$FILE" + + cat "$FILE" | wl-copy -t image/png + '' ) + + ( pkgs.writeShellScriptBin "brightness-down" '' + light -U 10 + ${my-deps.notify-send} "Brightness" -h int:value:$(light) -a brightness-down -t 1000 + '' ) + + ( pkgs.writeShellScriptBin "brightness-up" '' + light -A 10 + ${my-deps.notify-send} "Brightness" -h int:value:$(light) -a brightness-up -t 1000 + '' ) + ]; + + brave-nightly = pkgs.callPackage ../../custom/brave-nightly/. {}; + lf-sixel = pkgs.callPackage ../../custom/lf-sixel/. {}; +in { programs.home-manager.enable = true; @@ -21,27 +80,24 @@ }; home.packages = with pkgs; [ - # script requirements libnotify - playerctl - grim wl-clipboard - slurp chafa wofi exa + du-dust htop imv libsixel - swaybg - imagemagick + lf-sixel brave + brave-nightly logseq quickemu bitwarden - ]; + ] ++ my-scripts; programs.fish = { enable = true; @@ -90,13 +146,13 @@ } } - bind = SUPER, RETURN, exec, foot + bind = SUPER, RETURN, exec, ${ my-deps.terminal } bind = SUPER_SHIFT, Q, killactive, bind = SUPER_SHIFT, E, exit, bind = SUPER, d, exec, wofi --show drun - bind = SUPER, Z, exec, swaylock -f - bind = SUPER, M, exec, foot -e ncmpcpp - bind = SUPER, E, exec, foot -e neomutt + bind = SUPER, Z, exec, "${pkgs.swaylock-effects}/bin/swaylock" -f + bind = SUPER, M, exec, ${ my-deps.terminal } -e ncmpcpp + bind = SUPER, E, exec, ${ my-deps.terminal } -e neomutt bind = SUPER, O, exec, pcmanfm bind = SUPER, h, movefocus,l @@ -111,16 +167,16 @@ bind = SUPER, F, fullscreen, bind = SUPER, V, togglefloating, - bind = SUPER_SHIFT, P, exec,~/.local/scripts/bwmenu - bind = SUPER_SHIFT, S, exec,~/.local/scripts/screenshot + bind = SUPER_SHIFT, P, exec,bwmenu + bind = SUPER_SHIFT, S, exec,screenshot - bind =,XF86AudioRaiseVolume, exec,amixer sset Master 5%+ && amixer sset Master unmute - bind =,XF86AudioLowerVolume, exec,amixer sset Master 5%- - bind =,XF86AudioPlay, exec,~/.local/scripts/play-pause - bind =,XF86AudioNext, exec,playerctl next - bind =,XF86AudioPrev, exec,playerctl previous - bind =,XF86MonBrightnessUp, exec,~/.local/scripts/brightness-up - bind =,XF86MonBrightnessDown, exec,~/.local/scripts/brightness-down + bind =,XF86AudioRaiseVolume, exec,${ my-deps.amixer } sset Master 5%+ && ${ my-deps.amixer } sset Master unmute + bind =,XF86AudioLowerVolume, exec,${ my-deps.amixer } sset Master 5%- + bind =,XF86AudioPlay, exec,play-pause + bind =,XF86AudioNext, exec,${ my-deps.playerctl } next + bind =,XF86AudioPrev, exec,${ my-deps.playerctl } previous + bind =,XF86MonBrightnessUp, exec,brightness-up + bind =,XF86MonBrightnessDown, exec,brightness-down bind = SUPER,1,workspace,1 bind = SUPER,2,workspace,2 @@ -195,7 +251,7 @@ status-icons = { paused = "⏸️"; }; - on-click = "~/.local/scripts/play-pause"; + on-click = "play-pause"; }; battery = { format = "{icon} {capacity}%"; @@ -247,8 +303,8 @@ bindings = [ { key = "j"; command = "scroll_down"; } { key = "k"; command = "scroll_up"; } - { key = "l"; command = "select_item"; } - { key = "k"; command = "scroll_up"; } + { key = "l"; command = "next_column"; } + { key = "h"; command = "previous_column"; } { key = "J"; command = [ "select_item" "scroll_down" ]; } { key = "K"; command = [ "select_item" "scroll_up" ]; } ]; @@ -338,18 +394,82 @@ programs.neovim.defaultEditor = true; programs.lf.enable = true; + programs.lf.package = lf-sixel; programs.lf.keybindings = { D = "trash"; }; + programs.lf.previewer.source = pkgs.writeShellScript "preview" '' +image () { + ${my-deps.chafa} "$1" -f sixel -s "$(($2/2))x$3" | sed 's/#/\n#/g' + ${ my-deps.exiftool } "$1" +} + +batted () { + cat "$@" +} + +CACHE="$HOME/.cache/lf/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}'))" + +case "$(printf "%s\n" "$(readlink -f "$1")" | awk '{print tolower($0)}')" in + *.tgz|*.tar.gz) tar tzf "$1" ;; + *.tar.bz2|*.tbz2) tar tjf "$1" ;; + *.tar.txz|*.txz) xz --list "$1" ;; + *.tar) tar tf "$1" ;; + *.zip|*.jar|*.war|*.ear|*.oxt) unzip -l "$1" ;; + *.rar) unrar l "$1" ;; + *.md) glow -s dark "$1" ;; + *.7z) 7z l "$1" ;; + *.[1-8]) man "$1" | col -b ;; + *.o) nm "$1";; + *.torrent) transmission-show "$1" ;; + *.iso) iso-info --no-header -l "$1" ;; + *.odt|*.ods|*.odp|*.sxw) odt2txt "$1" ;; + *.doc) catdoc "$1" ;; + *.docx) docx2txt "$1" - ;; + *.xml|*.html) w3m -dump "$1";; + *.xls|*.xlsx) + ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batted --language=csv + ;; + *.wav|*.mp3|*.flac|*.m4a|*.wma|*.ape|*.ac3|*.og[agx]|*.spx|*.opus|*.as[fx]|*.mka) + ${ my-deps.exiftool } "$1" + ;; + *.pdf) + [ ! -f "$CACHE.jpg" ] && \ + pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE" + image "$CACHE.jpg" "$2" "$3" "$4" "$5" + ;; + *.epub) + [ ! -f "$CACHE" ] && \ + epub-thumbnailer "$1" "$CACHE" 1024 + image "$CACHE" "$2" "$3" "$4" "$5" + ;; + *.cbz|*.cbr|*.cbt) + [ ! -f "$CACHE" ] && \ + comicthumb "$1" "$CACHE" 1024 + image "$CACHE" "$2" "$3" "$4" "$5" + ;; + *.avi|*.mp4|*.wmv|*.dat|*.3gp|*.ogv|*.mkv|*.mpg|*.mpeg|*.vob|*.fl[icv]|*.m2v|*.mov|*.webm|*.ts|*.mts|*.m4v|*.r[am]|*.qt|*.divx) + [ ! -f "$CACHE.jpg" ] && \ + ffmpegthumbnailer -i "$1" -o "$CACHE.jpg" -s 0 -q 5 + image "$CACHE.jpg" "$2" "$3" "$4" "$5" + ;; + *.bmp|*.jpg|*.jpeg|*.png|*.xpm|*.webp|*.gif|*.jfif) + image "$1" "$2" "$3" "$4" "$5" + ;; + *.svg) + [ ! -f "$CACHE.jpg" ] && \ + convert "$1" "$CACHE.jpg" + image "$CACHE.jpg" "$2" "$3" "$4" "$5" + ;; + *.ino) + batted --language=cpp "$1" + ;; + *) + batted "$1" + ;; +esac + ''; - home.sessionPath = [ - "$HOME/.local/scripts" - ]; - home.file.".local/scripts" = { - source = ./scripts; - executable = true; - recursive = true; - }; home.file.".config/wofi/config".text = '' term=foot ''; diff --git a/system/global/scripts/autostart b/system/global/scripts/autostart deleted file mode 100755 index 6adf935..0000000 --- a/system/global/scripts/autostart +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -nextcloud & -waybar & - -swaybg \ - -o eDP-1 -i ~/Pictures/backgrounds/nix-wallpaper-waterfall.png \ - -o DP-1 -i ~/Pictures/backgrounds/demonslayer.jpg \ - -o HDMI-A-1 -i ~/Pictures/backgrounds/nier.jpg & - -swayidle -w \ - timeout 600 'swaylock &' & - diff --git a/system/global/scripts/brightness-down b/system/global/scripts/brightness-down deleted file mode 100755 index a24fe3d..0000000 --- a/system/global/scripts/brightness-down +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -light -U 10 -notify-send "Brightness" -h int:value:$(light) -a brightness-down -t 1000 - diff --git a/system/global/scripts/brightness-up b/system/global/scripts/brightness-up deleted file mode 100755 index 35682f1..0000000 --- a/system/global/scripts/brightness-up +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -light -A 10 -notify-send "Brightness" -h int:value:$(light) -a brightness-up -t 1000 - diff --git a/system/global/scripts/bwmenu b/system/global/scripts/bwmenu deleted file mode 100755 index 6200fe9..0000000 --- a/system/global/scripts/bwmenu +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -items="$(rbw list)" -echo "$items" | wofi --show dmenu | xargs -I_ rbw get _ | wl-copy diff --git a/system/global/scripts/play-pause b/system/global/scripts/play-pause deleted file mode 100755 index 37a415c..0000000 --- a/system/global/scripts/play-pause +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -if [ "$(playerctl --list-all | wc -l)" -lt 2 ] -then - playerctl play-pause -else - playerctl --list-all | \ - xargs -I _ playerctl --player _ metadata --format '_ - {{title}}' | \ - wofi --dmenu | awk '{print $1}' | \ - xargs -I _ playerctl --player _ play-pause -fi diff --git a/system/global/scripts/screenshot b/system/global/scripts/screenshot deleted file mode 100755 index 66f3c4f..0000000 --- a/system/global/scripts/screenshot +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -OUT_DIR=${GRIM_DEFAULT_DIR:-~/Pictures/Screenshots} -mkdir -p "$OUT_DIR" -FILE=$OUT_DIR/$(date +"%Y-%m-%dT%H:%M:%SZ").png - -grim -g "$(slurp -o)" "$FILE" -notify-send "Screenshot Taken" "$FILE" - -cat "$FILE" | wl-copy -t image/png - diff --git a/system/work/home.nix b/system/work/home.nix index d2062f9..0bcb9ed 100644 --- a/system/work/home.nix +++ b/system/work/home.nix @@ -23,9 +23,10 @@ wayland.windowManager.hyprland = { extraConfig = '' - exec-once = swaybg -o eDP-1 -i ~/Pictures/backgrounds/nix-wallpaper-simple-red.png & + exec-once = ${my-deps.swaybg} -o eDP-1 -i ~/Pictures/backgrounds/nix-wallpaper-simple-red.png & monitor = ,preferred,auto, 1.2 + accel_profile = flat input { kb_variant = dvorak }