From ea0c4558249ff01039b2302fdd9b2ff7496aeede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Mon, 1 Dec 2025 14:05:21 -0700 Subject: [PATCH] refactor(sydnix-cli): rewrite sydnix-cli holy shit. why. why did i write the first version LOL. so fucking ocmplicated. and half broken. --- flake.lock | 186 +---------- flake.nix | 1 - hosts/deertopia/configuration.nix | 4 +- hosts/fruitbook/configuration.nix | 4 +- hosts/live-minimal/configuration.nix | 2 +- hosts/nixos-testbed/configuration.nix | 7 +- hosts/sydpc/configuration.nix | 4 +- .../users/msyds/emacs/lisp/syd/smartparens.el | 8 +- scripts/sydnix-cli/.envrc | 2 +- scripts/sydnix-cli/.gitignore | 10 - scripts/sydnix-cli/bb.edn | 2 + scripts/sydnix-cli/default.nix | 3 + scripts/sydnix-cli/deps-lock.json | 289 ------------------ scripts/sydnix-cli/deps.edn | 21 -- scripts/sydnix-cli/flake.lock | 171 ----------- scripts/sydnix-cli/flake.nix | 67 ---- scripts/sydnix-cli/package.nix | 20 ++ scripts/sydnix-cli/shell.nix | 7 + scripts/sydnix-cli/src/asciidoc/render.clj | 89 ------ scripts/sydnix-cli/src/asciidoc/types.clj | 57 ---- .../sydnix-cli/src/sydnix_cli/cli_table.clj | 3 - .../src/sydnix_cli/commands/help.clj | 40 +-- .../src/sydnix_cli/commands/rebuild.clj | 26 +- .../src/sydnix_cli/commands/status.clj | 11 - .../src/sydnix_cli/commands/util.clj | 8 - .../src/sydnix_cli/commands/util/mangen.clj | 46 --- scripts/sydnix-cli/src/sydnix_cli/main.clj | 48 +-- scripts/sydnix-cli/src/sydnix_cli/mangen.clj | 94 ------ scripts/sydnix-cli/src/sydnix_cli/prelude.clj | 21 -- scripts/sydnix-cli/sydnix | 6 + 30 files changed, 103 insertions(+), 1154 deletions(-) delete mode 100644 scripts/sydnix-cli/.gitignore create mode 100644 scripts/sydnix-cli/bb.edn create mode 100644 scripts/sydnix-cli/default.nix delete mode 100644 scripts/sydnix-cli/deps-lock.json delete mode 100644 scripts/sydnix-cli/deps.edn delete mode 100644 scripts/sydnix-cli/flake.lock delete mode 100644 scripts/sydnix-cli/flake.nix create mode 100644 scripts/sydnix-cli/package.nix create mode 100644 scripts/sydnix-cli/shell.nix delete mode 100644 scripts/sydnix-cli/src/asciidoc/render.clj delete mode 100644 scripts/sydnix-cli/src/asciidoc/types.clj delete mode 100644 scripts/sydnix-cli/src/sydnix_cli/cli_table.clj delete mode 100644 scripts/sydnix-cli/src/sydnix_cli/commands/status.clj delete mode 100644 scripts/sydnix-cli/src/sydnix_cli/commands/util.clj delete mode 100644 scripts/sydnix-cli/src/sydnix_cli/commands/util/mangen.clj delete mode 100644 scripts/sydnix-cli/src/sydnix_cli/mangen.clj delete mode 100644 scripts/sydnix-cli/src/sydnix_cli/prelude.clj create mode 100755 scripts/sydnix-cli/sydnix diff --git a/flake.lock b/flake.lock index 1687530..7f0fbd8 100644 --- a/flake.lock +++ b/flake.lock @@ -68,26 +68,6 @@ "type": "github" } }, - "clj-nix": { - "inputs": { - "devshell": "devshell", - "nix-fetcher-data": "nix-fetcher-data", - "nixpkgs": "nixpkgs_10" - }, - "locked": { - "lastModified": 1732920288, - "narHash": "sha256-w04hFhbutbob60xy6wUYdawBCVK0qAzBfhGsD+bPypU=", - "owner": "jlesquembre", - "repo": "clj-nix", - "rev": "6e829214a303d2f921c7919f6fb7a2721069c608", - "type": "github" - }, - "original": { - "owner": "jlesquembre", - "repo": "clj-nix", - "type": "github" - } - }, "copyparty": { "inputs": { "flake-utils": "flake-utils", @@ -109,28 +89,6 @@ "type": "github" } }, - "devshell": { - "inputs": { - "nixpkgs": [ - "sydnix-cli", - "clj-nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1728330715, - "narHash": "sha256-xRJ2nPOXb//u1jaBnDP56M7v5ldavjbtR6lfGqSvcKg=", - "owner": "numtide", - "repo": "devshell", - "rev": "dd6b80932022cea34a019e2bb32f6fa9e494dfef", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, "disko": { "inputs": { "nixpkgs": "nixpkgs" @@ -258,24 +216,6 @@ "type": "github" } }, - "flake-parts_4": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib_2" - }, - "locked": { - "lastModified": 1719745305, - "narHash": "sha256-xwgjVUpqSviudEkpQnioeez1Uo2wzrsMaJKJClh+Bls=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "c3c5ecc05edc7dafba779c6c1a61cd08ac6583e9", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, "flake-utils": { "locked": { "lastModified": 1678901627, @@ -327,24 +267,6 @@ "type": "github" } }, - "flake-utils_4": { - "inputs": { - "systems": "systems_4" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "fromYaml": { "flake": false, "locked": { @@ -469,29 +391,6 @@ "type": "github" } }, - "nix-fetcher-data": { - "inputs": { - "flake-parts": "flake-parts_4", - "nixpkgs": [ - "sydnix-cli", - "clj-nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1728229178, - "narHash": "sha256-p5Fx880uBYstIsbaDYN7sECJT11oHxZQKtHgMAVblWA=", - "owner": "jlesquembre", - "repo": "nix-fetcher-data", - "rev": "f3a73c34d28db49ef90fd7872a142bfe93120e55", - "type": "github" - }, - "original": { - "owner": "jlesquembre", - "repo": "nix-fetcher-data", - "type": "github" - } - }, "nixarr": { "inputs": { "nixpkgs": [ @@ -568,18 +467,6 @@ "type": "github" } }, - "nixpkgs-lib_2": { - "locked": { - "lastModified": 1717284937, - "narHash": "sha256-lIbdfCsf8LMFloheeE6N31+BMIeixqyQWbSr2vk79EQ=", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" - }, - "original": { - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" - } - }, "nixpkgs-stable": { "locked": { "lastModified": 1742751704, @@ -613,38 +500,6 @@ } }, "nixpkgs_10": { - "locked": { - "lastModified": 1728492678, - "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_11": { - "locked": { - "lastModified": 1737632463, - "narHash": "sha256-38J9QfeGSej341ouwzqf77WIHAScihAKCt8PQJ+NH28=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "0aa475546ed21629c4f5bbf90e38c846a99ec9e9", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_12": { "locked": { "lastModified": 1750386251, "narHash": "sha256-1ovgdmuDYVo5OUC5NzdF+V4zx2uT8RtsgZahxidBTyw=", @@ -660,7 +515,7 @@ "type": "github" } }, - "nixpkgs_13": { + "nixpkgs_11": { "locked": { "lastModified": 1743568003, "narHash": "sha256-ZID5T65E8ruHqWRcdvZLsczWDOAWIE7om+vQOREwiX0=", @@ -866,7 +721,6 @@ "sops-nix": "sops-nix", "stylix": "stylix", "syd-fcitx5-tables": "syd-fcitx5-tables", - "sydnix-cli": "sydnix-cli", "sydpkgs": "sydpkgs", "tf2-nix": "tf2-nix", "vpn-confinement": "vpn-confinement" @@ -941,26 +795,9 @@ "type": "gitlab" } }, - "sydnix-cli": { - "inputs": { - "clj-nix": "clj-nix", - "flake-utils": "flake-utils_3", - "nixpkgs": "nixpkgs_11" - }, - "locked": { - "lastModified": 1762218505, - "narHash": "sha256-Hj55AYHzMlH1VwASNEqWbLyMTULLYPfkMrJTqNZFjh4=", - "path": "/persist/dots/scripts/sydnix-cli", - "type": "path" - }, - "original": { - "path": "/persist/dots/scripts/sydnix-cli", - "type": "path" - } - }, "sydpkgs": { "inputs": { - "nixpkgs": "nixpkgs_12" + "nixpkgs": "nixpkgs_10" }, "locked": { "lastModified": 1758168482, @@ -1021,25 +858,10 @@ "type": "github" } }, - "systems_4": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, "tf2-nix": { "inputs": { - "flake-utils": "flake-utils_4", - "nixpkgs": "nixpkgs_13" + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs_11" }, "locked": { "lastModified": 1761467191, diff --git a/flake.nix b/flake.nix index b6c072e..e55695a 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,6 @@ impermanence.url = "github:nix-community/impermanence"; home-manager.url = "github:nix-community/home-manager"; sops-nix.url = "github:Mic92/sops-nix"; - sydnix-cli.url = "path:///persist/dots/scripts/sydnix-cli"; copyparty = { url = "github:9001/copyparty"; inputs.nixpkgs.follows = "nixpkgs"; diff --git a/hosts/deertopia/configuration.nix b/hosts/deertopia/configuration.nix index 4607890..2a2ff3c 100644 --- a/hosts/deertopia/configuration.nix +++ b/hosts/deertopia/configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, disko, sydnix-cli, ... }: +{ config, pkgs, lib, disko, ... }: { imports = [ @@ -102,9 +102,9 @@ git sshfs waypipe - sydnix-cli.packages.x86_64-linux.default (import ../../scripts/port-tools { inherit pkgs; }) (import ../../scripts/vpn-tools { inherit pkgs; }) + (import ../../scripts/sydnix-cli { inherit pkgs; }) ]; # This server is connected to the internet! Port 22 is open!! Aagghhhh!!! diff --git a/hosts/fruitbook/configuration.nix b/hosts/fruitbook/configuration.nix index 4b775c8..996ff24 100644 --- a/hosts/fruitbook/configuration.nix +++ b/hosts/fruitbook/configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, disko, sydnix-cli, ... }: +{ config, pkgs, lib, disko, ... }: { imports = [ @@ -93,7 +93,7 @@ pkgs.neovim pkgs.git pkgs.waypipe - sydnix-cli.packages.x86_64-linux.default + (import ../../scripts/sydnix-cli { inherit pkgs; }) ]; services.flatpak.enable = true; diff --git a/hosts/live-minimal/configuration.nix b/hosts/live-minimal/configuration.nix index 2f66d2a..a8dca9c 100644 --- a/hosts/live-minimal/configuration.nix +++ b/hosts/live-minimal/configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, disko, sydnix-cli, modulesPath, ... }: +{ config, pkgs, lib, disko, modulesPath, ... }: { imports = [ diff --git a/hosts/nixos-testbed/configuration.nix b/hosts/nixos-testbed/configuration.nix index a9667ec..f440a5d 100644 --- a/hosts/nixos-testbed/configuration.nix +++ b/hosts/nixos-testbed/configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, disko, sydnix-cli, ... }: +{ config, pkgs, lib, disko, ... }: { imports = [ ./hardware.nix @@ -48,8 +48,9 @@ neovim git waypipe - sydnix-cli.packages.x86_64-linux.default - (import ../../scripts/port-tools { inherit pkgs; }) + (let scripts = ["port-tools" "sydnix-cli"]; + in map (s: import ../../scripts/${s} { inherit pkgs; }) + scripts) ]; services.openssh = { diff --git a/hosts/sydpc/configuration.nix b/hosts/sydpc/configuration.nix index ef03242..af01c49 100755 --- a/hosts/sydpc/configuration.nix +++ b/hosts/sydpc/configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, disko, sydnix-cli, ... }: +{ config, pkgs, lib, disko, ... }: { imports = [ @@ -112,8 +112,8 @@ environment.systemPackages = [ pkgs.neovim pkgs.git - sydnix-cli.packages.x86_64-linux.default (import ../../scripts/port-tools { inherit pkgs; }) + (import ../../scripts/sydnix-cli { inherit pkgs; }) # Waypipe provides the equivalent of X11 forwarding for Wayland. When # connecting to a remote, it is required that `waypipe` is on the remote's diff --git a/modules/home/users/msyds/emacs/lisp/syd/smartparens.el b/modules/home/users/msyds/emacs/lisp/syd/smartparens.el index 3e8fd53..c064d27 100755 --- a/modules/home/users/msyds/emacs/lisp/syd/smartparens.el +++ b/modules/home/users/msyds/emacs/lisp/syd/smartparens.el @@ -10,7 +10,7 @@ (use-package smartparens :hook (on-first-buffer . smartparens-global-mode) :commands (sp-pair sp-local-pair sp-with-modes - sp-point-in-comment sp-point-in-string) + sp-point-in-comment sp-point-in-string) :custom ;; Overlays are too distracting and not terribly helpful. show-parens does ;; this for us already (and is faster), so... @@ -59,8 +59,8 @@ It is only enabled it if `smartparens-global-mode' is on." ("⟅" . "⟆"))) (sp-pair (car pair) (cdr pair))) - (sp-local-pair - '(js-mode nix-mode) - "{" nil :post-handlers '(("||\n[i]" "RET")))) + (sp-with-modes '(js-mode nix-mode) + (sp-local-pair "{" nil :post-handlers '(("||\n[i]" "RET"))) + (sp-local-pair "[" nil :post-handlers '(("||\n[i]" "RET"))))) (provide 'syd/smartparens) diff --git a/scripts/sydnix-cli/.envrc b/scripts/sydnix-cli/.envrc index 3550a30..1d953f4 100644 --- a/scripts/sydnix-cli/.envrc +++ b/scripts/sydnix-cli/.envrc @@ -1 +1 @@ -use flake +use nix diff --git a/scripts/sydnix-cli/.gitignore b/scripts/sydnix-cli/.gitignore deleted file mode 100644 index 1fcb19e..0000000 --- a/scripts/sydnix-cli/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -result -.nrepl -.nrepl-port -.cpcache/ -.cache/ -.lsp/ -.clj-kondo -.cpcache -.lsp -.nrepl diff --git a/scripts/sydnix-cli/bb.edn b/scripts/sydnix-cli/bb.edn new file mode 100644 index 0000000..9f82c8e --- /dev/null +++ b/scripts/sydnix-cli/bb.edn @@ -0,0 +1,2 @@ +{:paths ["src"] + :deps {org.babashka/cli {:mvn/version "0.8.67"}}} diff --git a/scripts/sydnix-cli/default.nix b/scripts/sydnix-cli/default.nix new file mode 100644 index 0000000..a9da50f --- /dev/null +++ b/scripts/sydnix-cli/default.nix @@ -0,0 +1,3 @@ +{ pkgs ? import {} }: + +pkgs.callPackage ./package.nix {} diff --git a/scripts/sydnix-cli/deps-lock.json b/scripts/sydnix-cli/deps-lock.json deleted file mode 100644 index 6b3dc59..0000000 --- a/scripts/sydnix-cli/deps-lock.json +++ /dev/null @@ -1,289 +0,0 @@ -{ - "lock-version": 4, - "git-deps": [ - { - "lib": "com.github.msyds/spec-dict", - "url": "https://github.com/msyds/spec-dict.git", - "rev": "531d629b7f05f37232261cf9e8927a4b5915714f", - "git-dir": "https/github.com/msyds/spec-dict", - "hash": "sha256-5hMdPsB8OhOCtByPZS+CHXzVLq0H+OBKKnXec21xwmg=" - } - ], - "mvn-deps": [ - { - "mvn-path": "babashka/fs/0.5.24/fs-0.5.24.jar", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-owunNIWFqt6xNGhNV6vFs7GyYEz8z8wHRT7TSw1MDlU=" - }, - { - "mvn-path": "babashka/fs/0.5.24/fs-0.5.24.pom", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-E1jX6M3DeoTXVU6Vzd6xIpE0s9QAZpZALJl4nSKU8E8=" - }, - { - "mvn-path": "babashka/process/0.5.22/process-0.5.22.jar", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-22BH7RRkuVkJ2+/dHOD2dZ/bVroQS2ySO/dhFGToz0Y=" - }, - { - "mvn-path": "babashka/process/0.5.22/process-0.5.22.pom", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-Ijax5VAq9/FFnKomP+huFSOKh/HWGiwXLAZty/1iwo8=" - }, - { - "mvn-path": "cider/cider-nrepl/0.50.2/cider-nrepl-0.50.2.jar", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-tbnqZSyOG3J9fd1m4dapUi+nHjtaQJeLV4a/VC5YJPs=" - }, - { - "mvn-path": "cider/cider-nrepl/0.50.2/cider-nrepl-0.50.2.pom", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-pcCaxUODbWDLN1avACS4514owHqNuz4GSCm6trWVADs=" - }, - { - "mvn-path": "cider/orchard/0.27.2/orchard-0.27.2.jar", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-Jsgqu5d32ltq8zEWWEA/HJ4fTRedJBxVvbVwHcuNe+E=" - }, - { - "mvn-path": "cider/orchard/0.27.2/orchard-0.27.2.pom", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-eUGmk2TB2JzLpi2p+Ge//udJO7t/o339YCaPNt7KFek=" - }, - { - "mvn-path": "com/kohlschutter/junixsocket/junixsocket-common/2.3.2/junixsocket-common-2.3.2.jar", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-K1Aa5+IwuNvK4JkaELmbsit1LFg5GdbbjgF95TQV2w4=" - }, - { - "mvn-path": "com/kohlschutter/junixsocket/junixsocket-common/2.3.2/junixsocket-common-2.3.2.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-Bvm4o69XPu7DDfQ9xrHeXkvTAiygcwUTYs2lgSyoHhU=" - }, - { - "mvn-path": "com/kohlschutter/junixsocket/junixsocket-core/2.3.2/junixsocket-core-2.3.2.jar", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-U15ynrA6Q46/P5zRe/Vihhc792jLS+q5vrofzp/qn1g=" - }, - { - "mvn-path": "com/kohlschutter/junixsocket/junixsocket-core/2.3.2/junixsocket-core-2.3.2.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-UvBbBfXmZXQ20UAxB5W634Tcu66Qb3d3I7a7HjI4Kyk=" - }, - { - "mvn-path": "com/kohlschutter/junixsocket/junixsocket-native-common/2.3.2/junixsocket-native-common-2.3.2.jar", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-agkGlwca4wopwmP/1ZmXeN1WB3mXTuFblYagqj3D4NI=" - }, - { - "mvn-path": "com/kohlschutter/junixsocket/junixsocket-native-common/2.3.2/junixsocket-native-common-2.3.2.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-ZqkTeOuVJC/tuRGq861erwgJgHOnIHMwEG8u6MKGGFU=" - }, - { - "mvn-path": "com/kohlschutter/junixsocket/junixsocket-parent/2.3.2/junixsocket-parent-2.3.2.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-6xUM+wEcom7xA0WvsvdIRUs0TPWpgSVQtQwAx3S5mV8=" - }, - { - "mvn-path": "com/kohlschutter/kohlschutter-parent/1.3.4/kohlschutter-parent-1.3.4.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-XWmHS4avdhplwQQFZVB9hUvXl4KylP7h/kZWNmbja5w=" - }, - { - "mvn-path": "mx/cider/logjam/0.3.0/logjam-0.3.0.jar", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-h1moSv+GjTrjwDEil7l6psf7j5NUK39llkv5kT9K4J8=" - }, - { - "mvn-path": "mx/cider/logjam/0.3.0/logjam-0.3.0.pom", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-k9fFPsmXKX/14Z92LgY8cFtCu8jmbBE/DCbyRWK1D6Q=" - }, - { - "mvn-path": "nrepl/nrepl/1.1.1/nrepl-1.1.1.jar", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-P2jHLbYCXN4hKfwc7o5aL9/jYCTo6NAfo04tc3SL2gk=" - }, - { - "mvn-path": "nrepl/nrepl/1.1.1/nrepl-1.1.1.pom", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-KayXZRYA/ZpRur3UBfhjhi29S9Zt2sfQ5+vRQGznYwQ=" - }, - { - "mvn-path": "nrepl/nrepl/1.3.0/nrepl-1.3.0.jar", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-rI3mLHDxjE6EArE1im3tNXWLK8zY41mHsLQD8wL1EpI=" - }, - { - "mvn-path": "nrepl/nrepl/1.3.0/nrepl-1.3.0.pom", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-hj5NbrjvF299mnoVr3JqT2zZkBV5/Dw78ukg40Z+D1Q=" - }, - { - "mvn-path": "org/babashka/cli/0.8.62/cli-0.8.62.jar", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-/Y+i9wLRyvXCgB1D/qnZyZ05p0/jFwe6FYiDyIWlm7E=" - }, - { - "mvn-path": "org/babashka/cli/0.8.62/cli-0.8.62.pom", - "mvn-repo": "https://repo.clojars.org/", - "hash": "sha256-O3xHZ+YB2KirU9VMGeECp7XEoomB8WI3Qh9YpoeqMxc=" - }, - { - "mvn-path": "org/clojure/clojure/1.10.3/clojure-1.10.3.jar", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-fxJHLa7Y9rUXSYqqKrE6ViR1w+31FHjkWBzHYemJeaM=" - }, - { - "mvn-path": "org/clojure/clojure/1.10.3/clojure-1.10.3.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-GJwAxDNAdJai+7DsyzeQjJSVXZHq0b5IFWdE7MGBbZQ=" - }, - { - "mvn-path": "org/clojure/clojure/1.11.0/clojure-1.11.0.jar", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-PiH6daB+yd278bK1A1bPGAcQ0DmN6qT0TpHNYwRVWUc=" - }, - { - "mvn-path": "org/clojure/clojure/1.11.0/clojure-1.11.0.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-SQjMS0yeYsmoFJb5PLWsb2lBd8xkXc87jOXkkavOHro=" - }, - { - "mvn-path": "org/clojure/clojure/1.11.1/clojure-1.11.1.jar", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-I4G26UI6tGUVFFWUSQPROlYkPWAGuRlK/Bv0+HEMtN4=" - }, - { - "mvn-path": "org/clojure/clojure/1.11.1/clojure-1.11.1.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-IMRaGr7b2L4grvk2BQrjGgjBZ0CzL4dAuIOM3pb/y4o=" - }, - { - "mvn-path": "org/clojure/clojure/1.11.2/clojure-1.11.2.jar", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-iPqZkT1pIs+39kn1xGdQOHfLb8yMwW02948mSAhLqZc=" - }, - { - "mvn-path": "org/clojure/clojure/1.11.2/clojure-1.11.2.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-FzbP/xCV4dT+/raogrut9ttB7+MV8pbw/aMtt//EExE=" - }, - { - "mvn-path": "org/clojure/clojure/1.11.3/clojure-1.11.3.jar", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-nDBUCTKOK5boXdK160t1gQxnt2unCuTQ9t3pvPtVsbc=" - }, - { - "mvn-path": "org/clojure/clojure/1.11.3/clojure-1.11.3.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-DA2+Ge4NKpxXMQzr3dNWRD8NFlFMQmBHsGLjpXwNuK0=" - }, - { - "mvn-path": "org/clojure/clojure/1.11.4/clojure-1.11.4.jar", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-/H/xtmENDjSUp1zBHvgYEL2kAqwVcBL+TjuJlYbPQTM=" - }, - { - "mvn-path": "org/clojure/clojure/1.11.4/clojure-1.11.4.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-a6YADmhI+Cw5y5tJqyqmo6Vi9MJNUrMeUZCuZJXwwwk=" - }, - { - "mvn-path": "org/clojure/clojure/1.12.0/clojure-1.12.0.jar", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-xFMzAGRBoFnqn9sTQfxsH0C5IaENzNgmZTEeSKA4R2M=" - }, - { - "mvn-path": "org/clojure/clojure/1.12.0/clojure-1.12.0.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-KfRiqonLl2RXWEGKXwjUwagrc1yW569JgX0WqpuQgVA=" - }, - { - "mvn-path": "org/clojure/core.match/1.1.0/core.match-1.1.0.jar", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-10V6tjEIWae9cTmEM4IEX6PN7A0T97qSEpfy8/uZj1M=" - }, - { - "mvn-path": "org/clojure/core.match/1.1.0/core.match-1.1.0.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-NnHYN2UlIwq6Ah8fYmx54g86ELYrXfgXIiWJDsSv4EU=" - }, - { - "mvn-path": "org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-/PRCveArBKhj8vzFjuaiowxM8Mlw99q4VjTwq3ERZrY=" - }, - { - "mvn-path": "org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-AarxdIP/HHSCySoHKV1+e8bjszIt9EsptXONAg/wB0A=" - }, - { - "mvn-path": "org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-Bu6owHC75FwVhWfkQ0OWgbyMRukSNBT4G/oyukLWy8g=" - }, - { - "mvn-path": "org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-F3i70Ti9GFkLgFS+nZGdG+toCfhbduXGKFtn1Ad9MA4=" - }, - { - "mvn-path": "org/clojure/core.specs.alpha/0.4.74/core.specs.alpha-0.4.74.jar", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-63OsCM9JuoQMiLpnvu8RM2ylVDM9lAiAjXiUbg/rnds=" - }, - { - "mvn-path": "org/clojure/core.specs.alpha/0.4.74/core.specs.alpha-0.4.74.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-M0EOuKpz1S2Vez3G4KZfOZisBiPL2BPZDDPm5onEJCk=" - }, - { - "mvn-path": "org/clojure/pom.contrib/0.3.0/pom.contrib-0.3.0.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-fxgrOypUPgV0YL+T/8XpzvasUn3xoTdqfZki6+ee8Rk=" - }, - { - "mvn-path": "org/clojure/pom.contrib/1.1.0/pom.contrib-1.1.0.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-EOzku1+YKQENwWVh9C67g7ry9HYFtR+RBbkvPKoIlxU=" - }, - { - "mvn-path": "org/clojure/pom.contrib/1.2.0/pom.contrib-1.2.0.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-CRbXpBVYuVAKQnyIb6KYJ6zlJZIGvjrTPmTilvwaYRE=" - }, - { - "mvn-path": "org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-z2iZ+YUpjGSxPqEplGrZAo3uja3w6rmuGORVAn04JJw=" - }, - { - "mvn-path": "org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-WhHw4eizwFLmUcSYxpRbRNs1Nb8sGHGf3PZd8fiLE+Y=" - }, - { - "mvn-path": "org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-Z+yJjrVcZqlXpVJ53YXRN2u5lL2HZosrDeHrO5foquA=" - }, - { - "mvn-path": "org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-bY3hTDrIdXYMX/kJVi/5hzB3AxxquTnxyxOeFp/pB1g=" - }, - { - "mvn-path": "org/clojure/spec.alpha/0.5.238/spec.alpha-0.5.238.jar", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-lM2ZtupjlkHzevSGCmQ7btOZ7lqL5dcXz/C2Y8jXUHc=" - }, - { - "mvn-path": "org/clojure/spec.alpha/0.5.238/spec.alpha-0.5.238.pom", - "mvn-repo": "https://repo1.maven.org/maven2/", - "hash": "sha256-PLp+DcwIXEzpLd3/6iJhJP+sF4vnm9A3m1suMKlpy+o=" - } - ] -} diff --git a/scripts/sydnix-cli/deps.edn b/scripts/sydnix-cli/deps.edn deleted file mode 100644 index be03806..0000000 --- a/scripts/sydnix-cli/deps.edn +++ /dev/null @@ -1,21 +0,0 @@ -{:deps {org.babashka/cli {:mvn/version "0.8.62"} - babashka/process {:mvn/version "0.5.22"} - babashka/fs {:mvn/version "0.5.24"} - org.clojure/clojure {:mvn/version "1.12.0"} - org.clojure/core.match {:mvn/version "1.1.0"} - com.github.msyds/spec-dict - {:git/sha "531d629b7f05f37232261cf9e8927a4b5915714f"}} - :paths ["src"] - :aliases - {:cider - {:extra-deps {cider/cider-nrepl {:mvn/version "0.50.2"}} - :main-opts ["-m" "nrepl.cmdline" - "--middleware" "[cider.nrepl/cider-middleware]"]} - :nrepl - {:extra-deps - {nrepl/nrepl {:mvn/version "1.3.0"} - com.kohlschutter.junixsocket/junixsocket-core {:mvn/version "2.3.2"}} - :main-opts ["-m" "nrepl.cmdline" - "--socket" ".nrepl/socket"]} - :run - {:main-opts ["-m" "sydnix-cli.main"]}}} diff --git a/scripts/sydnix-cli/flake.lock b/scripts/sydnix-cli/flake.lock deleted file mode 100644 index 02101cd..0000000 --- a/scripts/sydnix-cli/flake.lock +++ /dev/null @@ -1,171 +0,0 @@ -{ - "nodes": { - "clj-nix": { - "inputs": { - "devshell": "devshell", - "nix-fetcher-data": "nix-fetcher-data", - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1732920288, - "narHash": "sha256-w04hFhbutbob60xy6wUYdawBCVK0qAzBfhGsD+bPypU=", - "owner": "jlesquembre", - "repo": "clj-nix", - "rev": "6e829214a303d2f921c7919f6fb7a2721069c608", - "type": "github" - }, - "original": { - "owner": "jlesquembre", - "repo": "clj-nix", - "type": "github" - } - }, - "devshell": { - "inputs": { - "nixpkgs": [ - "clj-nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1728330715, - "narHash": "sha256-xRJ2nPOXb//u1jaBnDP56M7v5ldavjbtR6lfGqSvcKg=", - "owner": "numtide", - "repo": "devshell", - "rev": "dd6b80932022cea34a019e2bb32f6fa9e494dfef", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib" - }, - "locked": { - "lastModified": 1719745305, - "narHash": "sha256-xwgjVUpqSviudEkpQnioeez1Uo2wzrsMaJKJClh+Bls=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "c3c5ecc05edc7dafba779c6c1a61cd08ac6583e9", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nix-fetcher-data": { - "inputs": { - "flake-parts": "flake-parts", - "nixpkgs": [ - "clj-nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1728229178, - "narHash": "sha256-p5Fx880uBYstIsbaDYN7sECJT11oHxZQKtHgMAVblWA=", - "owner": "jlesquembre", - "repo": "nix-fetcher-data", - "rev": "f3a73c34d28db49ef90fd7872a142bfe93120e55", - "type": "github" - }, - "original": { - "owner": "jlesquembre", - "repo": "nix-fetcher-data", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1728492678, - "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-lib": { - "locked": { - "lastModified": 1717284937, - "narHash": "sha256-lIbdfCsf8LMFloheeE6N31+BMIeixqyQWbSr2vk79EQ=", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" - }, - "original": { - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1737632463, - "narHash": "sha256-38J9QfeGSej341ouwzqf77WIHAScihAKCt8PQJ+NH28=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "0aa475546ed21629c4f5bbf90e38c846a99ec9e9", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "clj-nix": "clj-nix", - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs_2" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/scripts/sydnix-cli/flake.nix b/scripts/sydnix-cli/flake.nix deleted file mode 100644 index 0761c66..0000000 --- a/scripts/sydnix-cli/flake.nix +++ /dev/null @@ -1,67 +0,0 @@ -# Generate lock file: -# nix run github:jlesquembre/clj-nix#deps-lock - -{ - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; - clj-nix.url = "github:jlesquembre/clj-nix"; - }; - - outputs = { self, nixpkgs, flake-utils, clj-nix }: - flake-utils.lib.eachDefaultSystem (system: - let pkgs = import nixpkgs { - inherit system; - overlays = [ - # devshell.overlays.default - clj-nix.overlays.default - ]; - }; - - sydnix-cli-unwrapped = clj-nix.lib.mkCljApp { - pkgs = nixpkgs.legacyPackages.${system}; - modules = [ - { - name = "msyds/sydnix-cli"; - version = "1.0.0"; - main-ns = "sydnix-cli.main"; - projectSrc = ./.; - - nativeImage = { - # Disable for faster build times. - enable = true; - }; - } - ]; - }; - in { - packages.default = pkgs.symlinkJoin { - name = "sydnix-cli"; - version = "1.0.0"; - paths = [ sydnix-cli-unwrapped ]; - nativeBuildInputs = [ pkgs.makeWrapper ]; - postBuild = '' - # The name `sydnix-cli` seems to be automatically chosen by clj-nix. - # Not a fan! - mv $out/bin/sydnix-cli $out/bin/sydnix - wrapProgram $out/bin/sydnix \ - --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.asciidoctor ]} - ''; - }; - - devShells.default = pkgs.mkShell { - inputsFrom = [ - # FIXME: clj-nix causes some `fake-git` tool to come into scope, - # which shadows the actual git. - # self.packages.${system}.default - ]; - - packages = with pkgs; [ - clojure-lsp - clojure - babashka - asciidoctor - ]; - }; - }); -} diff --git a/scripts/sydnix-cli/package.nix b/scripts/sydnix-cli/package.nix new file mode 100644 index 0000000..cc99ef0 --- /dev/null +++ b/scripts/sydnix-cli/package.nix @@ -0,0 +1,20 @@ +{ stdenvNoCC +, babashka +}: + +stdenvNoCC.mkDerivation (final: { + pname = "sydnix-cli"; + version = "2.0.0"; + src = ./.; + buildInputs = [ + babashka + ]; + dontBuild = true; + installPhase = '' + runHook preInstall + mkdir -p $out/bin $out/var/sydnix + cp -r bb.edn src sydnix $out/var/sydnix + ln -s $out/var/sydnix/sydnix $out/bin/sydnix + runHook postInstall + ''; +}) diff --git a/scripts/sydnix-cli/shell.nix b/scripts/sydnix-cli/shell.nix new file mode 100644 index 0000000..3829935 --- /dev/null +++ b/scripts/sydnix-cli/shell.nix @@ -0,0 +1,7 @@ +{ pkgs ? import {} }: + +pkgs.mkShell { + packages = with pkgs; [ + babashka + ]; +} diff --git a/scripts/sydnix-cli/src/asciidoc/render.clj b/scripts/sydnix-cli/src/asciidoc/render.clj deleted file mode 100644 index a2a3f56..0000000 --- a/scripts/sydnix-cli/src/asciidoc/render.clj +++ /dev/null @@ -1,89 +0,0 @@ -(ns asciidoc.render - (:require - [clojure.pprint :refer [pprint]] - [asciidoc.types :as types] - [clojure.spec.alpha :as s] - [clojure.zip :as zip])) - -(defn- block-zip [root-block] - (zip/zipper #(s/conform ::block %) - :content - (fn [block children] (assoc block :content children)) - root-block)) - -(defn- escape-line [line] - ;; TODO - line) - -(declare render*) - -(defn- render-attributes [attributes] - (let [sorted-attributes (->> attributes - seq - (sort-by first))] - (doseq [[k v] sorted-attributes] - (printf ":%s: %s\n" (name k) v)))) - -(defn- render-document-header [depth {:keys [arguments] :as block}] - (println "=" (:title arguments)) - (when-let [author (:author arguments)] - (println author) - (when-let [version (:version arguments)] - (println version))) - (when-let [attributes (:a arguments)] - (render-attributes attributes)) - (println) - (run! #(render* (inc depth) %) (:content block))) - -(defn- render-p [block] - (apply println (:content block))) - -(defn- render-description [depth {{:keys [described]} :arguments :as block}] - (printf "%s::\n" described) - (run! #(render* (inc depth) %) (:content block))) - -(defn- render-section [depth {:keys [arguments] :as block}] - (print (apply str (repeat (inc depth) \=)) - (:title arguments) - "\n\n") - (run! #(render* (inc depth) %) (:content block)) - (println)) - -(defn- render* [depth block] - (case (:context block) - :document (do (assert (zero? depth) - "Document block should only occur as root node.") - (render-document-header depth block)) - :section (render-section depth block) - :p (render-p block) - :description (render-description depth block) - :<> (run! #(render* (inc depth) %) (apply concat (:content block))) - (throw (ex-info "no case" {:for (:context block) - :block block})))) - -(def my-manpage - [:document {:title "sydnix(1)" - :author "Madeleine Sydney Ślaga" - :a {:doctype "manpage" - :manmanual "SYDNIX" - :mansource "SYDNIX"}} - [:section {:title "Name"} - [:p "sydnix - Inspect and operate upon the system."]] - [:section {:title "Synopsis"} - [:p "*sydnix* [_COMMAND_]... [_OPTION_]... [_FILE_]..."]] - [:section {:title "Options"} - [:description {:described "*--flake=URI*"} - "UJri is a flake"]]]) - -(defn conform! [spec x] - (let [x' (s/conform spec x)] - (if (= x' :clojure.spec.alpha/invalid) - (throw (ex-info "invalid" (s/explain-data spec x))) - x'))) - -;; Currently unrelentingly recursive. We'll fix this if/when it bnecomes a -;; problem. Shame Clojure skimps out on general TCO. }:( -(defn render - "Render an AsciiDoc block to `*out*`." - [block] - (render* 0 (conform! :asciidoc.types/document block))) diff --git a/scripts/sydnix-cli/src/asciidoc/types.clj b/scripts/sydnix-cli/src/asciidoc/types.clj deleted file mode 100644 index 895a267..0000000 --- a/scripts/sydnix-cli/src/asciidoc/types.clj +++ /dev/null @@ -1,57 +0,0 @@ -(ns asciidoc.types - (:require - [clojure.spec.alpha :as s] - [spec-dict.main :refer [->opt dict]])) - -(defn- make-block-arguments [req opt] - (let [args (dict req - (->opt opt) - ^:opt {:a map?})] - (if (empty? req) - (s/? (s/and map? args)) - (s/& (s/? map?) args)))) - -(defn- make-block - [& {:keys [name required-args optional-args content-spec] - :or {required-args {} - optional-args {} - content-spec (s/* ::block)}}] - (s/and seqable? - (s/cat :context (s/and keyword? #{name}) - :arguments (make-block-arguments required-args optional-args) - :content content-spec) - ;; Set arguments to {} if none were provided. - (s/conformer #(if (contains? % :arguments) - % - (assoc % :arguments {}))))) - -(s/def ::document - (make-block :name :document - :required-args {:title string?} - :optional-args {:author string? - :version string?})) - -(s/def ::p - (make-block :name :p - :content-spec (s/* string?))) - -(s/def ::description - (make-block :name :description - :required-opts {:described string?})) - -(s/def ::section - (make-block :name :section - :required-args {:title string?})) - -(s/def ::<> - (make-block :name :<> - :content (s/coll-of ::block))) - -(s/def ::block - (s/and (s/or :document ::document - :section ::section - :description ::description - :<> ::<> - :p ::p) - ;; `s/or` provides tagging that `make-block` already does. - (s/conformer #(nth % 1)))) diff --git a/scripts/sydnix-cli/src/sydnix_cli/cli_table.clj b/scripts/sydnix-cli/src/sydnix_cli/cli_table.clj deleted file mode 100644 index 170a19a..0000000 --- a/scripts/sydnix-cli/src/sydnix_cli/cli_table.clj +++ /dev/null @@ -1,3 +0,0 @@ -(ns sydnix-cli.cli-table) - -(def *cli-table (atom nil)) diff --git a/scripts/sydnix-cli/src/sydnix_cli/commands/help.clj b/scripts/sydnix-cli/src/sydnix_cli/commands/help.clj index 6ff5286..9b662fa 100644 --- a/scripts/sydnix-cli/src/sydnix_cli/commands/help.clj +++ b/scripts/sydnix-cli/src/sydnix_cli/commands/help.clj @@ -1,42 +1,8 @@ (ns sydnix-cli.commands.help - (:require - [babashka.process :as p] - [sydnix-cli.mangen :as mangen])) + (:require [babashka.cli :as cli])) -(defn adorn-with-help-option [wrapped-command-fn] - (fn [{:keys [opts dispatch]}] - (if (:help opts) - (mangen/with-pipe - (fn [man->] - (mangen/write-man-for-command (mangen/find-dispatched dispatch) - :out man->)) - (fn [->man] - (p/shell {:in ->man} - "man -l -"))) - (wrapped-command-fn opts)))) - -(defn- view-man-for-command [command-spec] - (mangen/with-pipe - (fn [man->] - (mangen/write-man-for-command command-spec :out man->)) - (fn [->man] - (p/shell {:in ->man} "man -l -")))) - -(defn- wrap-command-fn [wrapped-fn] - (fn [info] - (if (:help (:opts info)) - (do (mangen/render-docs-for-command - (mangen/find-dispatched (:dispatch info))) - #_ - (view-man-for-command (mangen/find-dispatched (:dispatch info)))) - (when-not (nil? wrapped-fn) - (wrapped-fn info))))) - -(defn adorn-with-help-option* [command-spec] - (update command-spec :fn wrap-command-fn)) - -(defn- command-fn [_opts] - (view-man-for-command (mangen/find-dispatched []))) +(defn command-fn [{:keys [args opts]}] + (println "hallp")) (def command {:cmds ["help"] diff --git a/scripts/sydnix-cli/src/sydnix_cli/commands/rebuild.clj b/scripts/sydnix-cli/src/sydnix_cli/commands/rebuild.clj index a05c034..b1f7464 100644 --- a/scripts/sydnix-cli/src/sydnix_cli/commands/rebuild.clj +++ b/scripts/sydnix-cli/src/sydnix_cli/commands/rebuild.clj @@ -1,7 +1,5 @@ (ns sydnix-cli.commands.rebuild - (:require - [babashka.process :as p] - [sydnix-cli.commands.help :refer [adorn-with-help-option*]])) + (:require [babashka.process :as p])) (defn- parse-target [target] (when-some [[_ _ user host] (re-matches #"(([-a-zA-Z0-9_]+)@)?(.+)" @@ -23,15 +21,19 @@ :desc "Deploy config to HOST." :coerce parse-target}}) -(defn- command-fn [{:keys [args opts]}] +(defn- default-flake [host] + (str "path:///persist/dots" + (some->> host (str "#")))) + +(defn command-fn [{:keys [args opts]}] (let [rebuild-cmd (concat (when-not (:target opts) ["sudo"]) ["nixos-rebuild"] (or args ["switch"]) - ["--flake" (if-some [host (:host (:target opts))] - (format "/persist/dots#%s" host) - "/persist/dots")] + ["--flake" (or (:flake opts) + (-> opts :target :host + default-flake))] (when-some [target (:target opts)] ["--sudo" "--ask-sudo-password" "--target-host" (str-target target)]))] @@ -40,8 +42,8 @@ :exit System/exit))) -(def commands - [{:cmds ["rebuild"] - :desc "Rebuild the system NixOS and Home-manager configuration" - :fn command-fn - :spec command-options-spec}]) +(def command + {:cmds ["rebuild"] + :desc "Rebuild the system's NixOS configuration" + :fn command-fn + :spec command-options-spec}) diff --git a/scripts/sydnix-cli/src/sydnix_cli/commands/status.clj b/scripts/sydnix-cli/src/sydnix_cli/commands/status.clj deleted file mode 100644 index d96ac0a..0000000 --- a/scripts/sydnix-cli/src/sydnix_cli/commands/status.clj +++ /dev/null @@ -1,11 +0,0 @@ -(ns sydnix-cli.commands.status - (:require - [sydnix-cli.commands.help :refer [adorn-with-help-option*]])) - -(defn- command-fn [opts] - (prn opts)) - -(def commands - [{:cmds ["status"] - :desc "View system info" - :fn command-fn}]) diff --git a/scripts/sydnix-cli/src/sydnix_cli/commands/util.clj b/scripts/sydnix-cli/src/sydnix_cli/commands/util.clj deleted file mode 100644 index bff5eae..0000000 --- a/scripts/sydnix-cli/src/sydnix_cli/commands/util.clj +++ /dev/null @@ -1,8 +0,0 @@ -(ns sydnix-cli.commands.util - (:require - [sydnix-cli.commands.util.mangen :as cmd-util-mangen])) - -(def commands - [{:cmds ["util"] - :desc "Infrequently-used utilities such as docgen and shell completions."} - cmd-util-mangen/command]) diff --git a/scripts/sydnix-cli/src/sydnix_cli/commands/util/mangen.clj b/scripts/sydnix-cli/src/sydnix_cli/commands/util/mangen.clj deleted file mode 100644 index 8baadcf..0000000 --- a/scripts/sydnix-cli/src/sydnix_cli/commands/util/mangen.clj +++ /dev/null @@ -1,46 +0,0 @@ -(ns sydnix-cli.commands.util.mangen - (:require - [asciidoc.render] - [babashka.fs :as fs] - [babashka.process :as p] - [clojure.java.io :as io] - [clojure.spec.alpha :as s] - [clojure.string :as str] - [sydnix-cli.mangen :as mangen] - [sydnix-cli.cli-table :refer [*cli-table]] - [sydnix-cli.commands.help :refer [adorn-with-help-option*]] - [sydnix-cli.prelude :as prelude])) - -(defn command-fn [{:keys [yes output-directory]}] - (if (or yes - (prelude/y-or-n? (format "Write a bunch of man pages to %s?" - output-directory))) - (doseq [cmd-spec (deref *cli-table)] - (let [man-file-name (fs/file - output-directory - (str (str/join "-" (cons "sydnix" (:cmds cmd-spec))) - ".1"))] - (with-open [man-file (io/writer man-file-name)] - (mangen/write-man-for-command cmd-spec :out man-file)) - (printf "wrote %s\n" man-file-name) - (flush))) - (System/exit 1))) - -(def command-options-spec - {:output-directory {:coerce :string - :ref "DIRECTORY" - :alias :o - :desc "Directory to which the generated man pages will be - written." - :require true - :validate fs/directory?} - :yes {:coerce :bool - :desc "Don't ask for confirmation." - :default false}}) - -(def command - (adorn-with-help-option* - {:cmds ["util" "mangen"] - :desc "Generate man pages for each subcommand of `sydnix`." - :fn command-fn - :spec command-options-spec})) diff --git a/scripts/sydnix-cli/src/sydnix_cli/main.clj b/scripts/sydnix-cli/src/sydnix_cli/main.clj index b0e6f7a..4c7acc8 100644 --- a/scripts/sydnix-cli/src/sydnix_cli/main.clj +++ b/scripts/sydnix-cli/src/sydnix_cli/main.clj @@ -1,25 +1,33 @@ (ns sydnix-cli.main - (:require - [babashka.cli :as cli] - [sydnix-cli.cli-table :refer [*cli-table]] - [sydnix-cli.commands.help :as cmd-help :refer [adorn-with-help-option*]] - [sydnix-cli.commands.rebuild :as cmd-rebuild] - [sydnix-cli.commands.status :as cmd-status] - [sydnix-cli.commands.util :as cmd-util]) - (:gen-class)) + (:require [babashka.cli :as cli] + [sydnix-cli.commands.rebuild :as rebuild] + [sydnix-cli.commands.help :as help] + [clojure.pprint :refer [pprint]])) -(def real-cli-table - (map adorn-with-help-option* - (concat cmd-status/commands - cmd-rebuild/commands - cmd-util/commands - [cmd-help/command - ;; Show help when no other command matches. - (assoc cmd-help/command :cmds [])]))) +(defn help [opts] + (println "Hellllpp")) + +(def cli-table + [rebuild/command + help/command + ;; Assume help command when no subcommand is given. + (assoc help/command :cmds [])]) + +(defmacro stderr [& body] + `(binding [*out* *err*] + ~@body)) + +(defn error-fn [{:keys [spec type cause msg option] :as data}] + (if (= :org.babashka/cli type) + (stderr (printf "Error: %s\n" msg)) + (stderr + (println "a mysterious error has occured...") + (pprint data)))) (defn -main [& args] - (reset! *cli-table real-cli-table) - (cli/dispatch @*cli-table args) - ;; Process may hang without this form. D:{ - ;; https://github.com/babashka/process?tab=readme-ov-file#script-termination + (cli/dispatch cli-table args + {:restrict true + :error-fn #(do (error-fn %) + (stderr (flush)) + (System/exit 1))}) (shutdown-agents)) diff --git a/scripts/sydnix-cli/src/sydnix_cli/mangen.clj b/scripts/sydnix-cli/src/sydnix_cli/mangen.clj deleted file mode 100644 index bfe3d1e..0000000 --- a/scripts/sydnix-cli/src/sydnix_cli/mangen.clj +++ /dev/null @@ -1,94 +0,0 @@ -(ns sydnix-cli.mangen - (:require - [asciidoc.render] - [asciidoc.types] - [babashka.fs :as fs] - [babashka.process :as p] - [clojure.spec.alpha :as s] - [clojure.string :as str] - [sydnix-cli.cli-table :refer [*cli-table]]) - (:import - [java.io BufferedReader PipedReader PipedWriter])) - -(defn- format-p [s] - (-> s - (str/replace #"^ +" " ") - (str/replace #"\n +" "\n"))) - -(defn- docs-for-command [command-spec] - (let [command (cons "sydnix" (:cmds command-spec))] - [:document {:title (str (str/join "-" command) - "(1)") - :author "Madeleine Sydney Ślaga" - :a {:doctype "manpage" - :manmanual "SYDNIX" - :mansource "SYDNIX"}} - [:section {:title "Name"} - [:p (format "%s - %s" - (str/join " " command) - (:desc command-spec))]] - [:section {:title "Synopsis"} - [:p (format "%s [_option_…]" - (str/join " " command))]] - (concat [:section {:title "Options"}] - (for [[opt opt-spec] (:spec command-spec)] - [:description {:described (format "*--%s%s*" - (name opt) - (if-let [ref (:ref opt-spec)] - (str "=" ref) - ""))} - [:p (format-p (:desc opt-spec))]]))])) - -(defn render-docs-for-command [command-spec] - (try (asciidoc.render/render (docs-for-command command-spec)) - (catch Exception e - (prn e) - (s/explain :asciidoc.types/document command-spec) - (throw e)))) - -(defn- find-satisfying [p xs] - (->> xs (filter p) first)) - -(defn find-dispatched [dispatch] - (find-satisfying #(= dispatch (:cmds %)) (deref *cli-table))) - -(defn- find-adoc-processor - "Looks for a suitable AsciiDoc processor. In order of precedence, it will try - `$ADOC_PROCESSOR`, then `asciidoctor`." - [& {:keys [throw?]}] - (letfn [(suitable [x] - (when (and x (fs/executable? x)) - x))] - (or (suitable (System/getenv "ADOC_PROCESSOR")) - (suitable (fs/which "asciidoctor")) - (when throw? - (throw (ex-info "Can't find a suitable AsciiDoc processor" {})))))) - -(defn asciidoctor - "Shell out to AsciiDoctor (`$ADOC_PROCESSOR`, actually) to create ROFF markup - for man pages." - [& {:keys [asciidoctor-bin in out err] - :or {asciidoctor-bin (find-adoc-processor :throw? true) - in *in* - out *out* - err *err*}}] - (p/shell {:in in :out out :err err} - asciidoctor-bin "-o" "-" "-b" "manpage" "-")) - -(defn with-pipe [with-out with-in] - (let [out (PipedWriter.) - in (PipedReader. out)] - (future (with-out out) - (.close out)) - (with-in (BufferedReader. in)))) - -(defn write-man-for-command - [command-spec & {:keys [out err] - :or {out *out* - err *err*}}] - (with-pipe - (fn [adoc->] - (binding [*out* adoc->] - (render-docs-for-command command-spec))) - (fn [->adoc] - (asciidoctor :in ->adoc :out out :err err)))) diff --git a/scripts/sydnix-cli/src/sydnix_cli/prelude.clj b/scripts/sydnix-cli/src/sydnix_cli/prelude.clj deleted file mode 100644 index c892de4..0000000 --- a/scripts/sydnix-cli/src/sydnix_cli/prelude.clj +++ /dev/null @@ -1,21 +0,0 @@ -(ns sydnix-cli.prelude - (:require - [clojure.core.match :refer [match]])) - -(defn y-or-n? - [prompt - & {:keys [default] - :or {default :n} - :as opts}] - (let [y-n-indicator (case default - :y " [Y/n] " - :n " [y/N] ")] - (print (str prompt y-n-indicator)) - (flush)) - (let [line (read-line)] - (match line - "" (case default :y true :n false) - (:or "y" "Y") true - (:or "n" "N") false - _ (do (println "Please enter y or n.") - (recur prompt opts))))) diff --git a/scripts/sydnix-cli/sydnix b/scripts/sydnix-cli/sydnix new file mode 100755 index 0000000..34e148b --- /dev/null +++ b/scripts/sydnix-cli/sydnix @@ -0,0 +1,6 @@ +#!/usr/bin/env bb +;; -*- mode: clojure -*- + +(require '[sydnix-cli.main]) + +(apply sydnix-cli.main/-main *command-line-args*)