HGRC Quarry Fossil Service
Simple tools for lasting software

Infrastructure as a Service / Nemoptera

A solid foundation to fork, tweak, and enhance.

Public | Owner: Infrastructure as a Service | Default branch: trunk | Last update: 2026-11-08 15:56

Artifact f19534b9aada95bc44cb8adfcd4c59afef224a3702e0903189c99b8af58c6cac:


(defmodule nemoptera_config
  (export all))

(defun default-conf-path () "data/nemoptera.conf")
(defun listen-port () 8731)

(defun load ()
  (load (default-conf-path)))

(defun load (path)
  (case (file:consult path)
    (`#(ok ,terms)
     (let ((conf (maps:from_list terms)))
       (persistent_term:put 'nemoptera_conf conf)
       `#(ok ,conf)))
    (`#(error ,reason)
     `#(error ,(tuple 'consult-failed path reason)))))

(defun reload ()
  (persistent_term:erase 'nemoptera_conf)
  (load))

(defun put (conf)
  (persistent_term:put 'nemoptera_conf conf))

(defun get (key default)
  (case (maps:find key (current))
    (`#(ok ,value) value)
    ('error default)))

(defun db-path ()
  (get 'db_path "data/nemoptera.db"))

(defun repo-dir ()
  (get 'repo_dir "data/repos"))

(defun fossil-bin ()
  (case (maps:find 'fossil_bin (current))
    (`#(ok ,bin) bin)
    ('error
     (case (which-fossil (path-dirs))
       (`#(ok ,path) path)
       ('error 'fossil)))))

(defun write (pairs)
  (let ((path (default-conf-path)))
    (filelib:ensure_dir path)
    (let ((body (lists:map
                 (lambda (pair)
                   (lists:flatten (io_lib:format "~p.~n" (list pair))))
                 pairs)))
      (file:write_file path (lists:flatten body)))))

(defun current ()
  (case (persistent_term:get 'nemoptera_conf 'error)
    ('error
     (case (load)
       (`#(ok ,conf) conf)
       (_ #M())))
    (conf conf)))

(defun path-dirs ()
  (string:split (os:getenv "PATH" "") ":" 'all))

(defun which-fossil (dirs)
  (case dirs
    ('() 'error)
    (`(,dir . ,rest)
     (let ((candidate (filename:join dir "fossil")))
       (case (file:read_file_info candidate)
         (`#(ok ,info)
          (if (executable? info)
              `#(ok ,candidate)
              (which-fossil rest)))
         (_ (which-fossil rest)))))))

(defun executable? (info)
  (/= 0 (band (element 8 info) 511)))

Clone

You can clone this repository with the following command:

fossil clone https://hgrc.dev/IaaS/Nemoptera Nemoptera.fossil

Contribute

The best way to contribute is through e-mail. See the project documentation for more details.