2024-10-06 09:33:19 -04:00
|
|
|
(import (scheme base)
|
|
|
|
(scheme read)
|
|
|
|
(scheme write)
|
|
|
|
(scheme file)
|
|
|
|
(scheme process-context)
|
|
|
|
(srfi 1)
|
|
|
|
(srfi 13)
|
|
|
|
(srfi 14))
|
|
|
|
|
|
|
|
(include "licenses.scm")
|
|
|
|
|
|
|
|
(define tmpdir (list-ref (command-line) 1))
|
|
|
|
(if (not (file-exists? "repo.scm")) (error "No repo.scm found"))
|
|
|
|
(define repository (with-input-from-file "repo.scm" (lambda () (read))))
|
|
|
|
(define base-url "https://snow-fort.org")
|
2024-10-06 11:32:21 -04:00
|
|
|
(define module-file-path "packages/snow-fort.scm")
|
|
|
|
(when (file-exists? module-file-path) (delete-file module-file-path))
|
|
|
|
(define module-file (open-output-file module-file-path))
|
2024-10-06 09:33:19 -04:00
|
|
|
|
|
|
|
(define snow-dependencies->guix-dependencies
|
|
|
|
(lambda (dependencies)
|
|
|
|
(map
|
|
|
|
(lambda (dependency)
|
2024-10-06 11:14:17 -04:00
|
|
|
(string->symbol
|
|
|
|
(string-join (cons "snow" (map symbol->string dependency)) "-")))
|
2024-10-06 09:33:19 -04:00
|
|
|
(filter
|
|
|
|
(lambda (dependency)
|
|
|
|
(and (not (equal? (car dependency) 'scheme))
|
|
|
|
(not (equal? (car dependency) 'srfi))))
|
|
|
|
dependencies))))
|
|
|
|
|
|
|
|
(define snow-license->guix-license
|
|
|
|
(lambda (license-pair)
|
|
|
|
(cond ((not license-pair) 'public-domain)
|
|
|
|
((assoc (cadr license-pair) license-connections)
|
|
|
|
(cadr (assoc (cadr license-pair) license-connections)))
|
|
|
|
(else (error "Unconnected license" license-pair)))))
|
|
|
|
|
|
|
|
(define to-string
|
|
|
|
(lambda (item)
|
|
|
|
(cond ((symbol? item)
|
|
|
|
(symbol->string item))
|
|
|
|
((number? item)
|
|
|
|
(number->string item)))))
|
|
|
|
|
2024-10-06 11:32:21 -04:00
|
|
|
(define module-definition
|
|
|
|
'(define-module (snow-fort)
|
|
|
|
#:use-module (guix licenses)
|
2024-10-11 01:40:12 -04:00
|
|
|
#:use-module ((guix packages) #:select (package origin base32))
|
2024-10-06 11:32:21 -04:00
|
|
|
#:use-module (guix build-system copy)
|
2024-10-11 01:40:12 -04:00
|
|
|
#:use-module ((guix download) #:select (url-fetch))))
|
2024-10-06 11:32:21 -04:00
|
|
|
|
2024-10-06 09:33:19 -04:00
|
|
|
(define snow-library->guix-library
|
|
|
|
(lambda (lib version url sha-256 license)
|
|
|
|
(let* ((name (string-join (cons "snow" (map to-string (cadr (assoc 'name lib)))) "-"))
|
|
|
|
(dependencies (snow-dependencies->guix-dependencies (cdr (assoc 'depends lib))))
|
|
|
|
(source-path (string-append (symbol->string (car (cadr (assoc 'name lib)))) "/"))
|
|
|
|
(target-path (string-append "share/snow/" source-path))
|
|
|
|
(description (if (assoc 'description lib) (cadr (assoc 'description lib)) ""))
|
|
|
|
(guix-package
|
2024-10-06 12:06:45 -04:00
|
|
|
`(package
|
2024-10-06 09:33:19 -04:00
|
|
|
(name ,name)
|
|
|
|
(version ,version)
|
|
|
|
(source (origin
|
|
|
|
(method url-fetch)
|
|
|
|
(uri ,url)
|
2024-10-06 10:38:08 -04:00
|
|
|
(sha256 (base32 ,sha-256))))
|
2024-10-06 09:33:19 -04:00
|
|
|
(build-system copy-build-system)
|
2024-10-06 12:06:45 -04:00
|
|
|
(arguments (list #:install-plan ''((,source-path ,target-path))))
|
2024-10-06 09:33:19 -04:00
|
|
|
(synopsis ,description)
|
|
|
|
(description ,description)
|
2024-10-06 11:43:51 -04:00
|
|
|
(home-page "")
|
2024-10-06 12:06:45 -04:00
|
|
|
(license ,license))))
|
|
|
|
(if (null? dependencies)
|
|
|
|
(write `(define-public ,(string->symbol name) ,guix-package) module-file)
|
|
|
|
(write `(define-public
|
|
|
|
,(string->symbol name)
|
|
|
|
,(append
|
|
|
|
guix-package
|
|
|
|
`((propagated-inputs ,(cons 'list dependencies)))))
|
|
|
|
module-file))
|
2024-10-06 11:43:51 -04:00
|
|
|
(newline module-file)
|
2024-10-06 11:32:21 -04:00
|
|
|
(newline module-file))))
|
2024-10-06 09:33:19 -04:00
|
|
|
|
|
|
|
(define snow-package->guix-libraries
|
|
|
|
(lambda (package)
|
|
|
|
(let* ((version (cadr (assoc 'version package)))
|
|
|
|
(license (snow-license->guix-license (assoc 'license package)))
|
|
|
|
(url (string-append base-url (car (cdr (assoc 'url package)))))
|
|
|
|
(filename (car (reverse (string-tokenize url (char-set-delete char-set:ascii #\/)))))
|
|
|
|
(sha-256 (with-input-from-file
|
|
|
|
(string-append tmpdir "/hashes/" filename ".hash")
|
|
|
|
(lambda () (read-line)))))
|
|
|
|
(for-each
|
|
|
|
(lambda (item)
|
|
|
|
(when (equal? (car item) 'library)
|
|
|
|
(snow-library->guix-library (cdr item) version url sha-256 license)))
|
|
|
|
package))))
|
|
|
|
|
2024-10-06 11:43:51 -04:00
|
|
|
(write module-definition module-file)
|
|
|
|
(newline module-file)
|
|
|
|
(newline module-file)
|
|
|
|
|
2024-10-06 09:33:19 -04:00
|
|
|
(for-each
|
|
|
|
(lambda (item)
|
|
|
|
(when (equal? (car item) 'package)
|
2024-10-06 11:43:51 -04:00
|
|
|
(snow-package->guix-libraries (cdr item))))
|
2024-10-06 09:33:19 -04:00
|
|
|
(cdr repository))
|