From 1cd19687be5d7291915a49f0bdb3db6b3adc1473 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Sat, 28 Oct 2023 22:25:06 +0200 Subject: [PATCH] lmao --- build-mac-remote.sh | 4 -- build-mac.sh | 3 - build.sh | 1 - common.nix | 7 +- flake.nix | 2 +- haskell/xmonad/xmonad.hs | 23 ++----- hosts/catbook-j/configuration.nix | 7 +- justfile | 5 ++ modules/desktop/audio.nix | 1 + modules/desktop/default.nix | 16 ++++- modules/desktop/networking.nix | 74 +++++++++++++++------- modules/helix.nix | 8 +-- modules/utils.nix | 49 ++++++++++++++ modules/zellij.nix | 21 +++++- other/config.nu | 20 +++++- other/scripts/desktop/window-screenshot.nu | 19 ++++++ other/scripts/dispatcher.nu | 19 ++++++ other/scripts/networkhooks/WIFI@DB.nu | 40 ++++++++++++ other/scripts/networkhooks/WIFIonICE.nu | 22 +++++++ other/scripts/networkhooks/ccchh.nu | 41 ++++++++++++ test.sh | 1 - 21 files changed, 315 insertions(+), 68 deletions(-) delete mode 100755 build-mac-remote.sh delete mode 100755 build-mac.sh delete mode 100755 build.sh create mode 100644 justfile create mode 100644 modules/utils.nix create mode 100644 other/scripts/desktop/window-screenshot.nu create mode 100755 other/scripts/dispatcher.nu create mode 100755 other/scripts/networkhooks/WIFI@DB.nu create mode 100644 other/scripts/networkhooks/WIFIonICE.nu create mode 100644 other/scripts/networkhooks/ccchh.nu delete mode 100755 test.sh diff --git a/build-mac-remote.sh b/build-mac-remote.sh deleted file mode 100755 index 13c6a15..0000000 --- a/build-mac-remote.sh +++ /dev/null @@ -1,4 +0,0 @@ -sudo nixos-rebuild switch --flake . \ - --impure --override-input mac-brcm-fw path:/home/jade/mac-brcm-fw \ - --build-host 192.168.178.119 --no-build-nix - diff --git a/build-mac.sh b/build-mac.sh deleted file mode 100755 index 31bbe5a..0000000 --- a/build-mac.sh +++ /dev/null @@ -1,3 +0,0 @@ -sudo nixos-rebuild switch --flake . \ - --impure --override-input mac-brcm-fw path:/home/jade/mac-brcm-fw \ - diff --git a/build.sh b/build.sh deleted file mode 100755 index 941d5cf..0000000 --- a/build.sh +++ /dev/null @@ -1 +0,0 @@ -sudo nixos-rebuild switch --flake . --impure diff --git a/common.nix b/common.nix index 423e577..c2aebb0 100644 --- a/common.nix +++ b/common.nix @@ -27,12 +27,13 @@ with builtins; environment = { systemPackages = with pkgs; [ - + nushellFull networkmanager htmlq wget git neofetch pciutils zip unzip gnutar iw btop nodejs jdk8 jdk11 jdk libsecret gh nix-prefetch-scripts fzf glab ripgrep sl lolcat appimage-run git-crypt file whois p7zip file nmap cmatrix tree - socat smartmontools + socat smartmontools mprocs + dig aria2 usbutils ]; }; @@ -101,7 +102,7 @@ with builtins; users.users.jade = { isNormalUser = true; - extraGroups = [ "wheel" "input" "uinput" "libvirtd" "adbusers" "dialout" "plugdev" ]; + extraGroups = [ "wheel" "input" "uinput" "libvirtd" "adbusers" "dialout" "plugdev" "wireshark" ]; packages = [ pkgs.marksman ]; diff --git a/flake.nix b/flake.nix index c995e65..a1f7382 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,7 @@ # nixpkgs.url = "nixpkgs/nixos-22.11"; nixpkgs-stable.url = "nixpkgs/nixos-23.05"; home-manager = { - url = "github:nix-community/home-manager/release-22.11"; + url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; nixos-hardware.url = "github:networkException/nixos-hardware/apple-t2-init"; diff --git a/haskell/xmonad/xmonad.hs b/haskell/xmonad/xmonad.hs index 4044d80..2ec0677 100644 --- a/haskell/xmonad/xmonad.hs +++ b/haskell/xmonad/xmonad.hs @@ -13,6 +13,7 @@ import System.Exit import XMonad.Hooks.StatusBar import XMonad.Hooks.StatusBar.PP +import XMonad.Hooks.EwmhDesktops import qualified XMonad.StackSet as W import qualified Data.Map as M @@ -76,23 +77,7 @@ myRemaps = KeymapTable [ ((0, xK_a), (0, xK_b)) ] myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $ [ ((modm, xK_Return), spawn $ XMonad.terminal conf) , ((modm .|. shiftMask, xK_q), kill) - -- Rotate through the available layout algorithms - , ((modm, xK_space ), sendMessage NextLayout) - -- rofiing - , ((modm, xK_d), spawn "rofi -show drun") - , ((modm .|. shiftMask, xK_e), spawn "rofi -show \"desktopctl\" -modes \"desktopctl:$(which desktopctl)\"") - , ((modm, xK_m), spawn "menu-qalc") - , ((modm, xK_i), spawn "rofimoji -f alchemical_symbols anatolian_hieroglyphs emojis braille_patterns box_drawing chess_symbols emoticons geometric_shapes gothic greek_extended math mathematical_alphanumeric_symbols mathematical_operators miscellaneous_symbols miscellaneous_mathematical_symbols-a miscellaneous_mathematical_symbols-b miscellaneous_symbols_and_arrows miscellaneous_symbols_and_pictographs miscellaneous_technical modi modifier_tone_letters musical_symbols nerd_font number_forms shorthand_format_controls specials variation_selectors vertical_forms -a copy") - -- screenshotting - -- TODO: Fix/rewrite window-screenshot.sh - , ((modm, xK_w), spawn "window-screenshot.sh") - , ((modm, xK_s), spawn "flameshot gui -c -p $HOME/Pictures/screenshots") - , ((modm, xK_a), spawn "flameshot screen -c -p $HOME/Pictures/screenshots") - , ((modm, xK_t), spawn "ocr-screenshot.sh") - - [ ((modm, xK_Return), spawn $ XMonad.terminal conf) - , ((modm .|. shiftMask, xK_q), kill) - -- Rotate through the available layout algorithms + -- -- Rotate through the available layout algorithms , ((modm, xK_space ), sendMessage NextLayout) -- rofiing @@ -105,7 +90,7 @@ myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $ -- screenshotting -- TODO: Fix/rewrite window-screenshot.sh - , ((modm, xK_w), spawn "window-screenshot.sh") + , ((modm, xK_w), spawn "window-screenshot.nu") , ((modm, xK_s), spawn "flameshot gui -c -p $HOME/Pictures/screenshots") , ((modm, xK_a), spawn "flameshot screen -c -p $HOME/Pictures/screenshots") , ((modm, xK_t), spawn "ocr-screenshot.sh") @@ -306,7 +291,7 @@ myStartupHook = do -- Run xmonad with the settings you specify. No need to modify this. -- mySB = statusBarProp "polybar" (pure xmobarPP) -main = xmonad $ withEasySB mySB defToggleStrutsKey defaults +main = xmonad $ withEasySB mySB defToggleStrutsKey (ewmh defaults) -- A structure containing your configuration settings, overriding -- fields in the default config. Any you don't override, will diff --git a/hosts/catbook-j/configuration.nix b/hosts/catbook-j/configuration.nix index 870e47c..12aaed4 100644 --- a/hosts/catbook-j/configuration.nix +++ b/hosts/catbook-j/configuration.nix @@ -53,6 +53,11 @@ in { device = "DELL081C:00 044E:121F Mouse"; sensitivity = 255; }; + hardware.usbWwan.enable = true; + systemd.services."ModemManager".enable = true; + systemd.services."ModemManager".wants = [ "NetworkManager.service" ]; + systemd.services."ModemManager".wantedBy = [ "multi-user.target" ]; + programs.wireshark.enable = true; boot.resumeDevice = "/dev/disk/by-uuid/4f9e8afa-f8d7-40bf-b3ea-17e8e8fbb694"; boot.kernelParams = [ "resume_offset=7380652" ]; @@ -64,7 +69,7 @@ in { services.xserver.libinput.touchpad.tapping = false; - environment.systemPackages = [ pkgs.vivaldi pkgs.vivaldi-ffmpeg-codecs pkgs.plantuml ]; + environment.systemPackages = [ pkgs.vivaldi pkgs.vivaldi-ffmpeg-codecs pkgs.plantuml pkgs.mqttui pkgs.mobile-broadband-provider-info pkgs.modem-manager-gui pkgs.wireshark]; # Bootloader. boot.loader.systemd-boot.enable = true; diff --git a/justfile b/justfile new file mode 100644 index 0000000..18dab21 --- /dev/null +++ b/justfile @@ -0,0 +1,5 @@ +test: + sudo nixos-rebuild test --flake . --impure + +build: + sudo nixos-rebuild switch --flake . --impure diff --git a/modules/desktop/audio.nix b/modules/desktop/audio.nix index f015427..e61b48e 100644 --- a/modules/desktop/audio.nix +++ b/modules/desktop/audio.nix @@ -13,6 +13,7 @@ jack.enable = true; }; }; + hardware.pulseaudio.enable = pkgs.lib.mkForce false; sound.mediaKeys.enable = true; home-manager.users.jade = { pkgs, ... }: { home.packages = with pkgs; [ diff --git a/modules/desktop/default.nix b/modules/desktop/default.nix index 2e439f6..563288d 100644 --- a/modules/desktop/default.nix +++ b/modules/desktop/default.nix @@ -2,6 +2,7 @@ let cfg = config.jade.desktop; + # window-screenshot = pkgs.writeTextFile "window-screenshot.nu" (builtins.readFile ../../other/scripts/desktop/window-screenshot.nu); window-screenshot = pkgs.writeShellScriptBin "window-screenshot.sh" (builtins.readFile ../../other/scripts/desktop/window-screenshot.sh); # desktop-ctl = pkgs.writeShellScriptBin "desktop-ctl.sh" (builtins.readFile ../scripts/desktop/desktop-ctl.sh); desktop-ctl = import ../../other/scripts/desktop/desktopctl.nix { inherit pkgs; }; @@ -102,10 +103,13 @@ in with lib; { desktopManager = { xterm.enable = false; + # gnome = { + # enable = true; + # }; }; displayManager = { - #defaultSession = "none+i3"; + defaultSession = "none+xmonad"; gdm.enable = true; }; @@ -187,11 +191,17 @@ in with lib; { theme = ../../other/rofi-themes/applauncher.rasi; }; home.packages = with pkgs; [ + spotifyd spotify-tui + #nushell nu_scripts direnv + just bacon + magic-wormhole-rs + yt-dlp + argyllcms displaycal @@ -201,11 +211,13 @@ in with lib; { i3lock rofimoji feh xorg.xinput arandr flameshot tesseract5 imagemagick xclip xmacro libwacom wacomtablet xorg.xev + syncplay + # categories # filemanager xfce.thunar xfce.tumbler xfce.thunar-archive-plugin gnome.file-roller # media/file viewers - vlc evince nomacs + vlc mpv evince nomacs # from environment.systemPackages cleanup font-manager xdotool xorg.xwininfo gparted librewolf firefox uhk-agent diff --git a/modules/desktop/networking.nix b/modules/desktop/networking.nix index 2c761db..7a62d05 100644 --- a/modules/desktop/networking.nix +++ b/modules/desktop/networking.nix @@ -1,34 +1,60 @@ { config, lib, pkgs, ... }: -{ +let + addNuShebang = path: builtins.concatStringsSep "\n\n" [ + "#!${pkgs.nushellFull}/bin/nu" + (builtins.readFile path) + ]; +in { config = { networking = { - networkmanager.wifi.backend = "wpa_supplicant"; - extraHosts = '' - 127.0.0.1 www.youtube.com - 127.0.0.1 www.reddit.com - 127.0.0.1 www.tiktok.com - 127.0.0.1 www.twitter.com - 127.0.0.1 www.instagram.com - 127.0.0.1 www.facebook.com - 127.0.0.1 www.snapchat.com + networkmanager = { + wifi.backend = "wpa_supplicant"; + dispatcherScripts = [ + { + type = "basic"; + source = pkgs.writeText "dispatcher" (addNuShebang ../../other/scripts/dispatcher.nu); + } + ]; + }; + hosts = { + "127.0.0.1" = [ + "www.tiktok.com" + "www.twitter.com" + "www.instagram.com" + "www.facebook.com" + "www.snapchat.com" - 127.0.0.1 youtube.com - 127.0.0.1 reddit.com - 127.0.0.1 tiktok.com - 127.0.0.1 twitter.com - 127.0.0.1 instagram.com - 127.0.0.1 facebook.com - 127.0.0.1 snapchat.com + "tiktok.com" + "twitter.com" + "instagram.com" + "facebook.com" + "snapchat.com" - 127.0.0.1 google-analytics.com - 127.0.0.1 stats.g.doubleclick.net - 127.0.0.1 googleadservices.com - 127.0.0.1 googletagmanager.com - 127.0.0.1 googletagservices.com - 127.0.0.1 googlesyndication.com - ''; + "google-analytics.com" + "stats.g.doubleclick.net" + "googleadservices.com" + "googletagmanager.com" + "googletagservices.com" + "googlesyndication.com" + ]; + "10.31.208.9" = [ + "mqtt.z9" + ]; + }; }; + environment.etc = (with builtins; ( + listToAttrs ( + map (v: { + name = "networkhooks/${v}"; + value = { + text = addNuShebang ../../other/scripts/networkhooks/${v}; + mode = "0755"; + }; + }) + (attrNames (readDir ../../other/scripts/networkhooks)) + ) + )); systemd.services."NetworkManager-wait-online".enable = false; services.mullvad-vpn.enable = true; home-manager.users.jade = { pkgs, ... }: { diff --git a/modules/helix.nix b/modules/helix.nix index 737fe80..5c61508 100644 --- a/modules/helix.nix +++ b/modules/helix.nix @@ -30,16 +30,16 @@ in with lib; { space."=" = ":fmt"; }; }; - languages = [ - { + languages = { + "php" = { name = "php"; file-types = [ "php" ]; language-server = { command = "psalm"; args = ["--language-server"]; }; - } - ]; + }; + }; }; }; }; diff --git a/modules/utils.nix b/modules/utils.nix new file mode 100644 index 0000000..566dbe4 --- /dev/null +++ b/modules/utils.nix @@ -0,0 +1,49 @@ +{ pkgs, lib }: rec { + # taken from https://github.com/NixOS/nixpkgs/blob/3650808d85dccbfa3be3d785dfd3ce33a757bd2c/pkgs/build-support/trivial-builders/default.nix#L335 + writeNuShellApplication = + { name + , text + , runtimeInputs ? [ ] + , meta ? { } + , checkPhase ? null + }: + writeTextFile { + inherit name meta; + executable = true; + destination = "/bin/${name}"; + allowSubstitutes = true; + preferLocalBuild = false; + text = '' + #!${pkgs.nushell} + '' + lib.optionalString (runtimeInputs != [ ]) '' + + $env.PATH = ($env.PATH | split row (char esep) | prepend '${lib.makeBinPath runtimeInputs}'); + '' + '' + + ${text} + ''; + + checkPhase = + # GHC (=> shellcheck) isn't supported on some platforms (such as risc-v) + # but we still want to use writeShellApplication on those platforms + if checkPhase == null then '' + runHook preCheck + + nu -c "nu-check -d $target" + + runHook postCheck + '' + else checkPhase; + }; + packageNushellApplication = + { name + , path + , runtimeInputs ? [ ] + , meta ? { } + , checkPhase ? null + }: + writeNuShellApplication { + inherit name runtimeInputs meta checkPhase; + text = builtins.readFile path; + }; +} diff --git a/modules/zellij.nix b/modules/zellij.nix index 2e45cd6..7472324 100644 --- a/modules/zellij.nix +++ b/modules/zellij.nix @@ -6,12 +6,22 @@ in with lib; { }; config = mkIf cfg.enable { home-manager.users.jade = { pkgs, ... }: { + home.file = { + zellij-forgot = { + target = ".config/zellij/plugins/zellij-forgot.wasm"; + source = builtins.fetchurl "https://github.com/karimould/zellij-forgot/releases/download/0.2.0/zellij_forgot.wasm"; + }; + monocle = { + target = ".config/zellij/plugins/monocle.wasm"; + source = builtins.fetchurl "https://github.com/imsnif/monocle/releases/download/0.37.2/monocle.wasm"; + }; + }; programs.zellij = { enable = true; settings = { theme = "gruvbox-dark"; themes.gruvbox-dark = { - fg = "#D5C4A1"; + fg = "#d5c4a1"; bg = "#282828"; black = "#3C3836"; red = "#CC241D"; @@ -20,9 +30,16 @@ in with lib; { blue = "#3C8588"; magenta = "#B16286"; cyan = "#689D6A"; - white = "#FBF1C7"; + white = "#665c54"; orange = "#D65D0E"; }; + # keybinds = { + # session = { + # "bind \"o\"" = { + # LaunchOrFocusPlugin = ["file:/home/jade/.config/zellij/plugins/monocle.wasm" { floating = true; }]; + # }; + # }; + # }; pane_frames = false; }; }; diff --git a/other/config.nu b/other/config.nu index c0a1e82..cd8e7a9 100644 --- a/other/config.nu +++ b/other/config.nu @@ -247,9 +247,21 @@ $env.config = { hooks: { pre_prompt: [{ || - let direnv = (direnv export json | from json) - let direnv = if ($direnv | length) == 1 { $direnv } else { {} } - $direnv | load-env + let direnv = (direnv export json | from json | default {}) + if ($direnv | is-empty) { + return + } + $direnv + | items {|key, value| + { + key: $key + value: (if $key in $env.ENV_CONVERSIONS { + do ($env.ENV_CONVERSIONS | get $key | get from_string) $value + } else { + $value + }) + } + } | transpose -ird | load-env }] # run before the prompt is shown pre_execution: [{ null }] # run before the repl input is run env_change: { @@ -793,3 +805,5 @@ start_zellij alias gnix = cd ~/nix-configs; alias grepo = cd ~/Documents/repos; alias wh = wormhole-rs; +alias nix-shell = nix-shell --run 'nu -li'; +alias nsp = nix-shell --run 'nu -li' -p; diff --git a/other/scripts/desktop/window-screenshot.nu b/other/scripts/desktop/window-screenshot.nu new file mode 100644 index 0000000..89785b2 --- /dev/null +++ b/other/scripts/desktop/window-screenshot.nu @@ -0,0 +1,19 @@ +#!/usr/bin/env nu + +def main [ ] { + let reg = ( + xwininfo -id (xdotool getactivewindow) + | lines + | parse '{key}: {value}' + | str trim + | get value + | echo { + x: $in.1 + y: $in.2 + w: $in.5 + h: $in.6 + } + ); + + flameshot gui --region $"($reg.w)x($reg.h)+($reg.x)+($reg.y)" -c -p ~/Pictures/screenshots +} \ No newline at end of file diff --git a/other/scripts/dispatcher.nu b/other/scripts/dispatcher.nu new file mode 100755 index 0000000..f4e9f71 --- /dev/null +++ b/other/scripts/dispatcher.nu @@ -0,0 +1,19 @@ +def main [ + interface: string + type: string +] { + $env.PATH = ($env.PATH | split row (char esep) | append '/run/current-system/sw/bin'); + + let currentnet = ( + nmcli -m tabular connection show --active + | detect columns + | first + | get name + ); + + systemd-cat echo $"($currentnet) \(($interface)): ($type)"; + + if $interface == 'wlp2s0' { + ^$"/etc/networkhooks/($currentnet).nu" $interface $type + } +} diff --git a/other/scripts/networkhooks/WIFI@DB.nu b/other/scripts/networkhooks/WIFI@DB.nu new file mode 100755 index 0000000..dd0390d --- /dev/null +++ b/other/scripts/networkhooks/WIFI@DB.nu @@ -0,0 +1,40 @@ +def main [ + interface: string + type: string +] { + if not ($type == 'up') { + exit + }; + + mullvad disconnect; + let page = http get 'http://172.0.0.1/'; + + let hotspot_ip = $page | htmlq 'input[name=uamip]' -a 'value'; + let hotspot_port = $page | htmlq 'input[name=uamport]' -a 'value'; + + let pl_data = $page + | htmlq input -a name -r input[name=button] + | lines + | wrap name + | merge ( + $page + | htmlq input -a value + | lines + | wrap value + ) + | drop 1; + + let payload = $pl_data + | each {|kv| [ + ($kv.name | url encode --all) + ($kv.value | url encode --all) ] + | str join '=' + } | str join '&'; + + let res = curl --insecure --resolve $"www.hotsplots.de:($hotspot_port):($hotspot_ip)" -H 'Content-Type: application/x-www-form-urlencoded' "https://www.hotsplots.de/auth/login.php" --data-raw $"($payload)" ; + + let url = $res | htmlq 'meta[http-equiv=refresh]' -a 'content' | parse '0;url={url}'; + + http get $url.url.0; + mullvad connect; +} diff --git a/other/scripts/networkhooks/WIFIonICE.nu b/other/scripts/networkhooks/WIFIonICE.nu new file mode 100644 index 0000000..2de9902 --- /dev/null +++ b/other/scripts/networkhooks/WIFIonICE.nu @@ -0,0 +1,22 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p curl htmlq + +# echo "Fetching cookie and CSRF token..." +# form=$(curl --silent --location --junk-session-cookies --cookie-jar /tmp/wifionice "https://login.wifionice.de/en/" --resolve login.wifionice.de:443:10.101.64.10 -i | htmlq "input") + +# keys=$(htmlq "input" --attribute "name" <<< "$form") +# values=$(htmlq "input" --attribute "value" <<< "$form") +# payload=$(paste --delimiters="=" <(echo "$keys") <(echo "$values") | tr "\n" "&") + +# echo "Payload: \"$payload\"" +# echo "POSTing payload..." + +# curl --cookie /tmp/wifionice "https://login.wifionice.de/en/" --resolve login.wifionice.de:443:10.101.64.10 -d "$payload" + +def main [ + interface: string + type: string +] { + let form = curl --silent --location --junk-session-cookies --cookie-jar /tmp/wifionice 'https://login.wifionice.de/en/' --resolve 'login.wifionice.de:443:10.101.64.10' -i | htmlq 'input'; + # TODO +} diff --git a/other/scripts/networkhooks/ccchh.nu b/other/scripts/networkhooks/ccchh.nu new file mode 100644 index 0000000..bce6e8e --- /dev/null +++ b/other/scripts/networkhooks/ccchh.nu @@ -0,0 +1,41 @@ +const wave_timeout = 15min; + +def main [ + interface: string + type: string +] { + if not ('/var/lib/ccchh-winken/last' | path exists) { + mkdir '/var/lib/ccchh-winken'; + 0 | into datetime | save '/var/lib/ccchh-winken/last' -f; + } + + let $last_waved = open '/var/lib/ccchh-winken/last' --raw | into datetime; + + if ((date now) - $last_waved) > $wave_timeout { + if $type == "up" { + mullvad disconnect; + curl mqtt://mqtt.z9/winkekatze/katz9/eye/set -d (rand-color); + curl mqtt://mqtt.z9/winkekatze/Viktoria/eye/set -d (rand-color); + curl mqtt://mqtt.z9/winkekatze/allcats -d 'wink'; + mullvad connect; + + date now | save '/var/lib/ccchh-winken/last' -f; + } + } +} + +def rand-color [] { + const colors = [ + "blue" + "cyan" + "green" + "pink" + "red" + "white" + "yellow" + ]; + + $colors | get (random integer 0..(($colors | length) - 1)) +} + + diff --git a/test.sh b/test.sh deleted file mode 100755 index f6cda85..0000000 --- a/test.sh +++ /dev/null @@ -1 +0,0 @@ -sudo nixos-rebuild test --flake . --impure