feat: add time-window

No more random lisp scripts and derivations in my main NixOS config anymore
This commit is contained in:
eriedaberrie 2024-10-28 00:02:24 -07:00
parent 1d9f562236
commit 74691af79e
6 changed files with 114 additions and 1 deletions

View file

@ -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"
}

View file

@ -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;
};
};
};

44
nix/time-window.nix Normal file
View file

@ -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

7
time-window.asd Normal file
View file

@ -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))

3
time-window/package.lisp Normal file
View file

@ -0,0 +1,3 @@
(uiop:define-package #:time-window
(:use #:cl)
(:export #:time-window #:main))

View file

@ -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)))