summaryrefslogtreecommitdiffstats
path: root/tv
diff options
context:
space:
mode:
authorlassulus <git@lassul.us>2023-02-03 13:28:15 +0100
committerlassulus <git@lassul.us>2023-02-03 13:28:15 +0100
commit66586d70beeb8c02a6ad695303d30709c17a1c27 (patch)
tree91f208975d677a659ac14164c36034ac44d06738 /tv
parent2fa9f8601ed3f5c81316b9b780a03d414b4de9b3 (diff)
parentaf9e845e861b51d691102c1bc177dfe5e26fe63f (diff)
Merge remote-tracking branch 'ni/master'
Diffstat (limited to 'tv')
-rw-r--r--tv/2configs/wiregrill.nix4
-rw-r--r--tv/5pkgs/haskell/flameshot-once.nix20
-rw-r--r--tv/5pkgs/haskell/xmonad-tv/src/main.hs12
-rw-r--r--tv/5pkgs/simple/flameshot-once/default.nix28
-rw-r--r--tv/5pkgs/simple/flameshot-once/profile.nix235
5 files changed, 295 insertions, 4 deletions
diff --git a/tv/2configs/wiregrill.nix b/tv/2configs/wiregrill.nix
index d28a1ec29..edf65e979 100644
--- a/tv/2configs/wiregrill.nix
+++ b/tv/2configs/wiregrill.nix
@@ -28,8 +28,8 @@ in
systemd.network.networks.wiregrill = {
matchConfig.Name = "wiregrill";
address =
- optional (!isNull cfg.net.ip4) (toCidrNotation cfg.net.ip4) ++
- optional (!isNull cfg.net.ip6) (toCidrNotation cfg.net.ip6);
+ optional (cfg.net.ip4 != null) (toCidrNotation cfg.net.ip4) ++
+ optional (cfg.net.ip6 != null) (toCidrNotation cfg.net.ip6);
};
tv.iptables.extra.filter.INPUT = [
"-p udp --dport ${toString cfg.net.wireguard.port} -j ACCEPT"
diff --git a/tv/5pkgs/haskell/flameshot-once.nix b/tv/5pkgs/haskell/flameshot-once.nix
new file mode 100644
index 000000000..c8007ce9e
--- /dev/null
+++ b/tv/5pkgs/haskell/flameshot-once.nix
@@ -0,0 +1,20 @@
+{ mkDerivation, async, base, blessings, bytestring, dbus, fetchgit
+, iso8601-time, lib, process, random, text, time, unagi-chan, unix
+}:
+mkDerivation {
+ pname = "flameshot-once";
+ version = "1.4.0";
+ src = fetchgit {
+ url = "https://cgit.krebsco.de/flameshot-once";
+ sha256 = "13szgsiwn29aixm5xvs1m7128y5km5xss0ry5ii5y068rc2vysw8";
+ rev = "4475893c2081b3d9db4b7a54d0ce38d0914a17bf";
+ fetchSubmodules = true;
+ };
+ isLibrary = false;
+ isExecutable = true;
+ executableHaskellDepends = [
+ async base blessings bytestring dbus iso8601-time process random
+ text time unagi-chan unix
+ ];
+ license = lib.licenses.mit;
+}
diff --git a/tv/5pkgs/haskell/xmonad-tv/src/main.hs b/tv/5pkgs/haskell/xmonad-tv/src/main.hs
index eb61bd5cf..118f2da46 100644
--- a/tv/5pkgs/haskell/xmonad-tv/src/main.hs
+++ b/tv/5pkgs/haskell/xmonad-tv/src/main.hs
@@ -23,6 +23,7 @@ import System.Posix.Process (executeFile)
import XMonad.Actions.DynamicWorkspaces ( addWorkspacePrompt, renameWorkspace
, removeEmptyWorkspace)
import XMonad.Actions.CycleWS (toggleWS)
+import XMonad.Layout.Gaps (Direction2D(U,R,D,L), gaps)
import XMonad.Layout.NoBorders ( smartBorders )
import XMonad.Layout.ResizableTile (ResizableTall(ResizableTall))
import XMonad.Layout.ResizableTile (MirrorResize(MirrorExpand,MirrorShrink))
@@ -58,13 +59,19 @@ main = getArgs >>= \case
readEnv :: Data.Aeson.FromJSON b => String -> IO b
readEnv name =
- Data.Maybe.fromJust
+ readEnv' (error $ "could not get environment variable: " <> name) name
+
+readEnv' :: Data.Aeson.FromJSON b => b -> String -> IO b
+readEnv' defaultValue name =
+ Data.Maybe.fromMaybe defaultValue
. Data.Aeson.decodeStrict'
. Data.ByteString.Char8.pack
- <$> getEnv name
+ . Data.Maybe.fromMaybe mempty
+ <$> lookupEnv name
mainNoArgs :: IO ()
mainNoArgs = do
+ myScreenGaps <- readEnv' [] "XMONAD_SCREEN_GAPS" :: IO [Int]
myScreenWidth <- readEnv "XMONAD_SCREEN_WIDTH" :: IO Dimension
myTermFont <- getEnv "XMONAD_TERM_FONT"
myTermFontWidth <- readEnv "XMONAD_TERM_FONT_WIDTH" :: IO Dimension
@@ -89,6 +96,7 @@ mainNoArgs = do
, workspaces = workspaces0
, layoutHook =
refocusLastLayoutHook $
+ gaps (zip [U,R,D,L] myScreenGaps) $
smartBorders $
ResizableTall
1
diff --git a/tv/5pkgs/simple/flameshot-once/default.nix b/tv/5pkgs/simple/flameshot-once/default.nix
new file mode 100644
index 000000000..0524c2cfa
--- /dev/null
+++ b/tv/5pkgs/simple/flameshot-once/default.nix
@@ -0,0 +1,28 @@
+{ pkgs, stockholm, ... }@args:
+with stockholm.lib;
+
+let
+ # config cannot be declared in the input attribute set because that would
+ # cause callPackage to inject the wrong config. Instead, get it from ...
+ # via args.
+ config = args.config or {};
+in
+
+ pkgs.symlinkJoin {
+ name = "flameshot-once-wrapper";
+ paths = [
+ (pkgs.writeDashBin "flameshot-once" ''
+ export PATH=${makeBinPath [
+ pkgs.flameshot
+ pkgs.qt5.qtbase
+ pkgs.xclip
+ pkgs.xwaitforwindow
+ ]}
+ ${optionalString (config != null) /* sh */ ''
+ . ${import ./profile.nix { inherit config pkgs; }}
+ ''}
+ exec ${pkgs.haskellPackages.flameshot-once}/bin/flameshot-once "$@"
+ '')
+ pkgs.haskellPackages.flameshot-once
+ ];
+ }
diff --git a/tv/5pkgs/simple/flameshot-once/profile.nix b/tv/5pkgs/simple/flameshot-once/profile.nix
new file mode 100644
index 000000000..269f13a66
--- /dev/null
+++ b/tv/5pkgs/simple/flameshot-once/profile.nix
@@ -0,0 +1,235 @@
+{ config, pkgs }:
+with pkgs.stockholm.lib;
+with generators;
+let
+
+ # Refs https://github.com/lupoDharkael/flameshot/blob/master/src/widgets/capture/capturebutton.h
+ ButtonType = {
+ PENCIL = 0;
+ DRAWER = 1;
+ ARROW = 2;
+ SELECTION = 3;
+ RECTANGLE = 4;
+ CIRCLE = 5;
+ MARKER = 6;
+ SELECTIONINDICATOR = 7;
+ MOVESELECTION = 8;
+ UNDO = 9;
+ COPY = 10;
+ SAVE = 11;
+ EXIT = 12;
+ IMAGEUPLOADER = 13;
+ OPEN_APP = 14;
+ BLUR = 15;
+ REDO = 16;
+ PIN = 17;
+ TEXT = 18;
+ CIRCLECOUNT = 19;
+ };
+
+ cfg = eval.config;
+
+ eval = evalModules {
+ modules = singleton {
+ _file = toString ./profile.nix;
+ imports = singleton config;
+ options = {
+ buttons = mkOption {
+ apply = map (name: ButtonType.${name});
+ default = [
+ "PENCIL"
+ "DRAWER"
+ "ARROW"
+ "SELECTION"
+ "RECTANGLE"
+ "CIRCLE"
+ "MARKER"
+ "SELECTIONINDICATOR"
+ "MOVESELECTION"
+ "UNDO"
+ "SAVE"
+ "EXIT"
+ "BLUR"
+ "CIRCLECOUNT"
+ ]
+ ++ optional cfg.imgur.enable "IMAGEUPLOADER"
+ ;
+ type = types.listOf (types.enum (attrNames ButtonType));
+ };
+ copyAndCloseAfterUpload = mkOption {
+ default = false;
+ type = types.bool;
+ };
+ disabledTrayIcon = mkOption {
+ default = true;
+ type = types.bool;
+ };
+ drawColor = mkOption {
+ default = "#ff0000";
+ type =
+ types.addCheck types.str (test "#[0-9A-Fa-f]{6}");
+ };
+ drawThickness = mkOption {
+ default = 8;
+ type = types.positive;
+ };
+ filenamePattern = mkOption {
+ default = "%FT%T%z_flameshot";
+ type =
+ # This is types.filename extended by [%:][%:+]*
+ types.addCheck types.str (test "[%:0-9A-Za-z._][%:+0-9A-Za-z._-]*");
+ };
+ imgur = mkOption {
+ default = {};
+ type = types.submodule {
+ options = {
+ enable = mkEnableOption "imgur";
+ createUrl = mkOption {
+ example = "http://p.r/image";
+ type = types.str;
+ };
+ deleteUrl = mkOption {
+ example = "http://p.r/image/delete/%1";
+ type = types.str;
+ };
+ xdg-open = mkOption {
+ default = {};
+ type = types.submodule {
+ options = {
+ enable = mkEnableOption "imgur.xdg-open" // {
+ default = true;
+ };
+ browser = mkOption {
+ default = "${pkgs.coreutils}/bin/false";
+ type = types.str;
+ };
+ createPrefix = mkOption {
+ default = cfg.imgur.createUrl;
+ type = types.str;
+ };
+ deletePrefix = mkOption {
+ default = removeSuffix "/%1" cfg.imgur.deleteUrl;
+ type = types.str;
+ };
+ };
+ };
+ };
+ };
+ };
+ };
+ savePath = mkOption {
+ default = "/tmp";
+ type = types.absolute-pathname;
+ };
+ showDesktopNotification = mkOption {
+ default = false;
+ type = types.bool;
+ };
+ showHelp = mkOption {
+ default = false;
+ type = types.bool;
+ };
+ showSidePanelButton = mkOption {
+ default = false;
+ type = types.bool;
+ };
+ showStartupLaunchMessage = mkOption {
+ default = false;
+ type = types.bool;
+ };
+ timeout = mkOption {
+ default = 200;
+ description = ''
+ Maximum time in milliseconds allowed for the flameshot daemon to
+ react.
+ '';
+ type = types.positive;
+ };
+ };
+ };
+ };
+
+ hexchars = stringToCharacters "0123456789abcdef";
+
+ # Encode integer to C-escaped string of bytes, little endian / LSB 0
+ le = rec {
+ x1 = i: let
+ i0 = mod i 16;
+ i1 = i / 16;
+ in
+ "\\x${elemAt hexchars i1}${elemAt hexchars i0}";
+
+ x2 = i: let
+ i0 = mod i 256;
+ i1 = i / 256;
+ in
+ "${x1 i0}${x1 i1}";
+
+ x4 = i: let
+ i0 = mod i 65536;
+ i1 = i / 65536;
+ in
+ "${x2 i0}${x2 i1}";
+ };
+
+ toQList = t: xs:
+ assert t == "int";
+ "QList<${t}>${le.x4 0}${le.x4 (length xs)}${concatMapStrings le.x4 xs}";
+
+ XDG_CONFIG_HOME = pkgs.write "flameshot-config" {
+ "/flameshot/flameshot.ini".text =
+ toINI {} {
+ General = {
+ buttons = ''@Variant(\0\0\0\x7f\0\0\0\v${toQList "int" cfg.buttons})'';
+ disabledTrayIcon = cfg.disabledTrayIcon;
+ checkForUpdates = false;
+ copyAndCloseAfterUpload = cfg.copyAndCloseAfterUpload;
+ drawColor = cfg.drawColor;
+ drawThickness = cfg.drawThickness;
+ filenamePattern = cfg.filenamePattern;
+ savePath = cfg.savePath;
+ showDesktopNotification = cfg.showDesktopNotification;
+ showHelp = cfg.showHelp;
+ showSidePanelButton = cfg.showSidePanelButton;
+ showStartupLaunchMessage = cfg.showStartupLaunchMessage;
+ startupLaunch = false;
+ };
+ Shortcuts = {
+ TYPE_COPY = "Return";
+ };
+ };
+ };
+
+in
+
+ pkgs.writeDash "flameshot.profile" ''
+ export FLAMESHOT_CAPTURE_PATH=${cfg.savePath}
+ export FLAMESHOT_ONCE_TIMEOUT=${toString cfg.timeout}
+ export XDG_CONFIG_HOME=${XDG_CONFIG_HOME}
+ ${optionalString cfg.imgur.enable /* sh */ ''
+ export IMGUR_CREATE_URL=${shell.escape cfg.imgur.createUrl}
+ export IMGUR_DELETE_URL=${shell.escape cfg.imgur.deleteUrl}
+ ${optionalString cfg.imgur.xdg-open.enable /* sh */ ''
+ PATH=$PATH:${makeBinPath [
+ (pkgs.writeDashBin "xdg-open" ''
+ set -efu
+ uri=$1
+ prefix=$(${pkgs.coreutils}/bin/dirname "$uri")
+ case $prefix in
+ (${shell.escape cfg.imgur.xdg-open.createPrefix})
+ echo "opening image in browser: $uri" >&2
+ exec ${config.imgur.xdg-open.browser} "$uri"
+ ;;
+ (${shell.escape cfg.imgur.xdg-open.deletePrefix})
+ echo "deleting image: $uri" >&2
+ exec ${pkgs.curl}/bin/curl -fsS -X DELETE "$uri"
+ ;;
+ (*)
+ echo "don't know how to open URI: $uri" >&2
+ exit 1
+ esac
+ '')
+ ]}
+ ''}
+ ''}
+ ''