diff options
author | Profpatsch <mail@profpatsch.de> | 2016-10-04 02:54:00 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2016-10-04 02:56:19 +0200 |
commit | e0abe1dbbda54c1f048b5d38df05e1a3289216a6 (patch) | |
tree | 90632cfd9fa638d00ee9bd8a5e3bd19e9be60c2c /pkgs | |
parent | 0b5beb71d988d4ee39bda95bee947c1c41b3c9df (diff) |
pkgs/profpatsch/display-infos: init
A script to display current time & battery.
Diffstat (limited to 'pkgs')
-rw-r--r-- | pkgs/default.nix | 5 | ||||
-rw-r--r-- | pkgs/profpatsch/display-infos/default.nix | 38 |
2 files changed, 43 insertions, 0 deletions
diff --git a/pkgs/default.nix b/pkgs/default.nix index 71b5c16c..e6b5a0c0 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -13,6 +13,8 @@ let git-detach = callPackage ./git-detach { }; grandpa = callPackage ./grandpa { }; greybird-xfce-theme = callPackage ./greybird-xfce-theme { }; + iec16022 = callPackage ./iec16022 { }; + multi-iec16022 = callPackage ./multi_iec16022 { }; jmtpfs = pkgs.jmtpfs.override { libmtp = pkgs.libmtp.overrideDerivation (old: { patches = old.patches or [] ++ [ ./mtp-jolla.patch ]; @@ -47,5 +49,8 @@ let gitit = callPackage ./openlab/gitit { hlib = pkgs.haskell.lib; }; stackenblocken = callPackage ./openlab/stackenblocken {}; }; + profpatsch = pkgs.recurseIntoAttrs { + display-infos = callPackage ./profpatsch/display-infos {}; + }; }; in pkgs // self diff --git a/pkgs/profpatsch/display-infos/default.nix b/pkgs/profpatsch/display-infos/default.nix new file mode 100644 index 00000000..d213241c --- /dev/null +++ b/pkgs/profpatsch/display-infos/default.nix @@ -0,0 +1,38 @@ +{ lib, runCommand, python3, libnotify }: + +let + name = "display-infos-0.1.0"; + script = builtins.toFile (name + "-script") '' + #!@python3@ + + import sys + import glob + import subprocess as sub + import os.path as path + import statistics as st + + full = 0 + now = 0 + for bat in glob.iglob("/sys/class/power_supply/BAT*"): + def readint(fn): + with open(fn, 'r') as f: + return int(f.read()) + + full += readint(path.join(bat, "energy_full")) + now += readint(path.join(bat, "energy_now" )) + + bat = round( now/full, 2 ) + date = sub.run(["date", "+%d.%m. %a %T"], stdout=sub.PIPE).stdout.strip().decode() + notify = "BAT: {}% | {}".format(int(bat*100), date) + sub.run(["@notify-send@", notify]) + ''; + +in + with lib; runCommand "display-infos" { + meta.description = "Script to display time & battery"; + } '' + substitute ${script} script \ + --replace "@python3@" "${getBin python3}/bin/python3" \ + --replace "@notify-send@" "${getBin libnotify}/bin/notify-send" + install -D script $out/bin/display-infos + '' |