From fc1df2b684feebde9d5d625c7cbb2fa9074988f0 Mon Sep 17 00:00:00 2001 From: Tyler Kelley Date: Thu, 15 Feb 2024 22:17:08 -0600 Subject: [PATCH] Working on Zaney Control Center and added flatpak service for enabling FlatHub --- config/home/bash.nix | 7 ++- config/home/hyprland.nix | 3 - config/home/packages.nix | 2 +- config/scripts/zcc.nix | 126 +++++++++++++++++++++++++++++++++----- config/system/boot.nix | 1 + config/system/flatpak.nix | 10 ++- options.nix | 2 + 7 files changed, 129 insertions(+), 22 deletions(-) diff --git a/config/home/bash.nix b/config/home/bash.nix index 594fd63..a267d55 100644 --- a/config/home/bash.nix +++ b/config/home/bash.nix @@ -1,6 +1,6 @@ { config, lib, pkgs, ... }: -let inherit (import ../../options.nix) flakeDir theShell; in +let inherit (import ../../options.nix) flakeDir flakePrev flakeBackup theShell; in lib.mkIf (theShell == "bash") { # Configure Bash programs.bash = { @@ -18,7 +18,10 @@ lib.mkIf (theShell == "bash") { fi ''; sessionVariables = { - + FLAKEDIR = "${flakeDir}"; + ZANEYOS = true; + FLAKEBACKUP = "${flakeBackup}"; + FLAKEPREV = "${flakePrev}"; }; shellAliases = { sv="sudo nvim"; diff --git a/config/home/hyprland.nix b/config/home/hyprland.nix index 1ee10c9..5d0509a 100644 --- a/config/home/hyprland.nix +++ b/config/home/hyprland.nix @@ -53,8 +53,6 @@ in with lib; { env = GDK_BACKEND, wayland env = CLUTTER_BACKEND, wayland env = SDL_VIDEODRIVER, ${sdl-videodriver} - env = XCURSOR_SIZE, 24 - env = XCURSOR_THEME, Bibata-Modern-Ice env = QT_QPA_PLATFORM, wayland env = QT_WAYLAND_DISABLE_WINDOWDECORATION, 1 env = QT_AUTO_SCREEN_SCALE_FACTOR, 1 @@ -113,7 +111,6 @@ in with lib; { exec-once = $POLKIT_BIN exec-once = dbus-update-activation-environment --systemd --all exec-once = systemctl --user import-environment QT_QPA_PLATFORMTHEME WAYLAND_DISPLAY XDG_CURRENT_DESKTOP - exec-once = hyprctl setcursor Bibata-Modern-Ice 24 exec-once = swww init exec-once = waybar exec-once = swaync diff --git a/config/home/packages.nix b/config/home/packages.nix index 0966bc7..d537977 100644 --- a/config/home/packages.nix +++ b/config/home/packages.nix @@ -23,7 +23,7 @@ in { (import ./../scripts/web-search.nix { inherit pkgs; }) (import ./../scripts/rofi-launcher.nix { inherit pkgs; }) (import ./../scripts/screenshootin.nix { inherit pkgs; }) - (import ./../scripts/zcc.nix { inherit pkgs; }) +# (import ./../scripts/zcc.nix { inherit pkgs; }) ]; programs.gh.enable = true; diff --git a/config/scripts/zcc.nix b/config/scripts/zcc.nix index a14eaa3..42edc82 100644 --- a/config/scripts/zcc.nix +++ b/config/scripts/zcc.nix @@ -1,25 +1,121 @@ { pkgs, ... }: let - inherit (import ../../options.nix) flakeDir; + inherit (import ../../options.nix) flakeDir flakePrev flakeBackup; in pkgs.writeShellScriptBin "zcc" '' - kdenlive=false + if [ "$#" -eq 0 ]; then + echo "The ZaneyOS Control Center requires an option like 'zcc [OPTION]'." + elif [ "$#" -eq 1 ]; then + if [ "$ZANEYOS" = true ]; then + choice="$1" + if [[ "$choice" = "update" ]]; then + # Add your update logic here + # If ~/zaneyos-previous exists, backup the configuration + if [[ -d ${flakePrev} ]]; then + # Check if ~/zaneyos-backup exists, otherwise create it + if [[ ! -d ${flakeBackup} ]]; then + mkdir ${flakeBackup} + fi - # Function to toggle the boolean variable - toggle_kdenlive() { - kdenlive=$(yad --width=200 --height=100 --title="Toggle Kdenlive" \ - --text="Toggle Kdenlive" --button="Toggle:0" --button="Cancel:1" \ - --checkbox --value="$kdenlive") + # Create a unique backup folder name with date and time + backup_folder=${flakeBackup}/$(date +"%Y%m%d%H%M%S") - # If the user clicks "Toggle" button, update the boolean value - if [ "$?" -eq 0 ]; then - echo "Kdenlive is now set to: $kdenlive" + # Backup previous configuration + sudo mv ${flakePrev} "$backup_folder" + echo "---" + echo "Previous configuration saved in $backup_folder" + fi + # Copy the previous repository + sudo cp -rp ${flakeDir} ${flakePrev} + echo "---" + echo "Actual configuration saved on $FLAKEPREV" + + # Change directory + cd ${flakeDir} || exit 1 + + # Run git status to get only modified, tracked but not committed files + files_to_check=$(git status -s --untracked-files=no | awk '{print $2}') + + # Stash changes and update the local repo from the remote one + echo "---" + echo "Updating zaneyos..." + git stash && git pull + + # Show files to check to the user + echo "---" + echo "Files to review:" + echo $files_to_check + + # Initialize the unresolved_files list + unresolved_files=() + + # Verify and overwrite files if the user confirms or save files to be manually reviewed + for file in $files_to_check; do + echo "---" + echo "Differences on $file:" + diff "$file" ~/zaneyos-previous/"$file" + echo "---" + read -p "Overwrite file $file with your? [Y/n]: " choice + case "$choice" in + *) + cp ~/zaneyos-previous/"$file" "$file" + ;; + n|N) + # Add the file to unresolved_files + unresolved_files+=("$file") + ;; + esac + done + + # If unresolved_files contains one or more files + if [[ ''${#unresolved_files[@]} -gt 0 ]]; then + # Show the user files to be manually reviewed and exit + echo "---" + echo "Review manually the following files:" + printf '%s\n' "''${unresolved_files[@]}" + else + # Prompt for updating flake.nix + echo "---" + read -p "Do you want to update flake? [Y/n]: " update_flake + update_flake=${update_flake:-Y} # Set Y as default option + if [[ $update_flake == [Yy] ]]; then + # Run flake-update + echo "---" + echo "Running flake-update..." + sudo nix flake update ~/zaneyos + # Prompt for system rebuild + echo "---" + read -p "Do you want to rebuild the system? [Y/n]: " rebuild_system + rebuild_system=${rebuild_system:-Y} # Set Y as default option + if [[ $rebuild_system == [Yy] ]]; then + # Run flake-rebuild + echo "---" + echo "Running flake-rebuild..." + sudo nixos-rebuild switch --flake ~/zaneyos + else + echo "---" + echo "Ok, the system will not be rebuilt" + fi + else + echo "---" + echo "Ok, flake will not be updated" + fi + fi + echo "---" + echo "Ok. Press any key to exit." + read -n 1 -s + + elif [[ "$choice" = "install" ]]; then + echo "Installing..." + # Add logic for when the user chooses not to update + else + echo "Invalid option. Try zcc update or zcc install" + fi else - echo "Toggle canceled. Kdenlive remains set to: $kdenlive" + echo "ZANEYOS is false" fi - } - - # Call the toggle function - toggle_kdenlive + else + echo "Too many arguments. Please provide one argument." + fi '' diff --git a/config/system/boot.nix b/config/system/boot.nix index 5766f74..60c3c24 100644 --- a/config/system/boot.nix +++ b/config/system/boot.nix @@ -4,6 +4,7 @@ # Bootloader boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; + boot.kernel.sysctl = { "vm.max_map_count" = 2147483642; }; # This is for OBS Virtual Cam Support - v4l2loopback setup boot.kernelModules = [ "v4l2loopback" ]; diff --git a/config/system/flatpak.nix b/config/system/flatpak.nix index 8893084..13d40ba 100644 --- a/config/system/flatpak.nix +++ b/config/system/flatpak.nix @@ -1,6 +1,14 @@ -{ config, lib, ... }: +{ pkgs, config, lib, ... }: let inherit (import ../../options.nix) flatpak; in lib.mkIf (flatpak == true) { services.flatpak.enable = true; + + systemd.services.flatpak-repo = { + wantedBy = [ "multi-user.target" ]; + path = [ pkgs.flatpak ]; + script = '' + flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo + ''; + }; } diff --git a/options.nix b/options.nix index cac89b5..82730b6 100644 --- a/options.nix +++ b/options.nix @@ -24,6 +24,8 @@ in { wallpaperDir = "${userHome}/Pictures/Wallpapers"; screenshotDir = "${userHome}/Pictures/Screenshots"; flakeDir = "${flakeDir}"; + flakePrev = "${userHome}/.zaneyos-previous"; + flakeBackup = "${userHome}/.zaneyos-backup"; terminal = "alacritty"; # This sets the terminal that is used by the hyprland terminal keybinding # System Settings