From 06bfe006884c9c58bce202030508507e4fc2da83 Mon Sep 17 00:00:00 2001 From: Madeleine Sydney Date: Tue, 7 Jan 2025 06:19:00 -0700 Subject: [PATCH] feat: sydnix script --- scripts/sydnix/.envrc | 9 + scripts/sydnix/.gitignore | 10 + scripts/sydnix/.projectile | 0 scripts/sydnix/deps-lock.json | 271 ++++++++++++++++++ scripts/sydnix/deps.edn | 18 ++ scripts/sydnix/flake.lock | 171 +++++++++++ scripts/sydnix/flake.nix | 41 +++ scripts/sydnix/src/sydnix/cli_table.clj | 3 + scripts/sydnix/src/sydnix/commands/help.clj | 129 +++++++++ .../sydnix/src/sydnix/commands/rebuild.clj | 11 + scripts/sydnix/src/sydnix/commands/status.clj | 4 + scripts/sydnix/src/sydnix/main.clj | 34 +++ 12 files changed, 701 insertions(+) create mode 100644 scripts/sydnix/.envrc create mode 100644 scripts/sydnix/.gitignore create mode 100644 scripts/sydnix/.projectile create mode 100644 scripts/sydnix/deps-lock.json create mode 100644 scripts/sydnix/deps.edn create mode 100644 scripts/sydnix/flake.lock create mode 100644 scripts/sydnix/flake.nix create mode 100644 scripts/sydnix/src/sydnix/cli_table.clj create mode 100644 scripts/sydnix/src/sydnix/commands/help.clj create mode 100644 scripts/sydnix/src/sydnix/commands/rebuild.clj create mode 100644 scripts/sydnix/src/sydnix/commands/status.clj create mode 100755 scripts/sydnix/src/sydnix/main.clj diff --git a/scripts/sydnix/.envrc b/scripts/sydnix/.envrc new file mode 100644 index 0000000..82b2b9e --- /dev/null +++ b/scripts/sydnix/.envrc @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# the shebang is ignored, but nice for editors + +if type -P lorri &>/dev/null; then + eval "$(lorri direnv)" +else + echo 'while direnv evaluated .envrc, could not find the command "lorri" [https://github.com/nix-community/lorri]' + use nix +fi diff --git a/scripts/sydnix/.gitignore b/scripts/sydnix/.gitignore new file mode 100644 index 0000000..1fcb19e --- /dev/null +++ b/scripts/sydnix/.gitignore @@ -0,0 +1,10 @@ +result +.nrepl +.nrepl-port +.cpcache/ +.cache/ +.lsp/ +.clj-kondo +.cpcache +.lsp +.nrepl diff --git a/scripts/sydnix/.projectile b/scripts/sydnix/.projectile new file mode 100644 index 0000000..e69de29 diff --git a/scripts/sydnix/deps-lock.json b/scripts/sydnix/deps-lock.json new file mode 100644 index 0000000..39656b7 --- /dev/null +++ b/scripts/sydnix/deps-lock.json @@ -0,0 +1,271 @@ +{ + "lock-version": 4, + "git-deps": [], + "mvn-deps": [ + { + "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=" + }, + { + "mvn-path": "spec-dict/spec-dict/0.2.1/spec-dict-0.2.1.jar", + "mvn-repo": "https://repo.clojars.org/", + "hash": "sha256-a9AvVMvRL/4FoSLQLDjQBMutDIpwWEc7V5wrnjqAp34=" + }, + { + "mvn-path": "spec-dict/spec-dict/0.2.1/spec-dict-0.2.1.pom", + "mvn-repo": "https://repo.clojars.org/", + "hash": "sha256-pTMOUp6WJneXHxP97KYVULX+Yqn04DJR2uvkXlxxRUQ=" + } + ] +} diff --git a/scripts/sydnix/deps.edn b/scripts/sydnix/deps.edn new file mode 100644 index 0000000..4d9b15a --- /dev/null +++ b/scripts/sydnix/deps.edn @@ -0,0 +1,18 @@ +{:deps {org.babashka/cli {:mvn/version "0.8.62"} + org.clojure/clojure {:mvn/version "1.12.0"} + org.clojure/core.match {:mvn/version "1.1.0"} + spec-dict/spec-dict {:mvn/version "0.2.1"}} + :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.main"]}}} diff --git a/scripts/sydnix/flake.lock b/scripts/sydnix/flake.lock new file mode 100644 index 0000000..2c0a09f --- /dev/null +++ b/scripts/sydnix/flake.lock @@ -0,0 +1,171 @@ +{ + "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": 1736012469, + "narHash": "sha256-/qlNWm/IEVVH7GfgAIyP6EsVZI6zjAx1cV5zNyrs+rI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8f3e1f807051e32d8c95cd12b9b421623850a34d", + "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/flake.nix b/scripts/sydnix/flake.nix new file mode 100644 index 0000000..80bb78c --- /dev/null +++ b/scripts/sydnix/flake.nix @@ -0,0 +1,41 @@ +{ + 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 + ]; + }; + in { + packages.default = pkgs.mkCljBin { + name = "msyds/sydnix"; + main-ns = "sydnix.main"; + projectSrc = ./.; + + # nativeImage.enable = true; + # customJdk.enable = true; + }; + + 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 = [ + pkgs.clojure-lsp + pkgs.clojure + pkgs.babashka + ]; + }; + }); +} diff --git a/scripts/sydnix/src/sydnix/cli_table.clj b/scripts/sydnix/src/sydnix/cli_table.clj new file mode 100644 index 0000000..e4bac5b --- /dev/null +++ b/scripts/sydnix/src/sydnix/cli_table.clj @@ -0,0 +1,3 @@ +(ns sydnix.cli-table) + +(def ^:dynamic *cli-table*) diff --git a/scripts/sydnix/src/sydnix/commands/help.clj b/scripts/sydnix/src/sydnix/commands/help.clj new file mode 100644 index 0000000..21145d4 --- /dev/null +++ b/scripts/sydnix/src/sydnix/commands/help.clj @@ -0,0 +1,129 @@ +(ns sydnix.commands.help + (:require + [clojure.pprint :refer [pprint]] + [clojure.spec.alpha :as s] + [clojure.zip :as zip] + [spec-dict :refer [dict dict*]])) + +(s/def ::block-context + #{:document :section :paragraph}) + +(s/def :block/arguments + (s/and map? + (dict ^:opt {:a map?}))) + +(s/def ::block + (s/and vector? + (s/and (s/cat :context keyword? + :arguments (s/? :block/arguments) + :content (s/* (constantly true))) + ;; Set default fields. + (s/conformer #(if (contains? % :arguments) + % + (assoc % :arguments {})))))) + +(s/def :document/doctype #{:manpage}) +(s/def :document/manmanual string?) +(s/def :document/mansource string?) +(s/def :document/man-linkstyle string?) + +(s/def :block/attributes map?) + +#_ +(s/def :document/attributes + (s/keys :opt-un [:document/doctype + :document/manmanual + :document/mansource + :document/man-linkstyle])) + +(s/def :document/arguments + (s/and :block/arguments + (dict {:title string?} + ^:opt {:author string?} + ^:opt {:version string?}))) + +(s/def :document/content (s/coll-of ::block)) + +(s/def ::document + (s/and ::block + (dict {:context #{:document} + :content (s/coll-of ::block)}))) + +(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) + +(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 [{:keys [arguments]}] + (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))) + +(defn- render-section [depth {:keys [arguments] :as block}] + (println (apply str (repeat (inc depth) \=)) + (:title arguments)) + (apply println (:content block))) + +(defn- render* [depth block-zipper] + #_ + (pprint block-zipper) + (let [block (zip/node block-zipper)] + (case (:context block) + :document (do (assert (zero? depth) + "Document block should only occur as root node.") + (render-document-header block) + (println) + (when-let [x (zip/left block-zipper)] + (render* (inc depth) x)) + (when-let [x (zip/down block-zipper)] + (recur (inc depth) x))) + :section (do (render-section depth block) + (println) + (when-let [l (zip/left block-zipper)] + (recur (inc depth) l))) + (throw (ex-info "no case" {:for (:context block) + :block block}))))) + +(defn- render + "Render an AsciiDoc block to `*out*`." + [block] + (render* 0 (block-zip (s/conform ::document block)))) + +(def my-manpage + [:document {:title "sydnix(1)" + :author "Madeleine Sydney Ĺšlaga" + :a {:doctype "manpage" + :manmanual "SYDNIX" + :mansource "SYDNIX"}} + [:section {:title "Name"} + "sydnix - Inspect and operate upon the system."] + [:section {:title "Synopsis"} + "*sydnix* [_COMMAND_]... [_OPTION_]... [_FILE_]..."]]) + + + +(defn docs-for-command [command]) + +(defn command [opts] + (prn "help" opts)) + +(defn adorn-with-help-option [command-fn] + (fn [opts] + (prn "adorned help" opts) + (command-fn opts))) diff --git a/scripts/sydnix/src/sydnix/commands/rebuild.clj b/scripts/sydnix/src/sydnix/commands/rebuild.clj new file mode 100644 index 0000000..dc8c22c --- /dev/null +++ b/scripts/sydnix/src/sydnix/commands/rebuild.clj @@ -0,0 +1,11 @@ +(ns sydnix.commands.rebuild + (:require + [clojure.java.shell :refer [sh]])) + +(defn command [{:keys [args opts]}] + (let [command + (concat ["sudo" "nixos-rebuild"] + (or args ["switch"]) + ["--flake" (:flake opts)])] + (apply println "$" command) + (apply sh command))) diff --git a/scripts/sydnix/src/sydnix/commands/status.clj b/scripts/sydnix/src/sydnix/commands/status.clj new file mode 100644 index 0000000..a2fe42c --- /dev/null +++ b/scripts/sydnix/src/sydnix/commands/status.clj @@ -0,0 +1,4 @@ +(ns sydnix.commands.status) + +(defn command [opts] + (prn opts)) diff --git a/scripts/sydnix/src/sydnix/main.clj b/scripts/sydnix/src/sydnix/main.clj new file mode 100755 index 0000000..f509f66 --- /dev/null +++ b/scripts/sydnix/src/sydnix/main.clj @@ -0,0 +1,34 @@ +(ns sydnix.main + (:require + [babashka.cli :as cli] + [sydnix.cli-table :refer [*cli-table*]] + [sydnix.commands.help :as cmd-help] + [sydnix.commands.status :as cmd-status] + [sydnix.commands.rebuild :as cmd-rebuild]) + (:gen-class)) + +(def cmd-status-spec + {}) + +(def with-help cmd-help/adorn-with-help-option) + +(def cmd-rebuild-spec + {:flake {:coerce :string + :default "path:///persist/dots"}}) + +(def cli-table + [{:cmds ["status"] + :desc "View system info" + :fn (with-help cmd-status/command)} + {:cmds ["rebuild"] + :desc "Rebuild the system NixOS and Home-manager configuration" + :fn (with-help cmd-rebuild/command) + :spec cmd-rebuild-spec} + {:cmds ["help"] + :fn cmd-help/command} + {:cmds [] + :fn cmd-help/command}]) + +(defn -main [& args] + (binding [*cli-table* cli-table] + (cli/dispatch cli-table args)))