Skip to content

Commit

Permalink
add: awg-gui test
Browse files Browse the repository at this point in the history
  • Loading branch information
Askodon committed Nov 19, 2024
1 parent 894bdb2 commit 3900919
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 19 deletions.
2 changes: 2 additions & 0 deletions home/programs/gtk-qt-theme/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
bibata-cursors
libsForQt5.qt5ct
libsForQt5.qtstyleplugin-kvantum
glib
gsettings-desktop-schemas
];

imports = [ ./dconf-settings.nix ];
Expand Down
3 changes: 2 additions & 1 deletion home/programs/hyprland/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
wayland.windowManager.hyprland = {
enable = true;
xwayland.enable = true;
#package = inputs.hyprland.packages.${pkgs.system}.hyprland; # add this, after fix libinput 1.26.0
#package = inputs.hyprland.packages.${pkgs.system}.hyprland; # add this, after fix libinput 1.26.0
plugins = with pkgs.hyprlandPlugins; [ hyprspace ];
systemd.enable = true;
systemd.variables = [ "--all" ];
extraConfig = ''
Expand Down
120 changes: 120 additions & 0 deletions home/programs/nix-scripts/awg-gui.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
pkgs,
python3,
python312Packages.pygobject3,
gtk3,
glib,
...
}:
pkgs.writeScriptBin "awg-gui" ''
#!/usr/bin/env python3
import gi
import subprocess
import threading
from gi.repository import Gtk, Gdk
gi.require_version("Gtk", "3.0")
class VPNApp(Gtk.Window):
def __init__(self):
super().__init__(title="VPN Control")
self.set_border_width(10)
self.set_default_size(300, 200)
# Create a vertical container
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
self.add(vbox)
# Title
title_label = Gtk.Label(label="VPN Control")
title_label.set_justify(Gtk.Justification.CENTER)
title_label.set_margin_bottom(10)
vbox.pack_start(title_label, True, True, 0)
# Status indicator
self.status_label = Gtk.Label(label="VPN is disabled")
self.status_label.set_justify(Gtk.Justification.CENTER)
self.status_label.set_margin_bottom(10)
vbox.pack_start(self.status_label, True, True, 0)
# Password entry
self.password_entry = Gtk.Entry()
self.password_entry.set_visibility(False) # Hide password
self.password_entry.set_placeholder_text("Enter VPN password")
vbox.pack_start(self.password_entry, True, True, 0)
# Button to enable VPN
self.enable_button = Gtk.Button(label="Enable VPN")
self.enable_button.connect("clicked", self.on_enable_vpn)
vbox.pack_start(self.enable_button, True, True, 0)
# Button to disable VPN
self.disable_button = Gtk.Button(label="Disable VPN")
self.disable_button.connect("clicked", self.on_disable_vpn)
vbox.pack_start(self.disable_button, True, True, 0)
# Set button styles
self.enable_button.set_name("enable-button")
self.disable_button.set_name("disable-button")
# Set CSS for styles
self.apply_css()
def apply_css(self):
css = """
button {
padding: 10px;
font-size: 16px;
border-radius: 5px;
}
#enable-button {
background-color: #4CAF50; /* Green */
color: white;
}
#disable-button {
background-color: #f44336; /* Red */
color: white;
}
"""
style_provider = Gtk.CssProvider()
style_provider.load_from_data(css.encode('utf-8')) # Encode string to bytes
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER
)
def on_enable_vpn(self, widget):
password = self.password_entry.get_text()
self.run_vpn_command(["sudo", "-S", "awg-quick", "up", "/home/askodon/amnezia/awg.conf"], password)
def on_disable_vpn(self, widget):
self.run_vpn_command(["sudo", "-S", "awg-quick", "down", "/home/askodon/amnezia/awg.conf"])
def run_vpn_command(self, command, password=None):
def target():
process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if password:
# Send password to the process if needed
output, error = process.communicate(input=password + "\n")
else:
output, error = process.communicate()
# Update the status label based on the output
if process.returncode == 0:
self.status_label.set_text("VPN command executed successfully")
else:
self.status_label.set_text(f"Error: {error.strip()}")
# Run the command in a separate thread to avoid blocking the UI
threading.Thread(target=target).start()
if __name__ == "__main__":
app = VPNApp()
app.connect("destroy", Gtk.main_quit)
app.show_all()
Gtk.main()
'';


3 changes: 2 additions & 1 deletion home/programs/nix-scripts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ let
powerMenuArtemis = import ./powerMenuArtemis.nix { inherit pkgs; };
screenshotArtemis = import ./screenshotArtemis.nix { inherit pkgs; };
breakTime = import ./breakTime.nix { inherit pkgs; };

awg-gui = import ./awg-gui.nix { inherit pkgs; };
github = import ./github.nix { inherit pkgs; };

in

{
home.packages = [
awg-gui
screenshotArtemis
powerMenuArtemis
breakTime
Expand Down
1 change: 1 addition & 0 deletions home/programs/shell/zellij.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
text = ''
bind "Alt g" { SwitchToMode "locked"; }
default_shell "nu"
pane_frames false
keybinds {
normal clear-defaults=true {
bind "Ctrl b" { SwitchToMode "Tmux"; }
Expand Down
28 changes: 11 additions & 17 deletions nixos/hardware-configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@
{ config, lib, pkgs, modulesPath, ... }:

{
imports =
[ (modulesPath + "/installer/scan/not-detected.nix")
];
imports = [ ];

boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usbhid" "sd_mod" ];
boot.initrd.kernelModules = [ "amdgpu" ];
boot.kernelModules = [ "amdgpu" ];
boot.initrd.availableKernelModules = [ "sd_mod" ];
boot.initrd.kernelModules = [ ];
boot.blacklistedKernelModules = [ "hyperv_fb" ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];

fileSystems."/" =
{ device = "/dev/disk/by-uuid/a338c142-d383-4567-a906-29c47bf7f5a9";
{ device = "/dev/disk/by-uuid/2405d72b-02c0-438d-9a0b-5f62c3011497";
fsType = "ext4";
};

fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/7715-EA31";
{ device = "/dev/disk/by-uuid/3D42-C109";
fsType = "vfat";
options = [ "fmask=0022" "dmask=0022" ];
};

fileSystems."/home/askodon/mnt" =
{ device = "/dev/disk/by-uuid/11455f09-c52b-44c9-8048-53a5b53dcaae";
fsType = "xfs";
options = [ "fmask=0077" "dmask=0077" ];
};

swapDevices = [ ];
Expand All @@ -36,9 +30,9 @@
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.enp8s0.useDHCP = lib.mkDefault true;
# networking.interfaces.zt44xhtvio.useDHCP = lib.mkDefault true;
# networking.interfaces.eth0.useDHCP = lib.mkDefault true;
# networking.interfaces.tailscale0.useDHCP = lib.mkDefault true;

nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
#hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
virtualisation.hypervGuest.enable = true;
}

0 comments on commit 3900919

Please sign in to comment.