Skip to content

Commit 0e5aa14

Browse files
committed
feat: add network manager
1 parent 9bc13c6 commit 0e5aa14

File tree

4 files changed

+100
-20
lines changed

4 files changed

+100
-20
lines changed

hosts/Default/variables.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
desktop = "hyprland"; # hyprland, i3-gaps, gnome, plasma6
66

77
# Theme & Appearance
8-
waybarTheme = "stylish"; # stylish, minimal
8+
waybarTheme = "minimal"; # stylish, minimal
99
sddmTheme = "astronaut"; # astronaut, black_hole, purple_leaves, jake_the_dog, hyprland_kath
1010
defaultWallpaper = "kurzgesagt.webp"; # Change with SUPER + SHIFT + W
1111
hyprlockWallpaper = "evening-sky.webp";

modules/desktop/hyprland/programs/waybar/stylish.nix

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ in
1818
exclusive = true;
1919
passthrough = false;
2020
gtk-layer-shell = true;
21+
reload_style_on_change = true;
2122
ipc = true;
2223
fixed-center = true;
2324
margin-top = 0;
@@ -72,7 +73,7 @@ in
7273
orientation = "horizontal";
7374
modules = [
7475
"custom/trigger"
75-
"custom/user"
76+
# "custom/user"
7677
"tray"
7778
# "wlr/taskbar"
7879
];
@@ -178,7 +179,8 @@ in
178179

179180
"custom/distro" = {
180181
format = "";
181-
tooltip = false;
182+
tooltip = true;
183+
tooltip-format = "I use NixOS, btw.";
182184
};
183185

184186
"idle_inhibitor" = {
@@ -318,23 +320,10 @@ in
318320
headset = "󰋎";
319321
headset-muted = "󰋐";
320322
};
321-
# "rotate":
322-
# "states":
323323
min-length = 7;
324324
max-length = 7;
325-
# "scroll-step":
326-
on-click = "~/.config/waybar/scripts/volume.sh output mute";
327-
# "on-click-middle":
328-
# "on-click-right":
329-
on-scroll-up = "~/.config/waybar/scripts/volume.sh output raise";
330-
on-scroll-down = "~/.config/waybar/scripts/volume.sh output lower";
331-
# "smooth-scrolling-threshold":
332-
# "tooltip":
325+
on-click = "pavucontrol -t 3";
333326
tooltip-format = "Output Device: {desc}";
334-
# "max-volume":
335-
# "ignored-sinks":
336-
# "reverse-scrolling":
337-
# "reverse-mouse-scrolling":
338327
};
339328

340329
"pulseaudio#input" = {
@@ -344,7 +333,8 @@ in
344333
min-length = 7;
345334
max-length = 7;
346335
scroll-step = 1;
347-
on-click = "pamixer --default-source --toggle-mute";
336+
on-click = "pavucontrol -t 4";
337+
# on-click = "pamixer --default-source --toggle-mute";
348338
tooltip-format = "Input Device: {desc}";
349339
};
350340

@@ -565,7 +555,7 @@ in
565555
}
566556
567557
#waybar {
568-
background-color: @outline;
558+
background-color: @main-bg;
569559
}
570560
571561
#waybar > box {
@@ -677,7 +667,7 @@ in
677667
color: @accent;
678668
}
679669
#custom-distro {
680-
padding: 0 13px 0 5px;
670+
padding: 0 12px 0 4px;
681671
background-color: @accent;
682672
color: @main-bg;
683673
}

modules/scripts/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let
2424
(import ./rebuild.nix scriptArgs)
2525
(import ./rollback.nix scriptArgs)
2626
(import ./launcher.nix scriptArgs)
27+
(import ./network.nix scriptArgs)
2728
(import ./tmux-sessionizer.nix scriptArgs)
2829
(import ./extract.nix scriptArgs)
2930
(import ./driverinfo.nix scriptArgs)

modules/scripts/network.nix

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{ pkgs, ... }:
2+
pkgs.writeShellScriptBin "network" ''
3+
RED='\033[1;31m'
4+
RST='\033[0m'
5+
6+
TIMEOUT=5
7+
8+
get-network-list() {
9+
nmcli device wifi rescan 2> /dev/null
10+
11+
local i
12+
for ((i = 1; i <= TIMEOUT; i++)); do
13+
printf '\rScanning for networks...'
14+
15+
list=$(timeout 1 nmcli device wifi list)
16+
networks=$(tail -n +2 <<< "$list" | awk '$2 != "--"')
17+
18+
[[ -n $networks ]] && break
19+
done
20+
21+
printf '\n%bScanning Finished.%b\n\n' "$RED" "$RST"
22+
23+
if [[ -z $networks ]]; then
24+
notify-send "Wi-Fi" -e -t 2500 -u low "No networks found" -i "package-broken"
25+
tput cnorm
26+
return 1
27+
fi
28+
}
29+
30+
select-network() {
31+
local header
32+
header=$(head -n 1 <<< "$list")
33+
34+
# shellcheck disable=SC1090
35+
36+
local opts=(
37+
--border=sharp
38+
--border-label=' Wi-Fi Networks '
39+
--ghost='Search'
40+
--header="$header"
41+
--height=~100%
42+
--highlight-line
43+
--info=inline-right
44+
--pointer=
45+
--reverse
46+
)
47+
48+
bssid=$(fzf "''${opts[@]}" <<< "$networks" | awk '{print $1}')
49+
50+
if [[ -z $bssid ]]; then
51+
return 1
52+
elif [[ $bssid == '*' ]]; then
53+
notify-send "Wi-Fi" -e -t 2500 -u low "Already connected to this network" \
54+
-i 'package-install'
55+
return 1
56+
fi
57+
}
58+
59+
connect-to-network() {
60+
printf 'Connecting...\n'
61+
62+
nmcli --ask device wifi connect "$bssid"
63+
if nmcli --ask device wifi connect "$bssid"; then
64+
return
65+
# notify-send "Wi-Fi" -e -t 2500 -u low "Successfully connected" -i "package-install"
66+
else
67+
notify-send "Wi-Fi" -e -t 2500 -u low "Failed to connect" -i "package-purge"
68+
fi
69+
}
70+
71+
main() {
72+
local status
73+
status=$(nmcli radio wifi)
74+
75+
if [[ $status == 'disabled' ]]; then
76+
nmcli radio wifi on
77+
notify-send "Wi-Fi Enabled" -e -t 2500 -u low -r 1125 -i "network-wireless-on"
78+
fi
79+
80+
tput civis # make cursor invisible
81+
get-network-list || exit 1
82+
tput cnorm # make cursor visible
83+
84+
select-network || exit 1
85+
connect-to-network
86+
}
87+
88+
main
89+
''

0 commit comments

Comments
 (0)