diff --git a/flake.lock b/flake.lock index 1de93e7..e55ce62 100644 --- a/flake.lock +++ b/flake.lock @@ -945,8 +945,8 @@ "nixpkgs": "nixpkgs_11" }, "locked": { - "lastModified": 1742862380, - "narHash": "sha256-h19Bg+BTV/51MiCnKa3rN3QbRC74cBWjBHhDrpVgdXM=", + "lastModified": 1758284075, + "narHash": "sha256-QSNNBTOPyfS5bapOtqGi6boyusQfnlENh0Lv14QkT/A=", "path": "/persist/dots/scripts/sydnix-cli", "type": "path" }, diff --git a/scripts/sydnix-cli/.envrc b/scripts/sydnix-cli/.envrc index 82b2b9e..3550a30 100644 --- a/scripts/sydnix-cli/.envrc +++ b/scripts/sydnix-cli/.envrc @@ -1,9 +1 @@ -#!/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 +use flake diff --git a/scripts/sydnix-cli/.projectile b/scripts/sydnix-cli/.projectile deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/sydnix-cli/src/sydnix_cli/commands/deps-lock.json b/scripts/sydnix-cli/src/sydnix_cli/commands/deps-lock.json deleted file mode 100644 index b25327a..0000000 --- a/scripts/sydnix-cli/src/sydnix_cli/commands/deps-lock.json +++ /dev/null @@ -1,151 +0,0 @@ -{ - "lock-version": 4, - "git-deps": [], - "mvn-deps": [ - { - "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://repo.maven.apache.org/maven2/", - "hash": "sha256-xFMzAGRBoFnqn9sTQfxsH0C5IaENzNgmZTEeSKA4R2M=" - }, - { - "mvn-path": "org/clojure/clojure/1.12.0/clojure-1.12.0.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-KfRiqonLl2RXWEGKXwjUwagrc1yW569JgX0WqpuQgVA=" - }, - { - "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://repo.maven.apache.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://repo.maven.apache.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://repo.maven.apache.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://repo.maven.apache.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://repo.maven.apache.org/maven2/", - "hash": "sha256-lM2ZtupjlkHzevSGCmQ7btOZ7lqL5dcXz/C2Y8jXUHc=" - }, - { - "mvn-path": "org/clojure/spec.alpha/0.5.238/spec.alpha-0.5.238.pom", - "mvn-repo": "https://repo.maven.apache.org/maven2/", - "hash": "sha256-PLp+DcwIXEzpLd3/6iJhJP+sF4vnm9A3m1suMKlpy+o=" - } - ] -} diff --git a/scripts/sydnix-cli/src/sydnix_cli/commands/rebuild.clj b/scripts/sydnix-cli/src/sydnix_cli/commands/rebuild.clj index 721207f..a05c034 100644 --- a/scripts/sydnix-cli/src/sydnix_cli/commands/rebuild.clj +++ b/scripts/sydnix-cli/src/sydnix_cli/commands/rebuild.clj @@ -3,18 +3,38 @@ [babashka.process :as p] [sydnix-cli.commands.help :refer [adorn-with-help-option*]])) +(defn- parse-target [target] + (when-some [[_ _ user host] (re-matches #"(([-a-zA-Z0-9_]+)@)?(.+)" + target)] + {:user user :host host})) + +(defn- str-target [{:keys [user host]}] + (str (when user + (str user "@")) + host)) + (def command-options-spec {:flake {:coerce :string :ref "URI" :desc "URI is a path to a Flake, which is passed to `nixos-rebuild --flake URI` as is." - :default "path:///persist/dots"}}) + :default "path:///persist/dots"} + :target {:ref "[USER@]HOST" + :desc "Deploy config to HOST." + :coerce parse-target}}) (defn- command-fn [{:keys [args opts]}] (let [rebuild-cmd - (concat ["sudo" "nixos-rebuild"] + (concat (when-not (:target opts) + ["sudo"]) + ["nixos-rebuild"] (or args ["switch"]) - ["--flake" (:flake opts)])] + ["--flake" (if-some [host (:host (:target opts))] + (format "/persist/dots#%s" host) + "/persist/dots")] + (when-some [target (:target opts)] + ["--sudo" "--ask-sudo-password" + "--target-host" (str-target target)]))] (apply println "$" rebuild-cmd) (-> (apply p/shell {:continue true} rebuild-cmd) :exit