From 6e8aae7d8ddf8d75a0dd570611326e62c8e5626b Mon Sep 17 00:00:00 2001 From: oddlama Date: Mon, 16 Oct 2023 00:46:30 +0200 Subject: [PATCH] refactor(screenshots): use separate scripts package --- flake.lock | 36 ++++----- lib/disko.nix | 4 +- lib/misc.nix | 6 +- lib/net.nix | 6 +- lib/types.nix | 4 +- lib/wireguard.nix | 8 +- modules/meta/microvms.nix | 2 + pkgs/caddy.nix | 10 +-- pkgs/default.nix | 23 +++--- pkgs/scripts/default.nix | 7 ++ pkgs/scripts/screenshot-area-scan-qr.nix | 58 +++++++++++++++ pkgs/scripts/screenshot-area.nix | 46 ++++++++++++ pkgs/scripts/screenshot-screen.nix | 20 +++++ users/myuser/graphical/i3.nix | 94 +++++++++--------------- users/myuser/graphical/sway.nix | 1 + 15 files changed, 216 insertions(+), 109 deletions(-) create mode 100644 pkgs/scripts/default.nix create mode 100644 pkgs/scripts/screenshot-area-scan-qr.nix create mode 100644 pkgs/scripts/screenshot-area.nix create mode 100644 pkgs/scripts/screenshot-screen.nix diff --git a/flake.lock b/flake.lock index f6473bd..7de1bc2 100644 --- a/flake.lock +++ b/flake.lock @@ -664,11 +664,11 @@ ] }, "locked": { - "lastModified": 1697323135, - "narHash": "sha256-tlAv11c0NIRTk2IzpFxYknHrveeFXojVyCTAMg749Zg=", + "lastModified": 1697371398, + "narHash": "sha256-Tn5feZ5SoYHQM9BTjw5e06DuNu8wc21gC9+bq/kXA8Y=", "owner": "nix-community", "repo": "home-manager", - "rev": "d4a5076ea8c2c063c45e0165f9f75f69ef583e20", + "rev": "3b67ae3f665379c06999641f99d94dba75b53876", "type": "github" }, "original": { @@ -698,11 +698,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1696766909, - "narHash": "sha256-lU1BmCWpQ9cx64YnJKc89lMg9cx4pCokXIbh5J//2t0=", + "lastModified": 1697371715, + "narHash": "sha256-1ZV4qoL1B35DsciS/inC+z6vAwjxjWHL3+4G4QQhT0A=", "owner": "nix-community", "repo": "lib-aggregate", - "rev": "9f495e4feea66426589cbb59ac8b972993b5d872", + "rev": "af42578368ca0c97d5836ba55b146745911aaecc", "type": "github" }, "original": { @@ -773,11 +773,11 @@ ] }, "locked": { - "lastModified": 1696736548, - "narHash": "sha256-Dg0gJ9xVXud55sAbXspMapFYZOpVAldQQo7MFp91Vb0=", + "lastModified": 1697340827, + "narHash": "sha256-XlrR68N7jyaZ0bs8TPrhqcWG0IPG3pbjrKzJMpYOsos=", "owner": "Mic92", "repo": "nix-index-database", - "rev": "2902dc66f64f733bfb45754e984e958e9fe7faf9", + "rev": "29977d0796c058bbcfb2df5b18eb5badf1711007", "type": "github" }, "original": { @@ -877,11 +877,11 @@ }, "nixpkgs-lib": { "locked": { - "lastModified": 1696726172, - "narHash": "sha256-89yxFXzTA7JRyWo6hg7SD4DlS/ejYt8Y8IvGZHbSWsg=", + "lastModified": 1697331025, + "narHash": "sha256-a5LJWWHfEvnq9tBd9UyNVdtzLXc2ehu5MCp//Bex/0E=", "owner": "nix-community", "repo": "nixpkgs.lib", - "rev": "59da6ac0c02c48aa92dee37057f978412797db2a", + "rev": "05c07c73de74725ec7efa6609011687035a92c0f", "type": "github" }, "original": { @@ -948,11 +948,11 @@ ] }, "locked": { - "lastModified": 1697300259, - "narHash": "sha256-gmLtTy9kuLnw5MekDHY1Roc36kkEsLNTnKq8lSQkD3U=", + "lastModified": 1697372844, + "narHash": "sha256-Ut7Bojh7SqNf2pKRIoGPWWRU9ZjvSxSJS+GByC8AHD0=", "owner": "nix-community", "repo": "nixpkgs-wayland", - "rev": "6b428305043afaf77119adb44dfea246c809e07f", + "rev": "3bd7c4e831bc3dc82828e179397b06652adf2878", "type": "github" }, "original": { @@ -1258,11 +1258,11 @@ }, "templates": { "locked": { - "lastModified": 1691421369, - "narHash": "sha256-Agfum0ykpUxUUS4AKYPVSWF+NeHPWay2o1TTNH0BFXA=", + "lastModified": 1697364028, + "narHash": "sha256-t7IGwY/nvopK9n9tgCVrHlLimhU2MuoP9VbVy07AR2A=", "owner": "NixOS", "repo": "templates", - "rev": "0fb94bf87144b18e42765693c3e15ac5f17eeab0", + "rev": "98bc26d94008617aac7cd0244fb09ff04d6c8cf6", "type": "github" }, "original": { diff --git a/lib/disko.nix b/lib/disko.nix index d603877..1d9dd0b 100644 --- a/lib/disko.nix +++ b/lib/disko.nix @@ -1,6 +1,6 @@ -_inputs: _self: super: { +_inputs: _final: prev: { lib = - super.lib + prev.lib // { disko = { gpt = { diff --git a/lib/misc.nix b/lib/misc.nix index 38ba180..cb91dc7 100644 --- a/lib/misc.nix +++ b/lib/misc.nix @@ -1,6 +1,6 @@ -inputs: self: super: let +inputs: _final: prev: let inherit - (super.lib) + (prev.lib) concatMapStrings escapeShellArg filter @@ -71,7 +71,7 @@ inputs: self: super: let hexToDec = v: foldl' (acc: x: acc * 16 + hexLiteralValues.${x}) 0 (stringToCharacters v); in { lib = - super.lib + prev.lib // { inherit concatAttrs diff --git a/lib/net.nix b/lib/net.nix index 5dba681..e461bc5 100644 --- a/lib/net.nix +++ b/lib/net.nix @@ -1,4 +1,4 @@ -inputs: self: super: let +inputs: final: prev: let inherit (inputs.nixpkgs.lib) all @@ -22,7 +22,7 @@ inputs: self: super: let ; inherit - (self.lib) + (final.lib) hexToDec pow ; @@ -37,7 +37,7 @@ inputs: self: super: let .lib .net; in { - lib = recursiveUpdate super.lib { + lib = recursiveUpdate prev.lib { net = recursiveUpdate (removeAttrs libNet ["types"]) { cidr = rec { # host :: (ip | mac | integer) -> cidr -> ip diff --git a/lib/types.nix b/lib/types.nix index 019086f..2bbea2b 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -1,4 +1,4 @@ -inputs: _self: super: let +inputs: _final: prev: let inherit (inputs.nixpkgs.lib) all @@ -39,7 +39,7 @@ inputs: _self: super: let # automatically be coerced to the given type when merged. lazyOf = type: types.coercedTo (lazyValueOf type) (x: x._lazyValue) type; in { - lib = recursiveUpdate super.lib { + lib = recursiveUpdate prev.lib { types = { inherit isLazyValue diff --git a/lib/wireguard.nix b/lib/wireguard.nix index 2ea11e7..2355909 100644 --- a/lib/wireguard.nix +++ b/lib/wireguard.nix @@ -1,4 +1,4 @@ -inputs: self: super: let +inputs: final: prev: let inherit (inputs.nixpkgs.lib) assertMsg @@ -19,21 +19,21 @@ inputs: self: super: let ; inherit - (self.lib) + (final.lib) net concatAttrs types ; inherit - (self.lib.secrets) + (final.lib.secrets) rageDecryptArgs ; inherit (inputs.self) nodes; in { lib = - super.lib + prev.lib // { wireguard = wgName: let # Returns the given node's wireguard configuration of this network diff --git a/modules/meta/microvms.nix b/modules/meta/microvms.nix index d6dbeb2..9ce2cd5 100644 --- a/modules/meta/microvms.nix +++ b/modules/meta/microvms.nix @@ -102,6 +102,8 @@ imports = cfg.commonImports ++ vmCfg.modules; node.name = vmCfg.nodeName; + # TODO needed because of https://github.com/NixOS/nixpkgs/issues/102137 + environment.noXlibs = mkForce false; lib.microvm.mac = mac; microvm = { diff --git a/pkgs/caddy.nix b/pkgs/caddy.nix index f452b30..afefc12 100644 --- a/pkgs/caddy.nix +++ b/pkgs/caddy.nix @@ -1,6 +1,6 @@ -self: super: let +_final: prev: let inherit - (self.lib) + (prev.lib) escapeShellArg concatMapStrings flip @@ -20,9 +20,9 @@ self: super: let version, }: "go get ${escapeShellArg name}@${escapeShellArg version}\n"); in - super.caddy.override { + prev.caddy.override { buildGoModule = args: - super.buildGoModule (args + prev.buildGoModule (args // { inherit vendorHash; passthru.plugins = plugins; @@ -44,5 +44,5 @@ in { # ]; # vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; # } - caddy = super.caddy.overrideAttrs (_: {passthru.withPackages = make-custom-caddy;}); + caddy = prev.caddy.overrideAttrs (_: {passthru.withPackages = make-custom-caddy;}); } diff --git a/pkgs/default.nix b/pkgs/default.nix index ddb5b26..0639417 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,21 +1,22 @@ [ (import ./caddy.nix) (import ./oauth2-proxy) - (_self: super: { - deploy = super.callPackage ./deploy.nix {}; - git-fuzzy = super.callPackage ./git-fuzzy {}; - kanidm-secret-manipulator = super.callPackage ./kanidm-secret-manipulator.nix {}; - segoe-ui-ttf = super.callPackage ./segoe-ui-ttf.nix {}; - zsh-histdb-skim = super.callPackage ./zsh-skim-histdb.nix {}; + (import ./scripts) + (_final: prev: { + deploy = prev.callPackage ./deploy.nix {}; + git-fuzzy = prev.callPackage ./git-fuzzy {}; + kanidm-secret-manipulator = prev.callPackage ./kanidm-secret-manipulator.nix {}; + segoe-ui-ttf = prev.callPackage ./segoe-ui-ttf.nix {}; + zsh-histdb-skim = prev.callPackage ./zsh-skim-histdb.nix {}; - kanidm = super.kanidm.overrideAttrs (_finalAttrs: _previousAttrs: { + kanidm = prev.kanidm.overrideAttrs (_finalAttrs: _previousAttrs: { patches = [ - (super.fetchpatch { + (prev.fetchpatch { name = "group-list-json-output.patch"; url = "https://patch-diff.githubusercontent.com/raw/kanidm/kanidm/pull/2016.patch"; hash = "sha256-gc75KBzhth4fZvuvRa3Rjg1J7DIGy25mzUPCf2aha80="; }) - (super.fetchpatch { + (prev.fetchpatch { name = "person-and-oauth-json-output.patch"; url = "https://patch-diff.githubusercontent.com/raw/kanidm/kanidm/pull/2017.patch"; hash = "sha256-fZgJ7dY2LHvBi64A/6o7kfArUAsLqjWRRpH2q1GL5ic="; @@ -26,9 +27,9 @@ }); formats = - super.formats + prev.formats // { - ron = import ./ron.nix {inherit (super) lib pkgs;}; + ron = import ./ron.nix {inherit (prev) lib pkgs;}; }; }) ] diff --git a/pkgs/scripts/default.nix b/pkgs/scripts/default.nix new file mode 100644 index 0000000..687cd14 --- /dev/null +++ b/pkgs/scripts/default.nix @@ -0,0 +1,7 @@ +_final: prev: { + scripts = { + screenshot-area = prev.callPackage ./screenshot-area.nix {}; + screenshot-area-scan-qr = prev.callPackage ./screenshot-area-scan-qr.nix {}; + screenshot-screen = prev.callPackage ./screenshot-screen.nix {}; + }; +} diff --git a/pkgs/scripts/screenshot-area-scan-qr.nix b/pkgs/scripts/screenshot-area-scan-qr.nix new file mode 100644 index 0000000..bb61fc4 --- /dev/null +++ b/pkgs/scripts/screenshot-area-scan-qr.nix @@ -0,0 +1,58 @@ +{ + writeShellApplication, + libnotify, + xclip, + maim, + zbar, + yq, +}: +writeShellApplication { + name = "screenshot-area-scan-qr"; + text = '' + set -euo pipefail + umask 077 + + # Create in-memory tmpfile + TMPFILE=$(mktemp) + exec 3<>"$TMPFILE" + rm "$TMPFILE" # still open in-memory as /dev/fd/3 + TMPFILE=/dev/fd/3 + + date=$(date +"%Y-%m-%dT%H:%M:%S%:z") + out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-selection.png" + mkdir -p "$(dirname "$out")" + + if ${maim}/bin/maim --color=.4,.7,1 --bordersize=1.0 --nodecorations=1 --hidecursor --format=png --quality=10 --noopengl --select \ + | ${zbar}/bin/zbarimg --xml - > "$TMPFILE"; then + N=$(${yq}/bin/xq -r '.barcodes.source.index.symbol | if type == "array" then length else 1 end' < "$TMPFILE") + # Append codes Copy data separated by --- + DATA=$(${yq}/bin/xq -r '.barcodes.source.index.symbol | if type == "array" then .[0].data else .data end' < "$TMPFILE") + for ((i=1;i"$TMPFILE" - rm "$TMPFILE" # still open in-memory as /dev/fd/3 - TMPFILE=/dev/fd/3 - - if ${pkgs.maim}/bin/maim --color=.4,.7,1 --bordersize=1.0 --nodecorations=1 --hidecursor --format=png --quality=10 --noopengl --select \ - | ${pkgs.zbar}/bin/zbarimg --xml - > "$TMPFILE"; then - N=$(${pkgs.yq}/bin/xq -r '.barcodes.source.index.symbol | if type == "array" then length else 1 end' < "$TMPFILE") - # Append codes Copy data separated by --- - DATA=$(${pkgs.yq}/bin/xq -r '.barcodes.source.index.symbol | if type == "array" then .[0].data else .data end' < "$TMPFILE") - for ((i=1;i