From 5cdb4e421a809de51c3ebe8404e50d732721238b Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 26 Sep 2021 21:26:36 +0530 Subject: init --- services/battery.nix | 48 ++++++++++++++++++++++++++++++++++ services/default.nix | 27 ++++++++++++++++++++ services/dunst.nix | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ services/mbsync.nix | 11 ++++++++ services/picom.nix | 18 +++++++++++++ services/redshift.nix | 18 +++++++++++++ services/suspend.nix | 65 ++++++++++++++++++++++++++++++++++++++++++++++ services/sxhkd.nix | 17 ++++++++++++ 8 files changed, 275 insertions(+) create mode 100644 services/battery.nix create mode 100644 services/default.nix create mode 100644 services/dunst.nix create mode 100644 services/mbsync.nix create mode 100644 services/picom.nix create mode 100644 services/redshift.nix create mode 100644 services/suspend.nix create mode 100644 services/sxhkd.nix (limited to 'services') diff --git a/services/battery.nix b/services/battery.nix new file mode 100644 index 0000000..a871e8f --- /dev/null +++ b/services/battery.nix @@ -0,0 +1,48 @@ +{ config, lib, pkgs, ... }: + +with lib; +let + cfg = config.services.battery-alert; + bat = pkgs.writeScriptBin "bat" + '' + ''; +in +{ + options.services.battery-alert = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + If enabled, NixOS will periodically check battery levels and report + if it is below a threshold value. + ''; + }; + }; + + config = { + systemd.user.timers.battery-alert = mkIf cfg.enable { + description = "Periodically check battery status and alert if required"; + timerConfig.OnBootSec = "1m"; + timerConfig.OnUnitInactiveSec = "1m"; + timerConfig.Unit = "battery-alert.service"; + wantedBy = [ "timers.target" ]; + }; + + systemd.user.services.battery-alert = { + description = "Check battery levels"; + path = [ pkgs.libnotify pkgs.coreutils ]; + serviceConfig = { + PassEnvironment = "DISPLAY XAUTHORITY"; + }; + script = '' + bat_status=$( ${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/capacity ) + charging_status=$( ${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/status ) + + # if [[ $bat_status -ge 10 ]]; then + ${pkgs.libnotify}/bin/notify-send "Battery low: $bat_status%" "$charging_status" + # fi + ''; + }; + + }; +} diff --git a/services/default.nix b/services/default.nix new file mode 100644 index 0000000..0e85cd9 --- /dev/null +++ b/services/default.nix @@ -0,0 +1,27 @@ +{ config +, pkgs +, theme +, ... +}: + +{ + + imports = [ + ./dunst.nix + ./picom.nix + ./redshift.nix + ./sxhkd.nix + ./mbsync.nix + ]; + + services = { + lorri.enable = true; + gpg-agent = { + enable = true; + defaultCacheTtl = 86400; + maxCacheTtl = 86400; + pinentryFlavor = "curses"; + }; + }; + +} diff --git a/services/dunst.nix b/services/dunst.nix new file mode 100644 index 0000000..8882ade --- /dev/null +++ b/services/dunst.nix @@ -0,0 +1,71 @@ +{ config +, pkgs +, theme +, ... +}: + +with theme; +{ + services.dunst = { + enable = true; + settings = { + global = { + font = "Input 9"; + allow_markup = "no"; + format = "%s\n%b"; + sort = "yes"; + indicate_hidden = "yes"; + alignment = "right"; + bounce_freq = "0"; + show_age_threshold = "60"; + word_wrap = "yes"; + ignore_newline = "no"; + geometry = "300x8-20+20"; + shrink = "yes"; + transparency = "0"; + idle_threshold = "120"; + monitor = "0"; + follow = "mouse"; + sticky_history = "yes"; + history_length = "20"; + show_indicators = "yes"; + line_height = "0"; + separator_height = "0"; + padding = "20"; + horizontal_padding = "20"; + separator_color = "auto"; + startup_notification = "true"; + }; + + urgency_normal = { + background = base00; + foreground = base05; + timeout = 10; + }; + + urgency_low = { + background = base00; + foreground = base05; + timeout = 2; + }; + + urgency_critical = { + background = base00; + foreground = base05; + timeout = 0; + }; + + frame = { + width = 2; + color = base01; + }; + + shortcuts = { + close = "ctrl+space"; + close_all = "ctrl+shift+space"; + history = "ctrl+grave"; + context = "ctrl+shift+period"; + }; + }; + }; +} diff --git a/services/mbsync.nix b/services/mbsync.nix new file mode 100644 index 0000000..168b7ec --- /dev/null +++ b/services/mbsync.nix @@ -0,0 +1,11 @@ +{ config +, pkgs +, ... +}: + +{ + services.mbsync = { + enable = true; + frequency = "*:0/15"; + }; +} diff --git a/services/picom.nix b/services/picom.nix new file mode 100644 index 0000000..67605d1 --- /dev/null +++ b/services/picom.nix @@ -0,0 +1,18 @@ +{ config +, pkgs +, ... +}: + +{ + services.picom = { + enable = true; + backend = "glx"; + fade = true; + fadeDelta = 10; + fadeSteps = [ "0.04" "0.04" ]; + inactiveDim = "0.0"; + shadow = false; + shadowOffsets = [ (-60) (-60) ]; + shadowOpacity = "0.20"; + }; +} diff --git a/services/redshift.nix b/services/redshift.nix new file mode 100644 index 0000000..5385fc1 --- /dev/null +++ b/services/redshift.nix @@ -0,0 +1,18 @@ +{ config +, pkgs +, ... +}: + +{ + services.redshift = { + enable = true; + temperature = { + day = 5000; + night = 4000; + }; + tray = false; + provider = "manual"; + latitude = "12"; + longitude = "77"; + }; +} diff --git a/services/suspend.nix b/services/suspend.nix new file mode 100644 index 0000000..445446b --- /dev/null +++ b/services/suspend.nix @@ -0,0 +1,65 @@ +{ config, lib, pkgs, ... }: + +with lib; +let + cfg = config.services.batteryNotifier; +in +{ + options = { + services.batteryNotifier = { + enable = mkOption { + default = false; + description = '' + Whether to enable battery notifier. + ''; + }; + device = mkOption { + default = "BAT0"; + description = '' + Device to monitor. + ''; + }; + notifyCapacity = mkOption { + default = 10; + description = '' + Battery level at which a notification shall be sent. + ''; + }; + suspendCapacity = mkOption { + default = 5; + description = '' + Battery level at which a suspend unless connected shall be sent. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.user.timers."lowbatt" = { + description = "check battery level"; + timerConfig.OnBootSec = "1m"; + timerConfig.OnUnitInactiveSec = "1m"; + timerConfig.Unit = "lowbatt.service"; + wantedBy = [ "timers.target" ]; + }; + systemd.user.services."lowbatt" = { + description = "battery level notifier"; + serviceConfig.PassEnvironment = "DISPLAY"; + script = '' + export battery_capacity=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/capacity) + export battery_status=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/status) + if [[ $battery_capacity -le ${builtins.toString cfg.notifyCapacity} && $battery_status = "Discharging" ]]; then + ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Low" "You should probably plug-in." + fi + if [[ $battery_capacity -le ${builtins.toString cfg.suspendCapacity} && $battery_status = "Discharging" ]]; then + ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Critically Low" "Computer will suspend in 60 seconds." + sleep 60s + battery_status=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/status) + if [[ $battery_status = "Discharging" ]]; then + systemctl suspend + fi + fi + ''; + }; + }; +} diff --git a/services/sxhkd.nix b/services/sxhkd.nix new file mode 100644 index 0000000..8658875 --- /dev/null +++ b/services/sxhkd.nix @@ -0,0 +1,17 @@ +{ config +, pkgs +, theme +, ... +}: + +{ + services.sxhkd = { + enable = true; + keybindings = { + "XF86Audio{Lower,Raise}Volume" = "${pkgs.alsaUtils}/bin/amixer sset Master 2%{-,+}"; + "XF86AudioMute" = "${pkgs.alsaUtils}/bin/amixer sset Master toggle"; + "XF86MonBrightness{Down,Up}" = "${pkgs.light}/bin/light -{U,A} 5"; + "super + Escape" = "pkill -USR1 -x sxhkd"; + }; + }; +} -- cgit v1.2.3