From c4562ca6ee950c7e1b6c9339cd0be9fa9c0ada39 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 3 Jun 2016 15:05:00 +0200 Subject: tv: import q --- tv/5pkgs/default.nix | 1 + tv/5pkgs/q/default.nix | 193 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 tv/5pkgs/q/default.nix diff --git a/tv/5pkgs/default.nix b/tv/5pkgs/default.nix index 05dc028..da3c914 100644 --- a/tv/5pkgs/default.nix +++ b/tv/5pkgs/default.nix @@ -17,6 +17,7 @@ erlang = pkgs.erlangR16; }; ff = pkgs.callPackage ./ff {}; + q = pkgs.callPackage ./q {}; viljetic-pages = pkgs.callPackage ./viljetic-pages {}; xmonad-tv = import ./xmonad-tv.nix { inherit pkgs; }; }; diff --git a/tv/5pkgs/q/default.nix b/tv/5pkgs/q/default.nix new file mode 100644 index 0000000..1d08a54 --- /dev/null +++ b/tv/5pkgs/q/default.nix @@ -0,0 +1,193 @@ +{ pkgs, ... }: +let + q-cal = let + # XXX 23 is the longest line of cal's output + pad = ''{ + ${pkgs.gnused}/bin/sed ' + # rtrim + s/ *$// + + # delete last empty line + ''${/^$/d} + ' \ + | ${pkgs.gawk}/bin/awk '{printf "%-23s\n", $0}' \ + | ${pkgs.gnused}/bin/sed ' + # colorize header + 1,2s/.*/&/ + + # colorize week number + s/^[ 1-9][0-9]/&/ + ' + }''; + in '' + ${pkgs.coreutils}/bin/paste \ + <(${pkgs.utillinux}/bin/cal -mw \ + $(${pkgs.coreutils}/bin/date +'%m %Y' -d 'last month') \ + | ${pad} + ) \ + <(${pkgs.utillinux}/bin/cal -mw \ + | ${pkgs.gnused}/bin/sed ' + # colorize day of month + s/\(^\| \)'"$(${pkgs.coreutils}/bin/date +%e)"'\>/&/ + ' \ + | ${pad} + ) \ + <(${pkgs.utillinux}/bin/cal -mw \ + $(${pkgs.coreutils}/bin/date +'%m %Y' -d 'next month') \ + | ${pad} + ) \ + | ${pkgs.gnused}/bin/sed 's/\t/ /g' + ''; + + q-isodate = '' + ${pkgs.coreutils}/bin/date \ + '+%Y-%m-%dT%H:%M:%S%:z' + ''; + + # Singapore's red is #ED2E38 + q-sgtdate = '' + TZ=Asia/Singapore \ + ${pkgs.coreutils}/bin/date \ + '+%Y-%m-%dT%H:%M:%S%:z' + ''; + + q-gitdir = '' + if test -d .git; then + #git status --porcelain + branch=$( + ${pkgs.git}/bin/git branch \ + | ${pkgs.gnused}/bin/sed -rn 's/^\* (.*)/\1/p' + ) + echo "± $LOGNAME@''${HOSTNAME-$(${pkgs.nettools}/bin/hostname)}:$PWD .git $branch" + fi + ''; + + q-power_supply = '' + for uevent in /sys/class/power_supply/*/uevent; do + if test -f $uevent; then + eval "$(${pkgs.gnused}/bin/sed -n ' + s/^\([A-Z_]\+=\)\(.*\)/\1'\'''\2'\'''/p + ' $uevent)" + + if test "x''${POWER_SUPPLY_CHARGE_NOW-}" = x; then + continue + fi + + charge_percentage=$(echo " + scale=2 + $POWER_SUPPLY_CHARGE_NOW / $POWER_SUPPLY_CHARGE_FULL + " | ${pkgs.bc}/bin/bc) + + lfc=$POWER_SUPPLY_CHARGE_FULL + rc=$POWER_SUPPLY_CHARGE_NOW + #rc=2800 + N=78; N=76 + N=10 + n=$(echo $N-1 | ${pkgs.bc}/bin/bc) + centi=$(echo "$rc*100/$lfc" | ${pkgs.bc}/bin/bc) + deci=$(echo "$rc*$N/$lfc" | ${pkgs.bc}/bin/bc) + energy_evel=$( + echo -n '☳ ' # TRIGRAM FOR THUNDER + if test $centi -ge 42; then echo -n '' + elif test $centi -ge 23; then echo -n '' + elif test $centi -ge 11; then echo -n '' + else echo -n ''; fi + for i in $(${pkgs.coreutils}/bin/seq 1 $deci); do + echo -n ■ + done + echo -n '' + for i in $(${pkgs.coreutils}/bin/seq $deci $n); do + echo -n ■ + done + echo '' $rc #/ $lfc + ) + echo "$energy_evel $charge_percentage" + fi + done + ''; + + q-virtualization = '' + echo "VT: $(${pkgs.systemd}/bin/systemd-detect-virt)" + ''; + + q-wireless = '' + for dev in $( + ${pkgs.iw}/bin/iw dev \ + | ${pkgs.gnused}/bin/sed -n 's/^\s*Interface\s\+\([0-9a-z]\+\)$/\1/p' + ); do + inet=$(${pkgs.iproute}/bin/ip addr show $dev \ + | ${pkgs.gnused}/bin/sed -n ' + s/.*inet \([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p + ') \ + || unset inet + ssid=$(${pkgs.iw}/bin/iw dev $dev link \ + | ${pkgs.gnused}/bin/sed -n ' + s/.*\tSSID: \(.*\)/\1/p + ') \ + || unset ssid + echo "$dev''${inet+ $inet}''${ssid+ $ssid}" + done + ''; + + q-online = '' + if ${pkgs.curl}/bin/curl -s google.com >/dev/null; then + echo 'online' + else + echo offline + fi + ''; + + q-thermal_zone = '' + for i in /sys/class/thermal/thermal_zone*; do + type=$(${pkgs.coreutils}/bin/cat $i/type) + temp=$(${pkgs.coreutils}/bin/cat $i/temp) + printf '%s %s°C\n' $type $(echo $temp / 1000 | ${pkgs.bc}/bin/bc) + done + ''; + + q-todo = '' + TODO_file=$HOME/TODO + if test -e "$TODO_file"; then + ${pkgs.coreutils}/bin/cat "$TODO_file" \ + | ${pkgs.gawk}/bin/gawk -v now=$(${pkgs.coreutils}/bin/date +%s) ' + BEGIN { print "remind=0" } + /^[0-9]/{ + x = $1 + gsub(".", "\\\\&", x) + rest = substr($0, index($0, " ")) + rest = $0 + sub(" *", "", rest) + gsub(".", "\\\\&", rest) + print "test $(${pkgs.coreutils}/bin/date +%s -d"x") -lt "now" && \ + echo \"\x1b[38;5;208m\""rest esc "\"\x1b[m\" && \ + (( remind++ ))" + } + END { print "test $remind = 0 && echo \"nothing to remind\"" } + ' \ + | { + # bash needed for (( ... )) + ${pkgs.bash}/bin/bash + } + else + echo "$TODO_file: no such file or directory" + fi + ''; + +in +# bash needed for <(...) +pkgs.writeBashBin "q" '' + set -eu + export PATH=/var/empty + ${q-cal} + echo + ${q-isodate} + ${q-sgtdate} + (${q-gitdir}) & + (${q-power_supply}) & + (${q-virtualization}) & + (${q-wireless}) & + (${q-online}) & + (${q-thermal_zone}) & + wait + ${q-todo} +'' -- cgit v1.2.3 From a2b70cc0eda0f4ae61f641195fb25b28270471fd Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 3 Jun 2016 15:05:47 +0200 Subject: xu: use q --- tv/1systems/xu.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/tv/1systems/xu.nix b/tv/1systems/xu.nix index 96a0545..a79ae49 100644 --- a/tv/1systems/xu.nix +++ b/tv/1systems/xu.nix @@ -60,6 +60,7 @@ with config.krebs.lib; nmap p7zip pass + q qrencode texLive tmux -- cgit v1.2.3 From 7ee098b98520c858441d244983972bd5b964c512 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 4 Jun 2016 19:09:19 +0200 Subject: krebs pkgs.{writeHaskellBin => writeHaskell} --- tv/2configs/xserver/default.nix | 4 ++-- tv/5pkgs/xmonad-tv.nix | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tv/2configs/xserver/default.nix b/tv/2configs/xserver/default.nix index 965c3bb..c41c0a8 100644 --- a/tv/2configs/xserver/default.nix +++ b/tv/2configs/xserver/default.nix @@ -74,8 +74,8 @@ in { }; serviceConfig = { SyslogIdentifier = "xmonad"; - ExecStart = "${pkgs.xmonad-tv}/bin/xmonad-tv"; - ExecStop = "${pkgs.xmonad-tv}/bin/xmonad-tv --shutdown"; + ExecStart = "${pkgs.xmonad-tv}/bin/xmonad"; + ExecStop = "${pkgs.xmonad-tv}/bin/xmonad --shutdown"; User = user.name; WorkingDirectory = user.home; }; diff --git a/tv/5pkgs/xmonad-tv.nix b/tv/5pkgs/xmonad-tv.nix index 74e43dc..04e7e83 100644 --- a/tv/5pkgs/xmonad-tv.nix +++ b/tv/5pkgs/xmonad-tv.nix @@ -1,14 +1,15 @@ { pkgs, ... }: -pkgs.writeHaskellBin "xmonad-tv" { - depends = [ - "containers" - "unix" - "X11" - "xmonad" - "xmonad-contrib" - "xmonad-stockholm" - ]; -} '' +pkgs.writeHaskell "xmonad-tv" { + executables.xmonad = { + extra-depends = [ + "containers" + "unix" + "X11" + "xmonad" + "xmonad-contrib" + "xmonad-stockholm" + ]; + text = '' {-# LANGUAGE DeriveDataTypeable #-} -- for XS {-# LANGUAGE FlexibleContexts #-} -- for xmonad' {-# LANGUAGE LambdaCase #-} @@ -299,4 +300,6 @@ wGSConfig = def allWorkspaceNames :: W.StackSet i l a sid sd -> X [i] allWorkspaceNames ws = return $ map W.tag (W.hidden ws) ++ [W.tag $ W.workspace $ W.current ws] -'' + ''; + }; +} -- cgit v1.2.3 From 06a7bdf7964695f198357b6985bf2594b3484e13 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 5 Jun 2016 00:25:47 +0200 Subject: make build.pkgs.${name} --- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Makefile b/Makefile index a74e3a8..6e09559 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,14 @@ $(if $(target_user),,$(error unbound variable: target_user)) $(if $(target_port),,$(error unbound variable: target_port)) $(if $(target_path),,$(error unbound variable: target_path)) +build = \ + nix-build \ + --no-out-link \ + --show-trace \ + -I nixos-config=$(nixos-config) \ + -I stockholm=$(stockholm) \ + -E "let build = import ; in $(1)" + evaluate = \ nix-instantiate \ --eval \ @@ -74,6 +82,10 @@ deploy: env STOCKHOLM_VERSION="$$STOCKHOLM_VERSION" \ nixos-rebuild switch --show-trace -I $(target_path) +# usage: make build.pkgs.get +build build.:;@$(call build,$${expr-eval}) +build.%:;@$(call build,$@) + # usage: make LOGNAME=shared system=wolf eval.config.krebs.build.host.name eval eval.:;@$(call evaluate,$${expr-eval}) eval.%:;@$(call evaluate,$@) -- cgit v1.2.3