Refactor codebase to use nix modules

This commit is contained in:
Julia Lange 2024-04-14 05:40:02 -07:00
parent a4735423b4
commit ffada2703c
114 changed files with 1018 additions and 744 deletions

View file

@ -0,0 +1,14 @@
{ config, pkgs, ... }:
{
imports = [
./dunst
./home
./manpages
./ssh
./timers
./trash
./wal
./widgets
];
}

View file

@ -0,0 +1,49 @@
{ config, pkgs, lib, ... }:
{
options.dunst = {
enable = lib.mkEnableOption "Enables dunst";
};
config = lib.mkIf config.dunst.enable {
home.packages = with pkgs; [
libnotify
];
services.dunst = {
enable = true;
settings = {
global = {
width = 280;
height = 240;
origin = "bottom-right";
offset = "0x300";
notification_limit = 3;
progress_bar_max_width = 280;
gap_size = 4;
corner_radius = 20;
};
urgency_low = {
background = "#FFFFFFCC";
foreground = "#000000";
frame_color = "#0000";
};
urgency_normal = {
background = "#FFFFFFCC";
foreground = "#000000";
frame_color = "#0000";
};
urgency_critical = {
background = "#FFFFFFCC";
foreground = "#000000";
frame_color = "#0000";
};
};
};
};
}

View file

@ -0,0 +1,38 @@
{ config, pkgs, lib, ... }:
{
options = {
extraPkgs = lib.mkOption { default = []; };
};
config = {
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
home.sessionVariables = {
GRADLE_USER_HOME = "${config.xdg.dataHome}/gradle";
CUDA_CACHE_PATH = "${config.xdg.cacheHome}/nv";
};
xdg = {
enable = true;
mimeApps.enable = true;
userDirs = let
home = config.home.homeDirectory;
in {
enable = true;
documents = "${home}/dox";
publicShare = "${home}/dox/public";
templates = "${home}/dox/templates";
music = "${home}/med/mus";
pictures = "${home}/med/pix";
videos = "${home}/med/vid";
desktop = "${home}/dwn";
download = "${home}/dwn";
};
};
home.homeDirectory = "/home/" + config.home.username;
home.packages = config.extraPkgs;
};
}

View file

@ -0,0 +1,15 @@
{ config, pkgs, lib, ... }:
{
options.manpages = {
enable = lib.mkEnableOption "Enables manpager";
};
config = lib.mkIf config.manpages.enable {
programs.man.enable = true;
home.packages = with pkgs; [
man-pages
man-pages-posix
];
};
}

View file

@ -0,0 +1,14 @@
{ config, pkgs, lib, ... }:
{
options.ssh = {
enable = lib.mkEnableOption "Enables ssh";
};
config = lib.mkIf config.ssh.enable {
programs.ssh.enable = true;
home.packages = with pkgs; [
sshfs # SSH File system
];
};
}

View file

@ -0,0 +1,60 @@
{ config, pkgs, lib, ... }:
let rootPath = ./.; in
{
options.timer = {
enableHourly = lib.mkEnableOption "Enables an hourly notification";
enableQuarterly = lib.mkEnableOption "Enables a quarterly notification";
};
config = {
systemd.user.timers = {
hourly-time = lib.mkIf config.timer.enableHourly {
Timer = {
OnCalendar = "hourly";
};
Install = {
WantedBy = [
"timers.target"
];
};
};
quarterly-time = lib.mkIf config.timer.enableQuarterly {
Timer = {
OnCalendar = "*-*-* *:15,30,45:00";
};
Install = {
WantedBy = [
"timers.target"
];
};
};
};
systemd.user.services = {
hourly-time = lib.mkIf config.timer.enableHourly {
Unit = {
Description = "Notify the user every hour of time passing";
};
Service = {
Type="simple";
ExecStart="/home/pan/.config/timer_scripts/notify-time.sh 60000 1";
};
};
quarterly-time = lib.mkIf config.timer.enableQuarterly {
Unit = {
Description = "Notify the user every 15 minutes of time passing, \
skips hours";
};
Service = {
Type="simple";
ExecStart="/home/pan/.config/timer_scripts/notify-time.sh 10000 0";
};
};
};
xdg.configFile."timer-scripts" = {
source = rootPath + "/scripts";
target = "timer_scripts/";
executable = true;
};
};
}

Binary file not shown.

View file

@ -0,0 +1,8 @@
#!/bin/sh
export DISPLAY=":0"
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
/home/pan/.nix-profile/bin/notify-send "$(/run/current-system/sw/bin/date +%H:%M)" -t $1
if [ $2 -eq 1 ]; then
/run/current-system/sw/bin/pw-cat --volume 0.08 -p ./chimes.ogg &
fi

View file

@ -0,0 +1,13 @@
{ config, pkgs, lib, ... }:
{
options.trash = {
enable = lib.mkEnableOption "Enables trash";
};
config = {
home.packages = [
pkgs.trash-cli
];
};
}

View file

@ -0,0 +1,34 @@
{ config, pkgs, lib, ... }:
let rootPath = ./.; in
{
options.colors = {
enable = lib.mkEnableOption "Enables setting colors using wallust";
};
config = lib.mkIf config.colors.enable {
home.packages = with pkgs; [
wallust # A better pywal
pywalfox-native # Update librewolf's colorscheme based on wal
];
xdg.configFile."wallust-config" = {
target = "wallust/wallust.toml";
text = ''
backend = "wal"
color_space = "lab"
threshold = 20
filter = "dark16"
# [[entry]]
# # a relative path to a file where wallust.toml is (~/.config/wallust/)
# template = "dunstrc"
#
# # absolute path to the file to write the template (after templating)
# target = "~/.config/dunst/dunstrc"
'';
};
#xdg.configFile."wallust-templates" = {
# source = rootPath + "/templates";
# target = "wallust/";
#};
};
}

View file

@ -0,0 +1,9 @@
// import { Switch } from "./modules/workspace-switch.js";
import { notificationPopup } from "./modules/notifications/notificationPopup.ts"
export default {
style: App.configDir + '/modules/notifications/style.css',
windows: [
notificationPopup()
]
}

View file

@ -0,0 +1,22 @@
export const Clock = (monitor = 0) => {
return Widget.Window({
monitor,
name: `switch${monitor}`,
anchor: ['top', 'left', 'right'],
margins: [864, 1030],
css: 'background: transparent;',
child: container,
});
};
const container = Widget.Box({
css: `
min-height: 110px;
min-width: 500px;
border: 4px solid #f4d80a;
border-radius: 50px;
margin: 3px;
box-shadow: 0 0 0 3px white;
`,
});

View file

@ -0,0 +1,71 @@
const notifications = await Service.import('notifications');
const popups = notifications.bind('popups');
export const notificationPopup = (monitor = 0) => {
return Widget.Window({
name: 'notifications',
anchor: ['bottom', 'right'],
child: Widget.Box({
class_name: 'notifications',
vertical: true,
children: popups.as(popups => popups.map(Notification)),
}),
});
};
/** @param {import('resource:///com/github/Aylur/ags/service/notifications.js').Notification} n */
const Notification = n => {
const title = Widget.Label({
class_name: 'title',
xalign: 0,
justification: 'left',
hexpand: true,
max_width_chars: 24,
truncate: 'end',
wrap: true,
label: n.summary,
use_markup: true,
});
const body = Widget.Label({
class_name: 'body',
hexpand: true,
use_markup: true,
xalign: 0,
justification: 'left',
label: n.body,
wrap: true,
});
const actions = Widget.Box({
class_name: 'actions',
children: n.actions.map(({ id, label }) => Widget.Button({
class_name: 'action-button',
on_clicked: () => n.invoke(id),
hexpand: true,
child: Widget.Label(label),
})),
});
return Widget.EventBox({
on_primary_click: () => n.dismiss(),
child: Widget.Box({
class_name: `notification ${n.urgency}`,
vertical: true,
children: [
Widget.Box({
children: [
Widget.Box({
vertical: true,
children: [
title,
body,
],
}),
],
}),
actions,
],
}),
});
};

View file

@ -0,0 +1,61 @@
window#notifications {
all: unset;
}
window#notifications box.notifications {
padding: .5em;
}
.icon {
min-width: 68px;
min-height: 68px;
margin-right: 1em;
}
.icon image {
font-size: 58px;
/* to center the icon */
margin: 5px;
color: @theme_fg_color;
}
.icon box {
min-width: 68px;
min-height: 68px;
border-radius: 7px;
}
.notification {
min-width: 350px;
border-radius: 11px;
padding: 1em;
margin: .5em;
border: 1px solid @wm_borders_edge;
background-color: @theme_bg_color;
}
.notification.critical {
border: 1px solid lightcoral;
}
.title {
color: @theme_fg_color;
font-size: 1.4em;
}
.body {
color: @theme_unfocused_fg_color;
}
.actions .action-button {
margin: 0 .4em;
margin-top: .8em;
}
.actions .action-button:first-child {
margin-left: 0;
}
.actions .action-button:last-child {
margin-right: 0;
}

View file

@ -0,0 +1,22 @@
export const Switch = (monitor = 0) => {
return Widget.Window({
monitor,
name: `switch${monitor}`,
anchor: ['top', 'left', 'right'],
margins: [864, 1030],
css: 'background: transparent;',
child: container,
});
};
const container = Widget.Box({
css: `
min-height: 110px;
min-width: 500px;
border: 4px solid #f4d80a;
border-radius: 50px;
margin: 3px;
box-shadow: 0 0 0 3px white;
`,
});

View file

@ -0,0 +1,25 @@
{ config, inputs, pkgs, lib, ... }:
{
options.ags = {
enable = lib.mkEnableOption "Enable ags";
};
imports = [ inputs.ags.homeManagerModules.default ];
config = lib.mkIf config.ags.enable {
home.packages = with pkgs; [
libnotify # Notifications through ags
];
programs.ags = {
enable = true;
configDir = ./config;
extraPackages = with pkgs; [
gtksourceview
webkitgtk
accountsservice
];
};
};
}

View file

@ -0,0 +1,8 @@
{ config, pkgs, lib, ... }:
{
imports = [
./ags
./eww
];
}

View file

@ -0,0 +1,11 @@
.content-box {
border: 4px solid yellow;
border-radius: 50px;
background-color: rgba(255,255,255,10);
margin: 2px;
box-shadow: 0 0 0 3px white;
}
.switch {
background: transparent;
}

View file

@ -0,0 +1 @@
(include "modules/switch.yuck")

View file

@ -0,0 +1,40 @@
(include "./widgets/components/hyprwindow.yuck")
(include "./widgets/components/hyprworkspaces.yuck")
(include "./widgets/components/internet.yuck")
(include "./widgets/components/japanesedate.yuck")
(include "./widgets/components/japaneseaudio.yuck")
(defwidget bar []
(centerbox :orientation "horizontal"
:style "padding: 0px 8px"
(box :halign "start"
:spacing 18
:space-evenly false
(hyprworkspaces)
(hyprwindow)
)
""
(box :halign "end"
:spacing 18
:space-evenly false
(eventbox :onhover "eww open preview"
:onhoverlost "eww close preview"
barplayer
)
(internet)
(japaneseaudio)
(japanesedate)
(label :style "color: #FAE3B0"
:text bartime
)
)
)
)
(defpoll bartime :interval "10s"
"date '+%H:%M'"
)
(deflisten barplayer :initial ""
"playerctl --follow metadata --format '{{ artist }} - {{ title }}' || true"
)

View file

@ -0,0 +1,5 @@
(defwidget hyprwindow []
(label :text "${hyprwindow_listener}")
)
(deflisten hyprwindow_listener :initial "" "bash $XDG_CONFIG_HOME/eww/scripts/get-window-title")

View file

@ -0,0 +1,17 @@
(defwidget hyprworkspaces []
(eventbox :onscroll "bash ~/.config/eww/scripts/change-active-workspace {} ${current_workspace}" :class "workspaces-widget"
(box :space-evenly false
:spacing 5
(for workspace in workspaces
(eventbox :onclick "hyprctl dispatch workspace ${workspace.id}"
(box :class "workspace-entry ${workspace.id == current_workspace ? "current" : ""} ${workspace.windows > 0 ? "occupied" : "empty"}"
(label :text "${workspace.id}")
)
)
)
)
)
)
(deflisten workspaces :initial "[]" "bash $XDG_CONFIG_HOME/eww/scripts/get-workspaces")
(deflisten current_workspace :initial "1" "bash $XDG_CONFIG_HOME/eww/scripts/get-active-workspace")

View file

@ -0,0 +1,8 @@
(defwidget internet []
(box :spacing 0 :space-evenly false :style "color: #f5c2e7"
network
)
)
(defpoll network :interval "30s"
"iwgetid -r")

View file

@ -0,0 +1,11 @@
(defwidget japaneseaudio []
(eventbox :onscroll "bash -c 'if [ '{}' = 'up' ]; then pamixer -i 5; else pamixer -d 5; fi'"
(box :spacing 0 :space-evenly false :style "color: #96CDFB"
volume
"音"
)
)
)
(defpoll volume :interval "1s"
"pamixer --get-volume")

View file

@ -0,0 +1,9 @@
(defwidget japanesebattery []
(box :spacing 0 :space-evenly false :style "color: #FAB387"
power
"電"
)
)
(defpoll power :interval "1m"
"cat /sys/class/power_supply/BAT1/capacity")

View file

@ -0,0 +1,9 @@
(defwidget japanesedate []
(label :style "color: #DDB6F2"
:text japanesedate_time
)
)
(defpoll japanesedate_time :interval "100s"
"bash $XDG_CONFIG_HOME/eww/scripts/japanesedate"
)

View file

@ -0,0 +1,15 @@
(defwidget powerbar []
(box
:orientation "vertical"
:spacing 8
:space-evenly false
:style "color: #FAB387"
(progress
:orientation "v"
:value {100 - power})
"電"
)
)
(defpoll power :interval "1m"
"cat /sys/class/power_supply/BAT1/capacity")

View file

@ -0,0 +1,15 @@
(defwindow switch
:monitor 1
:stacking "fg"
:focusable false
:geometry (geometry :y "60%"
:width "500px"
:height "110px"
:anchor "top center")
(border
"Example contenting")
)
(defwidget border []
(box :class "content-box"
(children)))

View file

@ -0,0 +1,21 @@
#!/bin/sh
function clamp {
min=$1
max=$2
val=$3
python -c "print(max($min, min($val, $max)))"
}
direction=$1
current=$2
if test "$direction" = "down"
then
target=$(clamp 1 10 $(($current+1)))
echo "jumping to $target"
hyprctl dispatch workspace $target
elif test "$direction" = "up"
then
target=$(clamp 1 10 $(($current-1)))
echo "jumping to $target"
hyprctl dispatch workspace $target
fi

View file

@ -0,0 +1,3 @@
#!/bin/sh
hyprctl monitors -j | jq --raw-output .[0].activeWorkspace.id
socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | stdbuf -o0 grep '^workspace>>' | stdbuf -o0 awk -F '>>|,' '{print $2}'

View file

@ -0,0 +1,3 @@
#!/bin/sh
hyprctl activewindow -j | jq --raw-output .title
socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | stdbuf -o0 grep '^activewindow>>' | stdbuf -o0 awk -F '>>|,' '{print $3}'

View file

@ -0,0 +1,11 @@
#!/bin/sh
spaces (){
WORKSPACE_WINDOWS=$(hyprctl workspaces -j | jq 'map({key: .id | tostring, value: .windows}) | from_entries')
seq 1 10 | jq --argjson windows "${WORKSPACE_WINDOWS}" --slurp -Mc 'map(tostring) | map({id: ., windows: ($windows[.]//0)})'
}
spaces
socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | while read -r line; do
spaces
done

View file

@ -0,0 +1,31 @@
#!/bin/sh
readarray -t dateparts <<<"$(date "+%0m月%0d日%n%u")"
echo -n "${dateparts[0]}["
case ${dateparts[1]} in
1)
echo -n "月"
;;
2)
echo -n "火"
;;
3)
echo -n "水"
;;
4)
echo -n "木"
;;
5)
echo -n "金"
;;
6)
echo -n "土"
;;
7)
echo -n "日"
;;
esac
echo "]"

View file

@ -0,0 +1,3 @@
#!/bin/sh
playerctl --follow metadata mpris:artUrl | stdbuf -o0 cut -c 8-

View file

@ -0,0 +1,13 @@
{ config, pkgs, lib, ... }:
{
options.eww = {
enable = lib.mkEnableOption "Enables eww";
};
config = lib.mkIf config.eww.enable {
programs.eww.enable = true;
programs.eww.package = pkgs.eww-wayland;
programs.eww.configDir = ./config;
};
}