1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
This commit is contained in:
Kierán Meinhardt
2019-04-05 22:16:16 +02:00
parent 579b5e4618
commit c70c4369dc
5 changed files with 78 additions and 439 deletions

View File

@@ -5,35 +5,8 @@ let
iolanguage = pkgs.callPackage ../packages/iolanguage.nix {};
sncli = pkgs.python3Packages.callPackage ../packages/sncli.nix {};
todoist = pkgs.callPackage ../packages/todoist {};
dic-pkg = pkgs.fetchurl {
url = "https://cgit.krebsco.de/stockholm/plain/krebs/5pkgs/simple/dic/default.nix?id=8371e21c10bdb5d5353cc581efba7e09e4ce7a91";
sha256 = "1vd8mg1ac7wzrcs5bl20srkxcs65zr7rd7y3wxzrxspij5wrb23i";
};
yt-next-pkg = pkgs.fetchurl {
url = http://cgit.lassul.us/stockholm/plain/lass/5pkgs/yt-next/default.nix;
sha256 = "0j9r9xy34sl9ci5lz38060b3nakf0vd7gw46pykdiriwz6znbxn3";
};
urlencode-pkg = pkgs.fetchurl {
url = http://cgit.lassul.us/stockholm/plain/krebs/5pkgs/simple/urlencode/default.nix;
sha256 = "0cxf0fcaq02krkn33qipv878drqnjr035a564m66wp9x8n2zjgim";
};
acronym-pkg = pkgs.fetchurl {
url = http://cgit.lassul.us/stockholm/plain/lass/5pkgs/acronym/default.nix;
sha256 = "1rpr1rniz74vmkl4r3hgrg8q7ncxrvbf7zp0lq9b7lva85i12zx9";
};
urban-pkg = pkgs.fetchurl {
url = http://cgit.lassul.us/stockholm/plain/lass/5pkgs/urban/default.nix;
sha256 = "128v0znnapcqbyvc0nf112ddfyipr8sc1z4kcnggnbjf99i763ji";
};
mpv-poll-pkg = pkgs.fetchurl {
url = http://cgit.lassul.us/stockholm/plain/lass/5pkgs/mpv-poll/default.nix;
sha256 = "0ccmm7spxll98j8gy58fc3p8331arznshsj5wn4kkcypcs16n6ci";
};
dic = pkgs.callPackage dic-pkg {};
yt-next = pkgs.callPackage yt-next-pkg {};
acronym = pkgs.callPackage acronym-pkg {};
urban = pkgs.callPackage urban-pkg {};
mpv-poll = pkgs.callPackage mpv-poll-pkg {};
spotify-cli-linux = pkgs.python3Packages.callPackage ../packages/spotify-cli-linux.nix {};
instaloader = pkgs.python3Packages.callPackage ../packages/instaloader.nix {};
haskells = import ../dot/haskells.nix;
unstable = import <nixos-unstable> {};
executables = pkgs.haskell.lib.justStaticExecutables;
@@ -76,6 +49,7 @@ in with pkgs;
wget
httpie
whois
instaloader
] ++ [ # media
ffmpeg
mpv
@@ -206,6 +180,7 @@ in with pkgs;
pdfgrep
pdftk
spotify
spotify-cli-linux
youtubeDL
] ++ [ # cloud
dropbox-cli
@@ -235,10 +210,5 @@ in with pkgs;
unstable.hledger
wordnet
xsv
dic
yt-next
mpv-poll
acronym
urban
] ++ (if config.networking.hostName == "homeros" then [ unstable.zeroad ] else []);
}

View File

@@ -2,6 +2,38 @@
let
theme = import ../theme.nix;
unstable = import <nixos-unstable> {};
scripts.dic = pkgs.callPackage (pkgs.fetchurl {
url = "https://cgit.krebsco.de/stockholm/plain/krebs/5pkgs/simple/dic/default.nix?id=8371e21c10bdb5d5353cc581efba7e09e4ce7a91";
sha256 = "1vd8mg1ac7wzrcs5bl20srkxcs65zr7rd7y3wxzrxspij5wrb23i";
}) {};
scripts.yt-next = pkgs.callPackage (pkgs.fetchurl {
url = http://cgit.lassul.us/stockholm/plain/lass/5pkgs/yt-next/default.nix;
sha256 = "0j9r9xy34sl9ci5lz38060b3nakf0vd7gw46pykdiriwz6znbxn3";
}) {};
scripts.acronym = pkgs.callPackage (pkgs.fetchurl {
url = http://cgit.lassul.us/stockholm/plain/lass/5pkgs/acronym/default.nix;
sha256 = "1rpr1rniz74vmkl4r3hgrg8q7ncxrvbf7zp0lq9b7lva85i12zx9";
}) {};
scripts.urban = pkgs.callPackage (pkgs.fetchurl {
url = http://cgit.lassul.us/stockholm/plain/lass/5pkgs/urban/default.nix;
sha256 = "128v0znnapcqbyvc0nf112ddfyipr8sc1z4kcnggnbjf99i763ji";
}) {};
scripts.mpv-poll = pkgs.callPackage (pkgs.fetchurl {
url = http://cgit.lassul.us/stockholm/plain/lass/5pkgs/mpv-poll/default.nix;
sha256 = "0ccmm7spxll98j8gy58fc3p8331arznshsj5wn4kkcypcs16n6ci";
}) {};
script.instaget = unstable.writers.writeDash "instaget.sh" ''
for url in "$@"; do
${pkgs.curl}/bin/curl -s "$url" \
| grep display_url \
| grep -o '{.*}' \
| ${pkgs.jq}/bin/jq -r '
.entry_data.PostPage
| .[].graphql.shortcode_media.edge_sidecar_to_children.edges
| .[].node.display_url' \
| xargs ${pkgs.wget}/bin/wget
done
'';
bingWallpaper = unstable.writers.writeBash "bing-wallpaper.sh" ''
PICTURE_DIR="$HOME/pictures/external/bing/"
@@ -19,312 +51,19 @@ let
fi
done
'';
scripts.easy-backup = unstable.writers.writeDash "easy-backup" ''
if [ -d "$1" ]; then
OUTPUT_ROOT=''${1}/backup/current
rsync -hav --delete --stats --progress --exclude-from=$HOME/bin/backup.exclude $HOME/* $OUTPUT_ROOT/
else
echo "No backup directory supplied"
exit 1
fi
'';
scripts.pull-all = unstable.writers.writeDashBin "pull-all" ''
# store the current dir
CUR_DIR=$(pwd)
# Let the person running the script know what's going on.
echo -e "\n\033[1mPulling in latest changes for all repositories...\033[0m\n"
# Find all git repositories and update it to the master latest revision
for i in $(find . -name ".git" | cut -c 3-); do
echo "";
echo -e "\033[33m"+$i+"\033[0m";
# We have to go to the .git parent directory to call the pull command
cd "$i";
cd ..;
# finally pull
git pull origin master;
# lets get back to the CUR_DIR
echo ""
echo -e "\033[33m"+$i+"\033[0m"
cd "$i"
cd ..
git pull origin master
cd $CUR_DIR
done
echo -e "\n\033[32mComplete!\033[0m\n"
'';
scripts.sp = unstable.writers.writeBashBin "sp" ''
# This is sp, the command-line Spotify controller. It talks to a running
# instance of the Spotify Linux client over dbus, providing an interface not
# unlike mpc.
#
# Put differently, it allows you to control Spotify without leaving the comfort
# of your command line, and without a custom client or Premium subscription.
#
# As an added bonus, it also works with ssh, at and cron.
#
# Example:
# $ sp weather girls raining men
# $ sp current
# Album 100 Hits Of The '80s
# Artist The Weather Girls
# Title It's Raining Men
# $ sp pause
#
# Alarm clock example:
# $ at 7:45 <<< 'sp bangarang'
#
# Remote example:
# $ ssh vader@prod02.nomoon.ta 'sp imperial march'
#
#
# Copyright (C) 2013 Wander Nauta
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software, to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# The software is provided "as is", without warranty of any kind, express or
# implied, including but not limited to the warranties of merchantability,
# fitness for a particular purpose and noninfringement. In no event shall the
# authors or copyright holders be liable for any claim, damages or other
# liability, whether in an action of contract, tort or otherwise, arising from,
# out of or in connection with the software or the use or other dealings in the
# software.
#
# CONSTANTS
SP_VERSION="0.1"
SP_DEST="org.mpris.MediaPlayer2.spotify"
SP_PATH="/org/mpris/MediaPlayer2"
SP_MEMB="org.mpris.MediaPlayer2.Player"
# SHELL OPTIONS
shopt -s expand_aliases
# UTILITY FUNCTIONS
function require {
hash $1 2>/dev/null || {
echo >&2 "Error: '$1' is required, but was not found."; exit 1;
}
}
# COMMON REQUIRED BINARIES
# We need dbus-send to talk to Spotify.
require dbus-send
# Assert standard Unix utilities are available.
require grep
require sed
require cut
require tr
# 'SPECIAL' (NON-DBUS-ALIAS) COMMANDS
function sp-dbus {
# Sends the given method to Spotify over dbus.
dbus-send --print-reply --dest=$SP_DEST $SP_PATH $SP_MEMB.$1 ''${*:2} > /dev/null
}
function sp-open {
# Opens the given spotify: URI in Spotify.
sp-dbus OpenUri string:$1
}
function sp-metadata {
# Prints the currently playing track in a parseable format.
dbus-send \
--print-reply `# We need the reply.` \
--dest=$SP_DEST \
$SP_PATH \
org.freedesktop.DBus.Properties.Get \
string:"$SP_MEMB" string:'Metadata' \
| grep -Ev "^method" `# Ignore the first line.` \
| grep -Eo '("(.*)")|(\b[0-9][a-zA-Z0-9.]*\b)' `# Filter interesting fiels.`\
| sed -E '2~2 a|' `# Mark odd fields.` \
| tr -d '\n' `# Remove all newlines.` \
| sed -E 's/\|/\n/g' `# Restore newlines.` \
| sed -E 's/(xesam:)|(mpris:)//' `# Remove ns prefixes.` \
| sed -E 's/^"//' `# Strip leading...` \
| sed -E 's/"$//' `# ...and trailing quotes.` \
| sed -E 's/"+/|/' `# Regard "" as seperator.` \
| sed -E 's/ +/ /g' `# Merge consecutive spaces.`
}
function sp-current {
# Prints the currently playing track in a friendly format.
require column
sp-metadata \
| grep --color=never -E "(title)|(album)|(artist)" \
| sed 's/^\(.\)/\U\1/' \
| column -t -s'|'
}
function sp-eval {
# Prints the currently playing track as shell variables, ready to be eval'ed
require sort
sp-metadata \
| grep --color=never -E "(title)|(album)|(artist)|(trackid)|(trackNumber)" \
| sort -r \
| sed 's/^\([^|]*\)\|/\U\1/' \
| sed -E 's/\|/="/' \
| sed -E 's/$/"/' \
| sed -E 's/^/SPOTIFY_/'
}
function sp-art {
# Prints the artUrl.
sp-metadata | grep "artUrl" | cut -d'|' -f2
}
function sp-display {
# Calls display on the artUrl.
require display
display $(sp-art)
}
function sp-feh {
# Calls feh on the artURl.
require feh
feh $(sp-art)
}
function sp-url {
# Prints the HTTP url.
TRACK=$(sp-metadata | grep "url" | cut -d'|' -f2 | cut -d':' -f3)
echo "http://open.spotify.com/track/$TRACK"
}
function sp-clip {
# Copies the HTTP url.
require xclip
sp-url | xclip
}
function sp-http {
# xdg-opens the HTTP url.
require xdg-open
xdg-open $(sp-url)
}
function sp-help {
# Prints usage information.
echo "Usage: sp [command]"
echo "Control a running Spotify instance from the command line."
echo ""
echo " sp play - Play/pause Spotify"
echo " sp pause - Pause Spotify"
echo " sp next - Go to next track"
echo " sp prev - Go to previous track"
echo ""
echo " sp current - Format the currently playing track"
echo " sp metadata - Dump the current track's metadata"
echo " sp eval - Return the metadata as a shell script"
echo ""
echo " sp art - Print the URL to the current track's album artwork"
echo " sp display - Display the current album artwork with \`display\`"
echo " sp feh - Display the current album artwork with \`feh\`"
echo ""
echo " sp url - Print the HTTP URL for the currently playing track"
echo " sp clip - Copy the HTTP URL to the X clipboard"
echo " sp http - Open the HTTP URL in a web browser"
echo ""
echo " sp open <uri> - Open a spotify: uri"
echo " sp search <q> - Start playing the best search result for the given query"
echo ""
echo " sp version - Show version information"
echo " sp help - Show this information"
echo ""
echo "Any other argument will start a search (i.e. 'sp foo' will search for foo)."
}
function sp-search {
# Searches for tracks, plays the first result.
require curl
Q="$@"
SPTFY_URI=$( \
curl -s -G --data-urlencode "q=$Q" ws.spotify.com/search/1/track \
| grep -E -o "spotify:track:[a-zA-Z0-9]+" -m 1 \
)
sp-open $SPTFY_URI
}
function sp-version {
# Prints version information.
echo "sp $SP_VERSION"
echo "Copyright (C) 2013 Wander Nauta"
echo "License MIT"
}
# 'SIMPLE' (DBUS-ALIAS) COMMANDS
alias sp-play=" sp-dbus PlayPause"
alias sp-pause=" sp-dbus Pause"
alias sp-next=" sp-dbus Next"
alias sp-prev=" sp-dbus Previous"
# DISPATCHER
# First, we connect to the dbus session spotify is on. This isn't really needed
# when running locally, but is crucial when we don't have an X display handy
# (for instance, when running sp over ssh.)
SPOTIFY_PID="$(pidof -s spotify)"
if [[ -z "$SPOTIFY_PID" ]]; then
echo "Error: Spotify is not running."
exit 1
fi
QUERY_ENVIRON="$(cat /proc/''${SPOTIFY_PID}/environ | tr '\0' '\n' | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
if [[ "''${QUERY_ENVIRON}" != "" ]]; then
export DBUS_SESSION_BUS_ADDRESS="''${QUERY_ENVIRON}"
fi
# Then we dispatch the command.
subcommand="$1"
if [[ -z "$subcommand" ]]; then
# No arguments given, print help.
sp-help
else
# Arguments given, check if it's a command.
if $(type sp-$subcommand > /dev/null 2> /dev/null); then
# It is. Run it.
shift
eval "sp-$subcommand $@"
else
# It's not. Try a search.
eval "sp-search $@"
fi
fi
'';
spotifyGenius = unstable.writers.writeDashBin "spgenius.sh" ''
function normalise {
echo "$1" | tr ' ' -
}
eval $(${scripts.sp} eval)
${pkgs.xdg_utils}/bin/xdg-open "http://genius.com/$(normalise "$SPOTIFY_ARTIST")-$(normalise "$SPOTIFY_TITLE")-lyrics"
'';
scripts.genius = unstable.writers.writeDashBin "genius" ''
test $# -eq 2 || (
echo "usage: $0 <artist> <song>"
@@ -386,113 +125,8 @@ let
${pkgs.nix-prefetch-git}/bin/nix-prefetch-git "$@" 2> /dev/null | ${pkgs.jq}/bin/jq -r '"rev = \"\(.rev)\";\nsha256 = \"\(.sha256)\";"'
'';
scripts.autorenkalender = unstable.writers.writeDashBin "autorenkalender" ''
${pkgs.curl}/bin/curl -s gutenberg.spiegel.de | ${pkgs.gnused}/bin/sed -n '/Autorenkalender/,/<\/div>/p' | ${pkgs.html2text}/bin/html2text | ${pkgs.coreutils}/bin/tail +2
${pkgs.curl}/bin/curl -s https://gutenberg.spiegel.de | ${pkgs.gnused}/bin/sed -n '/Autorenkalender/,/<\/div>/p' | ${pkgs.html2text}/bin/html2text | ${pkgs.coreutils}/bin/tail +2
'';
scripts.q =
let
q-performance = ''
show_load() {
${pkgs.coreutils}/bin/cat /proc/loadavg | ${pkgs.gawk}/bin/gawk '{ print $1, $2, $3}'
}
show_memory() {
${pkgs.procps}/bin/free -h | ${pkgs.gnugrep}/bin/grep "Mem" | ${pkgs.gawk}/bin/gawk '{print $3}'
}
printf "\x1b[33m%s \x1b[1m%s\x1b[0m\n" "$(show_load)" "$(show_memory)"
'';
q-isodate = ''
${pkgs.coreutils}/bin/date '+%Y-%m-%d %H:%M:%S%:z'
'';
q-volume = ''
is_mute() {
if $(${pkgs.pamixer}/bin/pamixer --get-mute); then
echo "(Mute)"
else
echo
fi
}
current_volume() {
${pkgs.pamixer}/bin/pamixer --get-volume
}
printf "\x1b[36m%d%%\x1b[0m %s\n" "$(current_volume)" "$(is_mute)"
'';
q-online = ''
if ${pkgs.curl}/bin/curl -s google.com >/dev/null; then
echo 'online'
else
echo 'offline'
fi
'';
q-battery = ''
BAT_DIR="/sys/class/power_supply/BAT1/"
if test ! -d "$BAT_DIR"; then
exit 1
fi
if test -e "$BAT_DIR/charge_now" -a -e "$BAT_DIR/charge_full"; then
FULL_CHARGE="$BAT_DIR/charge_full"
CURR_CHARGE="$BAT_DIR/charge_now"
elif test -e "$BAT_DIR/energy_now" -a -e "$BAT_DIR/energy_full"; then
FULL_CHARGE="$BAT_DIR/energy_full"
CURR_CHARGE="$BAT_DIR/energy_now"
else
ls >&2
exit 1
fi
STATUS="$BAT_DIR/status"
charge_d=$((100 * $(${pkgs.coreutils}/bin/cat $CURR_CHARGE) / $(${pkgs.coreutils}/bin/cat $FULL_CHARGE)))
if [[ "$charge_d" -lt 10 ]]; then
printf "\x1b[31m"
elif [[ "$charge_d" -lt 20 ]]; then
printf "\x1b[33m"
else
printf "\x1b[32m"
fi
printf '%s%%\x1b[0m (%s)\n' "$charge_d" $(${pkgs.coreutils}/bin/cat "$STATUS")
'';
q-todo = ''
TODO_file=$PWD/.todo
if test -e "$TODO_file"; then
printf "\n\x1b[1mTodo\x1b[0m\n"
${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[93m\""rest esc "\"\x1b[m\" && \
(( remind++ ))"
}
END { print "test $remind = 0 && echo \"nothing to remind\"" }
' \
| {
# bash needed for (( ... ))
${pkgs.bash}/bin/bash
}
fi
'';
in unstable.writers.writeBashBin "q" ''
set -eu
export PATH=/var/empty
${q-isodate}
${q-performance}
(${q-volume}) &
(${q-battery}) &
(${q-online}) &
wait
${q-todo}
'';
in {
environment.shellAliases =
let rlwrap = cmd: "${pkgs.rlwrap}/bin/rlwrap ${cmd}";

View File

@@ -4,6 +4,6 @@ templates:
params:
author-name: ${user.name}
author-email: ${user.email}
copyright: 'Copyright: (c) 2018 ${user.name}'
copyright: 'Copyright: (c) 2019 ${user.name}'
github-username: ${user.github}
''

12
packages/instaloader.nix Normal file
View File

@@ -0,0 +1,12 @@
{ buildPythonApplication, fetchPypi, requests }:
let
in buildPythonApplication rec {
pname = "instaloader";
version = "4.2.4";
src = fetchPypi {
inherit pname version;
sha256 = "02zqb02idk2pzks7dv42vigcmmpjpfhfdyjp911yr0ix7dy3q0b9";
};
propagatedBuildInputs = [ requests ];
doCheck = false;
}

View File

@@ -0,0 +1,23 @@
{ buildPythonPackage, buildPythonApplication, fetchPypi, pytestrunner, six, beautifulsoup4, requests, dbus-python }:
let
lyricwikia = buildPythonPackage rec {
pname = "lyricwikia";
version = "0.1.9";
src = fetchPypi {
inherit pname version;
sha256 = "0sa5wkbgp5bpgkl8hgn7byyz9zj0786647ikf2l0k8m4fimq623y";
};
buildInputs = [ pytestrunner ];
propagatedBuildInputs = [ six beautifulsoup4 requests ];
doCheck = false;
};
in buildPythonApplication rec {
pname = "spotify-cli-linux";
version = "1.4.2";
src = fetchPypi {
inherit pname version;
sha256 = "1gxich3v2i4lmh60abbw3mw15399afvvqflv8g6plvvbmvxmbgp0";
};
propagatedBuildInputs = [ lyricwikia dbus-python ];
doCheck = false;
}