2017-03-26 03:15:42 +01:00
|
|
|
; QuickLisp-to-Nix export
|
|
|
|
; Requires QuickLisp to be loaded
|
|
|
|
; Installs the QuickLisp version of all the packages processed (in the
|
|
|
|
; QuickLisp instance it uses)
|
|
|
|
|
|
|
|
(ql:quickload :cl-emb)
|
|
|
|
(ql:quickload :external-program)
|
|
|
|
(ql:quickload :cl-ppcre)
|
|
|
|
(ql:quickload :alexandria)
|
2017-04-01 07:08:02 +01:00
|
|
|
(ql:quickload :md5)
|
|
|
|
|
|
|
|
(defvar testnames (make-hash-table :test 'equal))
|
2017-03-26 03:15:42 +01:00
|
|
|
|
|
|
|
(defun nix-prefetch-url (url)
|
|
|
|
(let*
|
|
|
|
((stdout nil)
|
|
|
|
(stderr nil))
|
|
|
|
(setf
|
|
|
|
stdout
|
|
|
|
(with-output-to-string (so)
|
|
|
|
(setf
|
|
|
|
stderr
|
|
|
|
(with-output-to-string (se)
|
|
|
|
(external-program:run
|
|
|
|
"nix-prefetch-url"
|
|
|
|
(list url)
|
|
|
|
:search t :output so :error se)))))
|
|
|
|
(let*
|
|
|
|
((path-line (first (last (cl-ppcre:split (format nil "~%") stderr))))
|
|
|
|
(path (cl-ppcre:regex-replace-all "path is .(.*)." path-line "\\1")))
|
|
|
|
(list
|
|
|
|
:sha256 (first (cl-ppcre:split (format nil "~%") stdout))
|
|
|
|
:path path
|
|
|
|
:md5 (string-downcase
|
|
|
|
(format nil "~{~16,2,'0r~}"
|
|
|
|
(map 'list 'identity (md5:md5sum-file path))))))))
|
|
|
|
|
2017-03-30 11:15:08 +01:00
|
|
|
(defun escape-filename (s)
|
2017-06-21 21:15:07 +01:00
|
|
|
(format
|
|
|
|
nil "~a~{~a~}"
|
|
|
|
(if (cl-ppcre:scan "^[a-zA-Z_]" s) "" "_")
|
|
|
|
(loop
|
|
|
|
for x in (map 'list 'identity s)
|
|
|
|
collect
|
|
|
|
(case x
|
|
|
|
(#\/ "_slash_")
|
|
|
|
(#\\ "_backslash_")
|
|
|
|
(#\_ "__")
|
|
|
|
(#\. "_dot_")
|
|
|
|
(t x)))))
|
2017-03-30 11:15:08 +01:00
|
|
|
|
2017-08-01 03:29:53 +01:00
|
|
|
(defun system-depends-on (system-name)
|
|
|
|
(labels
|
|
|
|
((decode (name)
|
|
|
|
(typecase name
|
|
|
|
(string
|
|
|
|
name)
|
|
|
|
(cons
|
|
|
|
(ecase (car name)
|
|
|
|
(:version (second name)))))))
|
|
|
|
(let* ((asdf-dependencies (asdf:system-depends-on (asdf:find-system system-name)))
|
|
|
|
(decoded-asdf-dependencies (mapcar #'decode asdf-dependencies))
|
|
|
|
(clean-asdf-dependencies (remove-if-not 'ql-dist:find-system decoded-asdf-dependencies))
|
|
|
|
(ql-dependencies (ql-dist:required-systems (ql-dist:find-system system-name)))
|
|
|
|
(all-dependencies (concatenate 'list clean-asdf-dependencies ql-dependencies))
|
|
|
|
(sorted-dependencies (sort all-dependencies #'string<))
|
|
|
|
(unique-dependencies (remove-duplicates sorted-dependencies :test #'equal)))
|
|
|
|
unique-dependencies)))
|
|
|
|
|
2017-03-26 03:15:42 +01:00
|
|
|
(defun system-data (system)
|
|
|
|
(let*
|
2017-06-21 21:15:07 +01:00
|
|
|
((asdf-system
|
|
|
|
(or
|
|
|
|
(ignore-errors (asdf:find-system system))
|
|
|
|
(progn
|
|
|
|
(ql:quickload system)
|
|
|
|
(asdf:find-system system))))
|
2017-03-26 03:15:42 +01:00
|
|
|
(ql-system (ql-dist:find-system system))
|
|
|
|
(ql-release (ql-dist:release ql-system))
|
2017-04-01 07:08:02 +01:00
|
|
|
(ql-sibling-systems (ql-dist:provided-systems ql-release))
|
2017-03-26 03:15:42 +01:00
|
|
|
(url (ql-dist:archive-url ql-release))
|
|
|
|
(local-archive (ql-dist:local-archive-file ql-release))
|
|
|
|
(local-url (format nil "file://~a" (pathname local-archive)))
|
|
|
|
(archive-data
|
|
|
|
(progn
|
|
|
|
(ql-dist:ensure-local-archive-file ql-release)
|
|
|
|
(nix-prefetch-url local-url)))
|
|
|
|
(ideal-md5 (ql-dist:archive-md5 ql-release))
|
|
|
|
(file-md5 (getf archive-data :md5))
|
2017-08-01 03:29:53 +01:00
|
|
|
(raw-dependencies (system-depends-on system))
|
2017-03-26 03:15:42 +01:00
|
|
|
(name (string-downcase (format nil "~a" system)))
|
2017-04-01 07:08:02 +01:00
|
|
|
(ql-sibling-names
|
|
|
|
(remove name (mapcar 'ql-dist:name ql-sibling-systems)
|
|
|
|
:test 'equal))
|
|
|
|
(dependencies
|
|
|
|
(set-difference
|
|
|
|
(remove-duplicates
|
|
|
|
(remove-if-not 'ql-dist:find-system raw-dependencies)
|
|
|
|
:test 'equal)
|
|
|
|
ql-sibling-names
|
|
|
|
:test 'equal))
|
2017-06-21 21:15:07 +01:00
|
|
|
(deps (mapcar (lambda (x) (list :name x :filename (escape-filename x)))
|
|
|
|
dependencies))
|
2017-03-26 03:15:42 +01:00
|
|
|
(description (asdf:system-description asdf-system))
|
|
|
|
(release-name (ql-dist:short-description ql-release))
|
|
|
|
(version (cl-ppcre:regex-replace-all
|
|
|
|
(format nil "~a-" name) release-name "")))
|
|
|
|
(assert (equal ideal-md5 file-md5))
|
|
|
|
(list
|
|
|
|
:system system
|
|
|
|
:description description
|
|
|
|
:sha256 (getf archive-data :sha256)
|
|
|
|
:url url
|
|
|
|
:md5 file-md5
|
|
|
|
:name name
|
2017-03-30 21:54:56 +01:00
|
|
|
:testname (gethash name testnames)
|
2017-03-30 11:15:08 +01:00
|
|
|
:filename (escape-filename name)
|
2017-03-26 03:15:42 +01:00
|
|
|
:deps deps
|
|
|
|
:dependencies dependencies
|
2017-04-01 07:08:02 +01:00
|
|
|
:version version
|
|
|
|
:siblings ql-sibling-names)))
|
2017-03-26 03:15:42 +01:00
|
|
|
|
|
|
|
(defmacro this-file ()
|
|
|
|
(or *compile-file-truename*
|
|
|
|
*load-truename*))
|
|
|
|
|
|
|
|
(defun nix-expression (system)
|
|
|
|
(cl-emb:execute-emb
|
|
|
|
(merge-pathnames #p"nix-package.emb" (this-file))
|
|
|
|
:env (system-data system)))
|
|
|
|
(defun nix-invocation (system)
|
|
|
|
(cl-emb:execute-emb
|
|
|
|
(merge-pathnames #p"invocation.emb" (this-file))
|
|
|
|
:env (system-data system)))
|
|
|
|
|
|
|
|
(defun systems-closure (systems)
|
|
|
|
(let*
|
|
|
|
((seen (make-hash-table :test 'equal)))
|
|
|
|
(loop
|
|
|
|
with queue := systems
|
|
|
|
with res := nil
|
|
|
|
while queue
|
|
|
|
for next := (pop queue)
|
2017-04-01 07:08:02 +01:00
|
|
|
for old := (gethash next seen)
|
|
|
|
for data := (unless old (system-data next))
|
|
|
|
for deps := (getf data :dependencies)
|
|
|
|
for siblings := (getf data :siblings)
|
|
|
|
unless old do
|
2017-03-26 03:15:42 +01:00
|
|
|
(progn
|
|
|
|
(push next res)
|
|
|
|
(setf queue (append queue deps)))
|
|
|
|
do (setf (gethash next seen) t)
|
|
|
|
finally (return res))))
|
|
|
|
|
|
|
|
(defun ql-to-nix (target-directory)
|
2017-03-30 21:54:56 +01:00
|
|
|
(load (format nil "~a/quicklisp-to-nix-overrides.lisp" target-directory))
|
2017-03-26 03:15:42 +01:00
|
|
|
(let*
|
|
|
|
((systems
|
|
|
|
(cl-ppcre:split
|
|
|
|
(format nil "~%")
|
|
|
|
(alexandria:read-file-into-string
|
|
|
|
(format nil "~a/quicklisp-to-nix-systems.txt" target-directory))))
|
|
|
|
(closure (systems-closure systems))
|
|
|
|
(invocations
|
|
|
|
(loop for s in closure
|
|
|
|
collect (list :code (nix-invocation s)))))
|
|
|
|
(loop
|
|
|
|
for s in closure
|
|
|
|
do (alexandria:write-string-into-file
|
|
|
|
(nix-expression s)
|
2017-03-30 11:15:08 +01:00
|
|
|
(format nil "~a/quicklisp-to-nix-output/~a.nix"
|
|
|
|
target-directory (escape-filename s))
|
2017-03-26 03:15:42 +01:00
|
|
|
:if-exists :supersede))
|
|
|
|
(alexandria:write-string-into-file
|
|
|
|
(cl-emb:execute-emb
|
|
|
|
(merge-pathnames
|
|
|
|
#p"top-package.emb"
|
|
|
|
(this-file))
|
|
|
|
:env (list :invocations invocations))
|
|
|
|
(format nil "~a/quicklisp-to-nix.nix" target-directory)
|
|
|
|
:if-exists :supersede)))
|