From 94d534975ab228b27d4713f7dec41bfa3900fdfb Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 2 Oct 2021 10:46:11 +0530 Subject: rework services --- hosts/olive/configuration.nix | 6 ++---- mail.nix | 1 - programs/neovim.nix | 2 +- scripts/default.nix | 26 ++++++++++++++++++++--- services/battery.nix | 48 ------------------------------------------- services/suspend.nix | 8 ++++---- 6 files changed, 30 insertions(+), 61 deletions(-) delete mode 100644 services/battery.nix diff --git a/hosts/olive/configuration.nix b/hosts/olive/configuration.nix index 0019695..3c15f74 100644 --- a/hosts/olive/configuration.nix +++ b/hosts/olive/configuration.nix @@ -8,7 +8,6 @@ imports = [ ./hardware-configuration.nix - ../../services/battery.nix ../../services/suspend.nix ]; @@ -92,7 +91,6 @@ adb.enable = true; }; - sound.enable = true; hardware.pulseaudio = { enable = true; @@ -114,8 +112,8 @@ services.batteryNotifier = { enable = true; - notifyCapacity = 40; - suspendCapacity = 5; + notifyCapacity = 20; + suspendCapacity = 10; }; users.users.np = { diff --git a/mail.nix b/mail.nix index b62e51a..9b22088 100644 --- a/mail.nix +++ b/mail.nix @@ -44,6 +44,5 @@ userName = "nerdy@peppe.rs"; notmuch.enable = true; msmtp.enable = true; - }; } diff --git a/programs/neovim.nix b/programs/neovim.nix index 18baeac..e163d48 100644 --- a/programs/neovim.nix +++ b/programs/neovim.nix @@ -35,7 +35,7 @@ vimtex # handy - # vim-gitgutter + vim-gitgutter tabular emmet-vim vimwiki diff --git a/scripts/default.nix b/scripts/default.nix index 84fcff3..a6e5936 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -1,17 +1,31 @@ { pkgs, ... }: -let +let # open a window with live video feed from the camera webcam = pkgs.writeScriptBin "webcam" '' ${pkgs.mpv}/bin/mpv av://v4l2:/dev/video0 --profile=low-latency --untimed ''; + # create new repo on fern + git-new-repo = pkgs.writeScriptBin "git-new-repo" '' + if [ $# -eq 0 ]; then + echo "requires an arg" + exit 1 + fi + + # $1 - section/repo-name + + ssh git@ferrn git init --bare "$1"; + git remote add origin git@ferrn:"$1"; + git push -u origin HEAD; + ''; + # set git repo descriptions on cgit git-set-desc = pkgs.writeScriptBin "git-set-desc" '' remote=$(git remote get-url --push origin) scp .git/description "$remote/description" - ''; + ''; # screen record with ffmpeg and slop record = import ./record.nix pkgs; @@ -23,4 +37,10 @@ let battery = import ./battery.nix pkgs; in - [ webcam git-set-desc record uploader battery ] +[ + webcam + git-set-desc + record + uploader + battery +] diff --git a/services/battery.nix b/services/battery.nix deleted file mode 100644 index a871e8f..0000000 --- a/services/battery.nix +++ /dev/null @@ -1,48 +0,0 @@ -{ 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/suspend.nix b/services/suspend.nix index 445446b..35e213a 100644 --- a/services/suspend.nix +++ b/services/suspend.nix @@ -37,8 +37,8 @@ in config = mkIf cfg.enable { systemd.user.timers."lowbatt" = { description = "check battery level"; - timerConfig.OnBootSec = "1m"; - timerConfig.OnUnitInactiveSec = "1m"; + timerConfig.OnBootSec = "5m"; + timerConfig.OnUnitInactiveSec = "5m"; timerConfig.Unit = "lowbatt.service"; wantedBy = [ "timers.target" ]; }; @@ -49,10 +49,10 @@ in 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." + ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Low: $battery_capacity%" 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." + ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Critically Low: $battery_capacity%" sleep 60s battery_status=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/status) if [[ $battery_status = "Discharging" ]]; then -- cgit v1.2.3