From 5b6ecd0a25c9cadc494d67ccf7131fc95ea7f7f9 Mon Sep 17 00:00:00 2001 From: Stefan Junker Date: Tue, 23 May 2023 18:09:54 +0200 Subject: [PATCH] feat(Justfile): cachix recipe and apply locally without ssh --- Justfile | 5 +- nix/home-manager/programs/salut.nix | 0 nix/home-manager/programs/waybar.css | 146 +++++++++++++++++ nix/home-manager/programs/waybar.nix | 197 +++++++++++++++++++++++ nix/os/cachix.nix | 14 ++ nix/os/cachix/nixpkgs-wayland.nix | 12 ++ nix/os/profiles/graphical-gnome-xorg.nix | 0 scripts/sway-swapoutputworkspaces.sh | 41 +++++ 8 files changed, 414 insertions(+), 1 deletion(-) create mode 100644 nix/home-manager/programs/salut.nix create mode 100644 nix/home-manager/programs/waybar.css create mode 100644 nix/home-manager/programs/waybar.nix create mode 100644 nix/os/cachix.nix create mode 100644 nix/os/cachix/nixpkgs-wayland.nix create mode 100644 nix/os/profiles/graphical-gnome-xorg.nix create mode 100755 scripts/sway-swapoutputworkspaces.sh diff --git a/Justfile b/Justfile index 168aa37..4dd9ebd 100755 --- a/Justfile +++ b/Justfile @@ -35,7 +35,7 @@ rebuild-remote-device device target rebuildarg="dry-activate" : # Rebuild this device's NixOS rebuild-this-device +rebuildargs="dry-activate": - nix run .#colmena -- apply --on $(hostname -s) {{rebuildargs}} + nix run .#colmena -- apply-local --sudo {{rebuildargs}} # Re-render the versions of a remote device and rebuild its environment update-remote-device devicename target rebuildmode='switch': @@ -318,3 +318,6 @@ test-connection: sleep 5 done + +cachix-use name: + nix run nixpkgs/nixos-unstable#cachix -- use {{name}} -m nixos -d nix/os/ diff --git a/nix/home-manager/programs/salut.nix b/nix/home-manager/programs/salut.nix new file mode 100644 index 0000000..e69de29 diff --git a/nix/home-manager/programs/waybar.css b/nix/home-manager/programs/waybar.css new file mode 100644 index 0000000..9adcc7b --- /dev/null +++ b/nix/home-manager/programs/waybar.css @@ -0,0 +1,146 @@ +* { + /* all: unset;*/ + + border: none; + border-radius: 0; + /* `otf-font-awesome` is required to be installed for icons */ + /* font matches sway-config.nix */ + font-family: "Iosevka Comfy Fixed"; /* TODO: parameterize this? */ + font-weight: bold; + font-size: 12px; + min-height: 0; + + padding: 0px; +} + +window#waybar { + background-color: #111111; + color: #666666; + border-bottom: 2px double #fff; + border-bottom: 2px double #33ccff; +} + +/* +window#waybar.termite { + background-color: #3F3F3F; +} + +window#waybar.chromium { + background-color: #000000; + border: none; +} +*/ + +#workspaces button { + padding: 0px; + margin: 4px; + margin-left: 2px; + margin-right: 2px; + color: #cccccc; + min-width: 25px; + border: 1px solid transparent; +} + +/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */ +/* +#workspaces button:hover { + background: rgba(0, 0, 0, 0.2); + box-shadow: inherit; + border-bottom: 3px solid #ffffff; +} +*/ + +#workspaces button.current_output { + border-color: #aaa; + border-style: dotted; + color: #ffffff; +} + +#workspaces button.focused { + background-color: #aaa; + color: #000000; + border-color: #aaa; + border-style: solid; +} + +#workspaces button.focused.current_output { + border-color: #ee00ff; + border-style: solid; +} + +#workspaces button.urgent { + background-color: #eb4d4b; +} + +#mode { + background-color: #64727D; + border-bottom: 1px solid #ffffff; +} + +#tray { + background-color: #111111; +} + +#clock, +#clock-time, +#battery, +#cpu, +#memory, +#temperature, +#network, +#custom-ppp, +#custom-rog, +#tray, +#mode, +#backlight, +#pulseaudio, +#idle_inhibitor, +#mpd { + /*padding: 2px;*/ + padding: 0px; + padding-left: 4px; + padding-right: 4px; + margin: 4px; + margin-right: 6px; + color: #fff; + background-color: #333; +} + +#battery { +} + +#battery.charging { + color: #26A65B; +} + +@keyframes blink { + to { + background-color: #f53c3c; + color: #ffffff; + } +} + +#battery.Charging { + color: green; +} +#battery.Discharging { + color: blue; +} +#battery.Discharging.warning { + color: orange; +} +#battery.Discharging.critical { + background-color: #f53c3c; + color: #ffffff; + animation-name: blink; + animation-duration: 0.5s; + animation-timing-function: linear; + animation-iteration-count: infinite; + animation-direction: alternate; +} + +/* +label:focus { + background-color: #000000; +} +*/ diff --git a/nix/home-manager/programs/waybar.nix b/nix/home-manager/programs/waybar.nix new file mode 100644 index 0000000..350f4e6 --- /dev/null +++ b/nix/home-manager/programs/waybar.nix @@ -0,0 +1,197 @@ +{ pkgs, config, inputs, ... }: + +let + rogScript = pkgs.writeShellScript "waybar-rog.sh" '' + set -euo pipefail + val="$(${pkgs.asusctl}/bin/asusctl profile -p)" + if [[ "''${val}" == *"Performance"* ]]; then + echo $'{"text": "rog prf"}'; + elif [[ "''${val}" == *"Balanced"* ]]; then + echo $'{"text": "rog bal"}'; + elif [[ "''${val}" == *"Quiet"* ]]; then + echo $'{"text": "rog qui"}'; + fi + ''; + + pppScript = pkgs.writeShellScript "waybar-ppp.sh" '' + set -euo pipefail + val="$(${pkgs.power-profiles-daemon}/bin/powerprofilesctl get)" + if [[ "''${val}" == "performance" ]]; then + echo $'{"text": "ppp prf"}'; + elif [[ "''${val}" == "balanced" ]]; then + echo $'{"text": "ppp bal"}'; + elif [[ "''${val}" == "power-saver" ]]; then + echo $'{"text": "ppp pwr"}'; + fi + ''; + extraModules = if config.networking.hostName != "zeph" then { } else { + "custom/rog" = { + exec = "${rogScript}"; + return-type = "json"; + interval = 10; + }; + "custom/ppp" = { + exec = "${pppScript}"; + return-type = "json"; + interval = 10; + }; + }; + # # jobpath = "/run/user/1000/srht/jobs"; + # # jobs = { + # # "niche" = "niche"; + # # "n-w" = "nixpkgs-wayland"; + # # "f-f-n" = "flake-firefox-nightly"; + # # }; + + # # suffix = pkgs.lib.mapAttrsToList (k: v: '' + # # status="$("${pkgs.jq}/bin/jq" -r '[.results[] | select(.tags=="${v}" and .status!="running" and .status!="cancelled")][0] | .status' "${jobpath}/data")" + # # echo "{\"text\":\"''${status}\", \"class\":\"srht-''${status}\"}" > "${jobpath}/${v}-json" + # # '') jobs; + + # # jobsScript = pkgs.writeShellScriptBin "jobs.sh" (pkgs.lib.concatStrings ( + # # ['' + # # TOKEN=$(cat ${config.sops.secrets."srht-pat".path}) + # # BUILD_HOST="https://builds.sr.ht" + # # "${pkgs.coreutils}/bin/mkdir" -p "${jobpath}" + # # "${pkgs.curl}/bin/curl" \ + # # -H "Authorization:token ''${TOKEN}" \ + # # -H "Content-Type: application/json" -X GET \ + # # "''${BUILD_HOST}/api/jobs" > "${jobpath}/data" + # # ''] ++ suffix )); + # networktoggle = pkgs.writeShellScriptBin "networktoggle.sh" '' + # if ip link | grep wlan; then + # sudo ${pkgs.util-linux}/bin/rfkill toggle wlan + # sudo ${pkgs.systemd}/bin/networkctl reconfigure wlan0 + # ${pkgs.libnotify}/bin/notify-send "toggled wlan0" + # else + # ${pkgs.libnotify}/bin/notify-send "no wlan to toggle" + # fi + # ''; +in +{ + config = { + # sops.secrets."srht-pat" = { + # owner = "cole"; + # group = "cole"; + # }; + + home-manager.users.cole = { pkgs, ... }: { + # systemd.user.services."srht-jobs-status" = { + # Unit.Description = "check srht-jobs status"; + # Service = { + # Type = "oneshot"; + # ExecStart = "${jobsScript}/bin/jobs.sh"; + # }; + # }; + # systemd.user.timers."srht-jobs-status" = { + # Unit.Description = "check srht jobs status"; + # Timer = { OnBootSec = "1m"; OnUnitInactiveSec = "1m"; Unit = "srht-jobs-status.service"; }; + # Install.WantedBy = [ "default.target" ]; + # # { + # # wantedBy = [ "timers.target" ]; + # # partOf = [ "srht-${repo}.service" ]; + # # timerConfig.OnCalendar = "hourly"; + # # } + # }; + home.packages = [ pkgs.libappindicator-gtk3 ]; + programs.waybar = { + enable = true; + package = inputs.nixpkgs-wayland.outputs.packages.${pkgs.stdenv.hostPlatform.system}.waybar; + style = pkgs.lib.readFile ./waybar.css; + systemd.enable = true; + settings = [{ + # ipc = true; + layer = "top"; + # position = "top"; + modules-left = [ + "sway/mode" + "sway/workspaces" + ]; + modules-center = [ + "wlr/workspaces" + ]; + modules-right = [ + # "keyboard-state" + # "idle_inhibitor" + "pulseaudio" + "backlight" + "tray" + ] + ++ (builtins.attrNames extraModules) + ++ [ + "cpu" + "memory" + "network" + "temperature" + "battery" + "clock" + "clock#date" + ]; + + modules = ({ + "sway/workspaces" = { + all-outputs = true; + disable-scroll-wraparound = true; + #enable-bar-scroll = true; + }; + "sway/mode" = { tooltip = false; }; + + + # # TODO: + # keyboard-state = { + # "numlock" = true; + # "capslock" = true; + # "format" = "{name} {icon}"; + # "format-icons" = { + # "locked" = "+"; + # "unlocked" = "-"; + # }; + # }; + "wlr/taskbar" = { }; + temperature = { + format = "tmp {temperatureC}"; + }; + idle_inhibitor = { + format = "iil {icon}"; + format-icons = { + activated = "[x]"; + deactivated = "[ ]"; + }; + }; + pulseaudio = { + format = "vol {volume}"; + on-click-middle = "${pkgs.sway}/bin/swaymsg exec \"${pkgs.pavucontrol}/bin/pavucontrol\""; + }; + network = { + format-wifi = "net {signalStrength}"; + format-ethernet = "eth"; + }; + cpu.interval = 2; + cpu.format = "cpu {usage}"; + memory.format = "mem {}"; + backlight = { + format = "nit {percent}"; + on-scroll-up = "${pkgs.brightnessctl}/bin/brightnessctl set 2%+"; + on-scroll-down = "${pkgs.brightnessctl}/bin/brightnessctl set 2%-"; + }; + tray.spacing = 10; + # battery + clock = { + format = "{:%d %b %Y}"; + }; + "clock#date" = { + format = "{:%H:%M %p}"; + }; + battery = { + format = "bat {}"; + states = { + warning = 25; + critical = 15; + }; + }; + } // extraModules); + }]; + }; + }; + }; +} diff --git a/nix/os/cachix.nix b/nix/os/cachix.nix new file mode 100644 index 0000000..cce90a3 --- /dev/null +++ b/nix/os/cachix.nix @@ -0,0 +1,14 @@ + +# WARN: this file will get overwritten by $ cachix use +{ pkgs, lib, ... }: + +let + folder = ./cachix; + toImport = name: value: folder + ("/" + name); + filterCaches = key: value: value == "regular" && lib.hasSuffix ".nix" key; + imports = lib.mapAttrsToList toImport (lib.filterAttrs filterCaches (builtins.readDir folder)); +in { + inherit imports; + nix.binaryCaches = ["https://cache.nixos.org/"]; +} + \ No newline at end of file diff --git a/nix/os/cachix/nixpkgs-wayland.nix b/nix/os/cachix/nixpkgs-wayland.nix new file mode 100644 index 0000000..aa9f600 --- /dev/null +++ b/nix/os/cachix/nixpkgs-wayland.nix @@ -0,0 +1,12 @@ + +{ + nix = { + binaryCaches = [ + "https://nixpkgs-wayland.cachix.org" + ]; + binaryCachePublicKeys = [ + "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=" + ]; + }; +} + \ No newline at end of file diff --git a/nix/os/profiles/graphical-gnome-xorg.nix b/nix/os/profiles/graphical-gnome-xorg.nix new file mode 100644 index 0000000..e69de29 diff --git a/scripts/sway-swapoutputworkspaces.sh b/scripts/sway-swapoutputworkspaces.sh new file mode 100755 index 0000000..9f8f637 --- /dev/null +++ b/scripts/sway-swapoutputworkspaces.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env sh + +# Get two outputs, visible workspaces and focused workspace +output1=$(swaymsg -t get_outputs --raw | jq '.[0].name' -r) +output2=$(swaymsg -t get_outputs --raw | jq '.[1].name' -r) +workspace1=$(swaymsg -t get_outputs --raw | jq '.[0].current_workspace' -r) +workspace2=$(swaymsg -t get_outputs --raw | jq '.[1].current_workspace' -r) +workspace_active=$(swaymsg -t get_workspaces | jq -r '.[] | select(.focused==true).name') + +# If any of the outputs doesn't have a workspace, do nothing +if [ "$workspace1" = null ] || [ "$workspace2" = null ]; then + exit 0 +else + # If script is provided with `follow` argument, then follow focused workspace + if [ "$1" = "follow" ]; then + if [ "$workspace1" = "$workspace_active" ]; then + swaymsg move workspace to output "$output2" + swaymsg workspace "$workspace2" + swaymsg move workspace to output "$output1" + swaymsg workspace "$workspace2" + else + swaymsg workspace "$workspace1" + swaymsg move workspace to output "$output2" + swaymsg workspace "$workspace2" + swaymsg move workspace to output "$output1" + fi + # Else focus stays with focused output + else + if [ "$workspace1" = "$workspace_active" ]; then + swaymsg move workspace to output "$output2" + swaymsg workspace "$workspace2" + swaymsg move workspace to output "$output1" + else + swaymsg workspace "$workspace1" + swaymsg move workspace to output "$output2" + swaymsg workspace "$workspace2" + swaymsg move workspace to output "$output1" + swaymsg workspace "$workspace1" + fi + fi +fi