print module pathname if it contains services

so that the user knows what to add to their imports
This commit is contained in:
Daniel Barlow 2023-08-12 21:12:57 +01:00
parent d7785d9d75
commit bd908307c4

View file

@ -18,6 +18,13 @@
:until (not (= (string.sub l 1 2) "##"))] :until (not (= (string.sub l 1 2) "##"))]
(.. (or lines "") (string.gsub l "^## *" "") "\n")))))) (.. (or lines "") (string.gsub l "^## *" "") "\n"))))))
(fn relative-pathname [pathname]
(let [pathname
(if (string.match pathname ".nix$")
pathname
(.. pathname "/default.nix"))]
(pick-values 1 (string.gsub pathname "^/nix/store/[^/]+/" "modules/"))))
(fn strip-newlines [text] (fn strip-newlines [text]
(-> text (-> text
(string.gsub "\n([^\n])" " %1") (string.gsub "\n([^\n])" " %1")
@ -108,10 +115,14 @@
(tset modules path e)))) (tset modules path e))))
(tset modules "lib/modules.nix" nil) (tset modules "lib/modules.nix" nil)
(let [modules (sort-modules modules)] (let [modules (sort-modules modules)]
(each [_ {: name : module} (ipairs modules)] (each [_ {: name : module : service?} (ipairs modules)]
(let [options (sort-options module)] (let [options (sort-options module)]
(print (or (read-preamble name) (headline name))) (when (> (# options) 0)
(each [_ o (ipairs options)] (print (or (read-preamble name) (headline name)))
(if (is-service? o) (when service?
(print-service o) (print "**path** " (.. ":file:`" (relative-pathname name) "`")))
(print-option o))))))) (print)
(each [_ o (ipairs options)]
(if (is-service? o)
(print-service o)
(print-option o))))))))