From 7065f73dd336f005307968d79d8080274f21d05b Mon Sep 17 00:00:00 2001 From: eriedaberrie Date: Mon, 28 Oct 2024 00:02:24 -0700 Subject: [PATCH] feat: add time-window No more random lisp scripts and derivations in my main NixOS config anymore --- flake.lock | 24 ++++++++++++++++++++ flake.nix | 12 +++++++++- nix/time-window.nix | 44 ++++++++++++++++++++++++++++++++++++ time-window.asd | 7 ++++++ time-window/package.lisp | 3 +++ time-window/time-window.lisp | 25 ++++++++++++++++++++ 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 nix/time-window.nix create mode 100644 time-window.asd create mode 100644 time-window/package.lisp create mode 100644 time-window/time-window.lisp diff --git a/flake.lock b/flake.lock index e6e1cb3..9e2bbde 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,28 @@ { "nodes": { + "cl-hyprland-ipc": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "systems": [ + "systems" + ] + }, + "locked": { + "lastModified": 1719084187, + "narHash": "sha256-CPDgaFwExL5v7Y0IL6ID/wh9M7A0lGKOh1NS2CoglRM=", + "owner": "eriedaberrie", + "repo": "cl-hyprland-ipc", + "rev": "5be47ac54bf6ce9e6ff0948d2933ab8590d19db7", + "type": "github" + }, + "original": { + "owner": "eriedaberrie", + "repo": "cl-hyprland-ipc", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1729880355, @@ -18,6 +41,7 @@ }, "root": { "inputs": { + "cl-hyprland-ipc": "cl-hyprland-ipc", "nixpkgs": "nixpkgs", "systems": "systems" } diff --git a/flake.nix b/flake.nix index 392f253..094b7eb 100644 --- a/flake.nix +++ b/flake.nix @@ -2,13 +2,19 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; systems.url = "github:nix-systems/default-linux"; + + cl-hyprland-ipc = { + url = "github:eriedaberrie/cl-hyprland-ipc"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.systems.follows = "systems"; + }; }; outputs = { self, nixpkgs, systems, - ... + cl-hyprland-ipc, }: let inherit (nixpkgs) lib; forSystems = f: @@ -17,6 +23,10 @@ overlays = { default = _: prev: { sync-music = prev.callPackage ./nix/sync-music.nix {}; + + time-window = prev.callPackage ./nix/time-window.nix { + inherit (cl-hyprland-ipc.packages.${prev.stdenv.system}) cl-hyprland-ipc; + }; }; }; diff --git a/nix/time-window.nix b/nix/time-window.nix new file mode 100644 index 0000000..8d3c09e --- /dev/null +++ b/nix/time-window.nix @@ -0,0 +1,44 @@ +{ + sbcl, + lib, + cl-hyprland-ipc, + writeText, + makeWrapper, +}: let + time-window = sbcl.buildASDFSystem { + pname = "sync-music"; + version = "dev"; + src = lib.cleanSource ../.; + + lispLibs = [ + cl-hyprland-ipc + ]; + + nativeBuildInputs = [ + makeWrapper + ]; + + buildScript = writeText "build-sync-music.lisp" '' + (load "${time-window.asdfFasl}/asdf.${time-window.faslExt}") + (asdf:load-system :time-window) + + (setf uiop:*image-entry-point* #'time-window:main) + (uiop:dump-image "main" + :executable t + #+sb-core-compression :compression + #+sb-core-compression t) + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + cp -va main $out/bin/time-window + + runHook postInstall + ''; + + meta.mainProgram = "time-window"; + }; +in + time-window diff --git a/time-window.asd b/time-window.asd new file mode 100644 index 0000000..e7990ab --- /dev/null +++ b/time-window.asd @@ -0,0 +1,7 @@ +(asdf:defsystem time-window + :pathname #P"time-window/" + :build-operation "program-op" + :entry-point "time-window:main" + :components ((:file "package") + (:file "time-window" :depends-on ("package"))) + :depends-on (#:cl-hyprland-ipc)) diff --git a/time-window/package.lisp b/time-window/package.lisp new file mode 100644 index 0000000..a552cbf --- /dev/null +++ b/time-window/package.lisp @@ -0,0 +1,3 @@ +(uiop:define-package #:time-window + (:use #:cl) + (:export #:time-window #:main)) diff --git a/time-window/time-window.lisp b/time-window/time-window.lisp new file mode 100644 index 0000000..fe35d97 --- /dev/null +++ b/time-window/time-window.lisp @@ -0,0 +1,25 @@ +(in-package #:time-window) + +(defun time-window (argv use-pid) + (time + (let* ((process-info (uiop:launch-program argv)) + (pid (uiop:process-info-pid process-info))) + (format t "Started process via `~{~A~^ ~}` with PID ~A~%" argv pid) + (hyprland-ipc:handle-events + :return-on-non-nil-p t + :open-window (lambda (address workspace-name class title) + (declare (ignorable address workspace-name class title)) + (or (not use-pid) + (= pid + (gethash "pid" + (hyprland-ipc:find-client-data address))))))))) + +(defun main () + (let* ((argv (uiop:command-line-arguments)) + (use-pid (string= (first argv) "-p"))) + (when use-pid + (setf argv (rest argv))) + (unless argv + (format *error-output* "Needs command string!~%") + (uiop:quit 1 t)) + (time-window argv use-pid)))