summaryrefslogtreecommitdiffstats
path: root/pkgs/simple
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/simple')
-rw-r--r--pkgs/simple/desktop-pager.nix40
-rw-r--r--pkgs/simple/git-preview/default.nix16
-rw-r--r--pkgs/simple/su2.nix130
-rw-r--r--pkgs/simple/withLocalBuild.nix30
-rw-r--r--pkgs/simple/xauth-user.nix38
-rw-r--r--pkgs/simple/xkeyboard_config-tv.nix16
6 files changed, 270 insertions, 0 deletions
diff --git a/pkgs/simple/desktop-pager.nix b/pkgs/simple/desktop-pager.nix
new file mode 100644
index 00000000..18bf714c
--- /dev/null
+++ b/pkgs/simple/desktop-pager.nix
@@ -0,0 +1,40 @@
+# desktop-pager in its own xterm, and its utilities, like desktops.
+# usage:
+# desktop-pager toggle [WINDOW_ID]
+# desktop-pager shift [WINDOW_ID]
+{ pkgs }:
+
+let
+ desktop-pager = pkgs.withLocalBuild pkgs.haskellPackages.desktop-pager;
+in
+pkgs.symlinkJoin {
+ name = "desktop-pager-wrapper";
+ paths = [
+ (pkgs.writeDashBin "desktop-pager" ''
+ set -efu
+
+ pidfile=$XDG_RUNTIME_DIR/desktop-pager.lock
+
+ if test -e "$pidfile" &&
+ ${pkgs.procps}/bin/pgrep --pidfile="$pidfile" >/dev/null
+ then
+ ${pkgs.procps}/bin/pkill --pidfile="$pidfile"
+ ${pkgs.coreutils}/bin/rm "$pidfile"
+ exit
+ fi
+
+ echo $$ > "$pidfile"
+
+ dpi=$(
+ ${pkgs.haskellPackages.xoutinfo}/bin/xoutinfo |
+ ${pkgs.jq}/bin/jq '.dpi_x | round'
+ )
+
+ exec ${pkgs.xterm}/bin/xterm \
+ -name DesktopPagerFloat \
+ -xrm "Xft.dpi: $dpi" \
+ -e ${desktop-pager}/bin/desktop-pager "$@"
+ '')
+ desktop-pager
+ ];
+}
diff --git a/pkgs/simple/git-preview/default.nix b/pkgs/simple/git-preview/default.nix
new file mode 100644
index 00000000..f0ed4dfd
--- /dev/null
+++ b/pkgs/simple/git-preview/default.nix
@@ -0,0 +1,16 @@
+{ coreutils, git, writeDashBin }:
+
+writeDashBin "git-preview" ''
+ set -efu
+ # Checked here: merge-tree fails with exit status 1 for a name it can't
+ # resolve, too, which would pass for a conflict below.
+ merge_commit=$(${git}/bin/git rev-parse --verify "$1^{commit}"); shift
+ # Merges in the object store, without a worktree: exit status 1 means
+ # conflicts, which the tree then holds as conflict markers.
+ output=$(${git}/bin/git merge-tree --write-tree HEAD "$merge_commit") || {
+ status=$?
+ test "$status" = 1 || exit "$status"
+ }
+ tree=$(printf '%s\n' "$output" | ${coreutils}/bin/head -n 1)
+ ${git}/bin/git diff HEAD "$tree" "$@"
+''
diff --git a/pkgs/simple/su2.nix b/pkgs/simple/su2.nix
new file mode 100644
index 00000000..a9a92b10
--- /dev/null
+++ b/pkgs/simple/su2.nix
@@ -0,0 +1,130 @@
+{ pkgs }:
+
+pkgs.writeDashBin "su2" ''
+ # usage: su2 [xauth=auto|disable|trusted|untrusted] user=USER [-- COMMAND [ARGS...]]
+
+ set -efu
+
+ xauth=''${xauth-auto}
+ while test $# -gt 0; do
+ case $1 in
+ xauth=auto|xauth=disable|xauth=trusted|xauth=untrusted)
+ xauth=''${1#xauth=}
+ shift
+ ;;
+ user=*)
+ user=''${1#user=}
+ shift
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ echo "$0: error: bad argument $1" >&2
+ exit 1
+ esac
+ done
+
+ if test "$xauth" = auto; then
+ xauth=disable
+ if test "$user" != root && test -z "''${SSH_CLIENT-}"; then
+ case ''${DISPLAY-} in
+ :8)
+ xauth=untrusted
+ ;;
+ :11)
+ xauth=trusted
+ ;;
+ esac
+ fi
+ fi
+
+ case $user in
+ root)
+ case $xauth in
+ trusted)
+ ${pkgs.xauth-user}/bin/xauth-user "$user" --trusted
+ ;;
+ untrusted)
+ ${pkgs.xauth-user}/bin/xauth-user "$user"
+ ;;
+ disable)
+ :
+ ;;
+ *)
+ echo "$0: error: bad xauth value: $xauth" >&2
+ exit 2
+ esac
+ if test -n "''${SSH_CLIENT-}"; then
+ exec /run/wrappers/bin/su - -c "env SSH_CLIENT='$SSH_CLIENT' '$SHELL'"
+ else
+ case $TERM in alacritty)
+ alacritty msg config 'colors.primary.background="#230000"'
+ alacritty msg config 'colors.primary.foreground="#e0c0c0"'
+ alacritty msg config 'colors.normal.black="#800000"'
+ esac
+ exec /run/wrappers/bin/su -
+ fi
+ ;;
+ *)
+ INIT=$(
+ case $xauth in
+ trusted|untrusted)
+ XCOOKIE=$(
+ umask 0077
+ tmpfile=$XDG_RUNTIME_DIR/su2.$$.xauth
+ trusted=$xauth
+ trap '${pkgs.coreutils}/bin/rm "$tmpfile"' EXIT
+ ${pkgs.coreutils}/bin/touch "$tmpfile"
+ ${pkgs.xauth}/bin/xauth -f "$tmpfile" generate "$DISPLAY" . "$trusted" timeout 86400
+ ${pkgs.xauth}/bin/xauth -f "$tmpfile" extract - "$DISPLAY" | ${pkgs.coreutils}/bin/base64
+ )
+ export XCOOKIE
+ ;;
+ disable)
+ :
+ ;;
+ *)
+ echo "$0: error: bad xauth value: $xauth" >&2
+ exit 2
+ esac
+ export SU2PID=$$
+ ${pkgs.jq}/bin/jq -nr '
+ def to_shell_vars(x):
+ x | to_entries | map(
+ select(.value != null) |
+ "\(.key)=\(.value|@sh)"
+ ) | join(" ");
+
+ env | [
+ "export \(to_shell_vars({
+ COLORTERM,
+ DISPLAY,
+ SSH_CLIENT,
+ }))",
+ "\(to_shell_vars({
+ SU2PID,
+ XCOOKIE,
+ }));"
+ ] | join(";")
+ '
+ )
+ export INIT
+
+ exec machinectl shell -E INIT "$user"@.host ${pkgs.writeDash "login" ''
+ eval "$INIT"
+ unset INIT
+ if test "''${XCOOKIE+x}" = x; then
+ echo "$XCOOKIE" | ${pkgs.coreutils}/bin/base64 -d | ${pkgs.xauth}/bin/xauth merge -
+ unset XCOOKIE
+ fi
+ if test $# = 0; then
+ set -- "$SHELL"
+ fi
+ # dtach-list finds su2 sessions by this process name.
+ exec ${pkgs.otherutils}/bin/exec -n "(su2 $SU2PID $1)" "$@"
+ ''} "$@"
+ ;;
+ esac
+''
diff --git a/pkgs/simple/withLocalBuild.nix b/pkgs/simple/withLocalBuild.nix
new file mode 100644
index 00000000..4bd599d7
--- /dev/null
+++ b/pkgs/simple/withLocalBuild.nix
@@ -0,0 +1,30 @@
+# Wraps each program of a package, so that it runs the local build
+# ~/tmp/cache/<package>/bin/<program> instead, when that exists.
+{ lib, pkgs, ... }:
+
+pkg: let
+ name = lib.getName pkg;
+ bin = lib.getBin pkg;
+in
+pkgs.symlinkJoin {
+ name = "${name}-with-local-build";
+ paths = [
+ (pkgs.runCommand "${name}-local-build-wrappers" {} /* sh */ ''
+ mkdir -p $out/bin
+ for path in ${bin}/bin/*; do
+ program=''${path##*/}
+ {
+ echo '#! ${pkgs.dash}/bin/dash'
+ echo "local=\$HOME/tmp/cache/${name}/bin/$program"
+ echo 'if test -x "$local"; then'
+ echo ' echo "using local build $local" >&2'
+ echo ' exec "$local" "$@"'
+ echo 'fi'
+ echo "exec $path \"\$@\""
+ } > $out/bin/$program
+ chmod +x $out/bin/$program
+ done
+ '')
+ pkg
+ ];
+}
diff --git a/pkgs/simple/xauth-user.nix b/pkgs/simple/xauth-user.nix
new file mode 100644
index 00000000..c663d916
--- /dev/null
+++ b/pkgs/simple/xauth-user.nix
@@ -0,0 +1,38 @@
+{ pkgs }:
+
+pkgs.writeDashBin "xauth-user" ''
+ #! /bin/sh
+ #
+ # usage: xauth-user NAME [DISPLAY] [--trusted]
+ #
+ set -efu
+
+ username=$1; shift
+ if test $# -gt 0 && test "$(printf %.1s "$1")" = :; then
+ display=$1; shift
+ else
+ display=$DISPLAY
+ fi
+ if test $# -gt 0 && test "$1" = --trusted; then
+ trusted=trusted; shift
+ else
+ trusted=untrusted
+ fi
+ if test $# -gt 0; then
+ echo "$0: error: bad arguments: $*" >&2
+ exit 1
+ fi
+
+ cleanup() {
+ ${pkgs.coreutils}/bin/rm "$tempfile"
+ trap - EXIT
+ }
+ trap cleanup EXIT
+ tempfile=$(${pkgs.coreutils}/bin/mktemp --tmpdir xauth-user.XXXXXXXX)
+ ${pkgs.coreutils}/bin/chmod 0600 "$tempfile"
+
+ set -x
+ ${pkgs.xauth}/bin/xauth -f "$tempfile" generate "$display" . "$trusted" timeout 86400
+ ${pkgs.xauth}/bin/xauth -f "$tempfile" extract - "$display" |
+ sudo -iu "$username" ${pkgs.xauth}/bin/xauth merge -
+''
diff --git a/pkgs/simple/xkeyboard_config-tv.nix b/pkgs/simple/xkeyboard_config-tv.nix
new file mode 100644
index 00000000..bc1f026f
--- /dev/null
+++ b/pkgs/simple/xkeyboard_config-tv.nix
@@ -0,0 +1,16 @@
+# xkeyboard_config with inet symbols that make F13 to F24 produce the X
+# keysyms F13 to F24.
+{ lib, pkgs }:
+
+pkgs.xkeyboard_config.overrideAttrs (_: {
+ pname = "xkeyboard-config-tv";
+ postFixup = /* sh */ ''
+ ${pkgs.gnused}/bin/sed -i -r '
+ s/(key <FK(13|14|15|16|17|18|19|20|21|22|23|24)>).*/\1 { [ F\2 ] };/g
+ s/^xkb_symbols "evdev" .*/&\n${lib.concatStringsSep ''\n '' [
+ "key <FK19> { [ F19 ] };"
+ "key <FK24> { [ F24 ] };"
+ ]}/
+ ' $out/share/X11/xkb/symbols/inet
+ '';
+})