snow-fort-guix-channel/build.scm

126 lines
4.7 KiB
Scheme
Raw Permalink Normal View History

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))
2024-10-11 14:45:42 -04:00
(include "licenses.scm")
2024-10-06 09:33:19 -04:00
(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-11 14:45:11 -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))
(define snow-libraries (list))
(for-each
(lambda (item)
(when (equal? (car item) 'package)
(for-each
(lambda (item)
(when (equal? (car item) 'library)
(set! snow-libraries (append snow-libraries (list (cadr (assoc 'name (cdr item))))))))
(cdr item))))
(cdr repository))
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))
2024-10-11 02:10:16 -04:00
(not (equal? (car dependency) 'srfi))
(not (equal? dependency '(chibi)))
(member dependency snow-libraries)))
2024-10-11 14:45:11 -04:00
dependencies))))
2024-10-06 09:33:19 -04:00
(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)))))
(define module-definition
'(define-module (snow-fort)
#:use-module (guix licenses)
2024-10-11 14:45:11 -04:00
#:use-module (guix search-paths)
#:use-module ((guix packages) #:select (package origin base32))
#:use-module (guix build-system copy)
#:use-module ((guix download) #:select (url-fetch))))
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)))) "/"))
2024-10-11 03:14:29 -04:00
(target-path (string-append "/usr/lib/snow/" source-path))
2024-10-06 09:33:19 -04:00
(description (if (assoc 'description lib) (cadr (assoc 'description lib)) ""))
(guix-package
2024-10-11 14:45:11 -04:00
`(package
(name ,name)
(version ,version)
(source (origin
(method url-fetch)
(uri ,url)
(sha256 (base32 ,sha-256))))
(build-system copy-build-system)
(arguments (list #:install-plan ''((,source-path ,target-path))))
(synopsis ,description)
(description ,description)
(home-page "")
(license ,license)
2024-10-11 15:13:34 -04:00
(search-paths
2024-10-11 14:45:11 -04:00
(list (search-path-specification
(variable "SNOW_LIBRARY_PATH")
(files '("usr/lib/snow"))))))))
2024-10-06 12:06:45 -04:00
(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)
(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))