Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
;; My IP address data is shaped like this:
(def data {"host-a" {:ip ""}
"host-b" {:ip ""}
"container" {"host-c" {:ip ""}
"host-d" {:ip ""}}})
;; This logic turns that data into a map ("set" in nix) that would work for `networking.hosts`:
(defn build-hosts [ip-data & [name-prefix]]
(reduce-kv (fn [result hostname {:keys [ip] :as info}]
(let [full-hostname (if name-prefix
(str name-prefix "-" hostname)
(if ip
(assoc result ip [full-hostname])
(merge result (build-hosts info hostname)))))
(build-hosts data)
=> {"" ["host-a"],
"" ["host-b"],
"" ["container-host-c"],
"" ["container-host-d"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.