123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510 |
- (define-module (build-self)
- #:use-module (gnu)
- #:use-module (guix)
- #:use-module (guix ui)
- #:use-module (guix config)
- #:use-module (guix modules)
- #:use-module (guix build-system gnu)
- #:use-module (srfi srfi-1)
- #:use-module (srfi srfi-19)
- #:use-module (srfi srfi-34)
- #:use-module (srfi srfi-35)
- #:use-module (rnrs io ports)
- #:use-module (ice-9 match)
- #:use-module (ice-9 popen)
- #:export (build))
- (define %persona-variables
-
- '(%guix-package-name
- %guix-version
- %guix-bug-report-address
- %guix-home-page-url))
- (define %config-variables
-
- (letrec-syntax ((variables (syntax-rules ()
- ((_)
- '())
- ((_ variable rest ...)
- (cons `(variable . ,variable)
- (variables rest ...))))))
- (variables %localstatedir %storedir %sysconfdir %system)))
- (define* (make-config.scm #:key gzip xz bzip2
- (package-name "GNU Guix")
- (package-version "0")
- (bug-report-address "bug-guix@gnu.org")
- (home-page-url "https://guix.gnu.org"))
-
- (define defmod 'define-module)
- (scheme-file "config.scm"
- #~(begin
- (#$defmod (guix config)
- #:export (%guix-package-name
- %guix-version
- %guix-bug-report-address
- %guix-home-page-url
- %store-directory
- %state-directory
- %store-database-directory
- %config-directory
- %libz
- %gzip
- %bzip2
- %xz))
-
- (eval-when (expand load eval)
- #$@(map (match-lambda
- ((name . value)
- #~(define-public #$name #$value)))
- %config-variables)
- (define %store-directory
- (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
- %storedir))
- (define %state-directory
-
-
- (or (getenv "GUIX_STATE_DIRECTORY")
- (string-append %localstatedir "/guix")))
- (define %store-database-directory
- (or (getenv "GUIX_DATABASE_DIRECTORY")
- (string-append %state-directory "/db")))
- (define %config-directory
-
-
- (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
- (string-append %sysconfdir "/guix")))
- (define %guix-package-name #$package-name)
- (define %guix-version #$package-version)
- (define %guix-bug-report-address #$bug-report-address)
- (define %guix-home-page-url #$home-page-url)
- (define %gzip
- #+(and gzip (file-append gzip "/bin/gzip")))
- (define %bzip2
- #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
- (define %xz
- #+(and xz (file-append xz "/bin/xz")))))))
- (define (load-path-expression modules path)
- "Return as a monadic value a gexp that sets '%load-path' and
- '%load-compiled-path' to point to MODULES, a list of module names. MODULES
- are searched for in PATH."
- (mlet %store-monad ((modules (imported-modules modules
- #:module-path path))
- (compiled (compiled-modules modules
- #:module-path path)))
- (return (gexp (eval-when (expand load eval)
- (set! %load-path
- (cons (ungexp modules) %load-path))
- (set! %load-compiled-path
- (cons (ungexp compiled)
- %load-compiled-path)))))))
- (define* (gexp->script name exp
- #:key (guile (default-guile))
- (module-path %load-path))
- "Return an executable script NAME that runs EXP using GUILE, with EXP's
- imported modules in its search path."
- (mlet %store-monad ((set-load-path
- (load-path-expression (gexp-modules exp)
- module-path)))
- (gexp->derivation name
- (gexp
- (call-with-output-file (ungexp output)
- (lambda (port)
-
-
-
-
- (format port
- "#!~a/bin/guile --no-auto-compile~%!#~%"
- (ungexp guile))
- (write '(ungexp set-load-path) port)
- (write '(ungexp exp) port)
- (chmod port #o555))))
- #:module-path module-path)))
- (define (date-version-string)
- "Return the current date and hour in UTC timezone, for use as a poor
- person's version identifier."
-
- (date->string (current-date 0) "~Y~m~d.~H"))
- (define guile-gcrypt
-
-
-
-
- (match (find-best-packages-by-name "guile-gcrypt" #f)
- (()
- (package
- (name "guile-gcrypt")
- (version "0.1.0")
- (home-page "https://notabug.org/cwebber/guile-gcrypt")
- (source (origin
- (method url-fetch)
- (uri (string-append home-page "/archive/v" version ".tar.gz"))
- (sha256
- (base32
- "1gir7ifknbmbvjlql5j6wzk7bkb5lnmq80q59ngz43hhpclrk5k3"))
- (file-name (string-append name "-" version ".tar.gz"))))
- (build-system gnu-build-system)
- (arguments
-
-
- '(#:phases (modify-phases %standard-phases
- (delete 'bootstrap)
- (add-before 'configure 'bootstrap
- (lambda _
- (unless (zero? (system* "autoreconf" "-vfi"))
- (error "autoreconf failed"))
- #t)))))
- (native-inputs
- `(("pkg-config" ,(specification->package "pkg-config"))
- ("autoconf" ,(specification->package "autoconf"))
- ("automake" ,(specification->package "automake"))
- ("texinfo" ,(specification->package "texinfo"))))
- (inputs
- `(("guile" ,(specification->package "guile"))
- ("libgcrypt" ,(specification->package "libgcrypt"))))
- (synopsis "Cryptography library for Guile using Libgcrypt")
- (description
- "Guile-Gcrypt provides a Guile 2.x interface to a subset of the
- GNU Libgcrypt crytographic library. It provides modules for cryptographic
- hash functions, message authentication codes (MAC), public-key cryptography,
- strong randomness, and more. It is implemented using the foreign function
- interface (FFI) of Guile.")
- (license #f)))
- ((package . _)
- package)))
- (define* (build-program source version
- #:optional (guile-version (effective-version))
- #:key (pull-version 0) (channel-metadata #f))
- "Return a program that computes the derivation to build Guix from SOURCE."
- (define select?
-
-
-
- (match-lambda
- (('guix 'config) #f)
- (('guix 'channels) #f)
- (('guix 'build 'download) #f)
- (('guix _ ...) #t)
- (('gnu _ ...) #t)
- (_ #f)))
- (define fake-gcrypt-hash
-
- (scheme-file "hash.scm"
- #~(define-module (gcrypt hash)
- #:export (sha1 sha256))))
- (define fake-git
- (scheme-file "git.scm" #~(define-module (git))))
- (with-imported-modules `(((guix config)
- => ,(make-config.scm))
- ;; To avoid relying on 'with-extensions', which was
- ;; introduced in 0.15.0, provide a fake (gcrypt
- ;; hash) just so that we can build modules, and
- ;; adjust %LOAD-PATH later on.
- ((gcrypt hash) => ,fake-gcrypt-hash)
- ;; (guix git-download) depends on (git) but only
- ;; for peripheral functionality. Provide a dummy
- ;; (git) to placate it.
- ((git) => ,fake-git)
- ,@(source-module-closure `((guix store)
- (guix self)
- (guix derivations)
- (gnu packages bootstrap))
- (list source)
- #:select? select?))
- (gexp->script "compute-guix-derivation"
- #~(begin
- (use-modules (ice-9 match))
- (eval-when (expand load eval)
-
-
- (match (command-line)
- ((_ source _ ...)
- (match %load-path
- ((front _ ...)
- (unless (string=? front source)
- (set! %load-path
- (list source
- (string-append #$guile-gcrypt
- "/share/guile/site/"
- (effective-version))
- front)))))))
-
-
- (set! %load-compiled-path
- (cons (string-append #$guile-gcrypt "/lib/guile/"
- (effective-version)
- "/site-ccache")
- %load-compiled-path))
-
-
- (read-disable 'positions))
- (use-modules (guix store)
- (guix self)
- (guix derivations)
- (srfi srfi-1))
- (match (command-line)
- ((_ source system version protocol-version
- build-output)
-
-
-
-
-
-
- (let* ((proto (string->number protocol-version))
- (store (if (integer? proto)
- (port->connection (duplicate-port
- (current-input-port)
- "w+0")
- #:version proto)
- (open-connection)))
- (sock (socket AF_UNIX SOCK_STREAM 0)))
-
-
- (connect sock AF_UNIX build-output)
- (display
- (and=>
-
- (parameterize ((current-warning-port
- (%make-void-port "w"))
- (current-build-output-port sock))
- (run-with-store store
- (guix-derivation source version
- #$guile-version
- #:channel-metadata
- '#$channel-metadata
- #:pull-version
- #$pull-version)
- #:system system))
- derivation-file-name))))))
- #:module-path (list source))))
- (define (proxy input output)
- "Dump the contents of INPUT to OUTPUT until EOF is reached on INPUT.
- Display a spinner when nothing happens."
- (define spin
- (circular-list "-" "\\" "|" "/" "-" "\\" "|" "/"))
- (setvbuf input 'block 16384)
- (let loop ((spin spin))
- (match (select (list input) '() '() 1)
- ((() () ())
- (when (isatty? (current-error-port))
- (display (string-append "\b" (car spin))
- (current-error-port))
- (force-output (current-error-port)))
- (loop (cdr spin)))
- (((_) () ())
-
- (let ((bv (get-bytevector-some input)))
- (unless (eof-object? bv)
- (put-bytevector output bv)
- (loop spin)))))))
- (define (call-with-clean-environment thunk)
- (let ((env (environ)))
- (dynamic-wind
- (lambda ()
- (environ '()))
- thunk
- (lambda ()
- (environ env)))))
- (define-syntax-rule (with-clean-environment exp ...)
- "Evaluate EXP in a context where zero environment variables are defined."
- (call-with-clean-environment (lambda () exp ...)))
- (define* (build source
- #:key verbose?
- (version (date-version-string)) channel-metadata
- system
- (pull-version 0)
-
-
-
- (guile-version (if (> pull-version 0)
- "3.0"
- (effective-version)))
- #:allow-other-keys
- #:rest rest)
- "Return a derivation that unpacks SOURCE into STORE and compiles Scheme
- files."
-
-
- (mlet %store-monad ((build (build-program source version guile-version
- #:channel-metadata channel-metadata
- #:pull-version pull-version))
- (system (if system (return system) (current-system)))
- (home -> (getenv "HOME"))
-
-
- (port ((store-lift nix-server-socket)))
- (major ((store-lift nix-server-major-version)))
- (minor ((store-lift nix-server-minor-version))))
- (mbegin %store-monad
-
-
- (munless (module-defined? (resolve-module '(guix store))
- 'with-build-handler)
- (show-what-to-build* (list build)))
- (built-derivations (list build))
-
-
-
-
- (let* ((sock (socket AF_UNIX SOCK_STREAM 0))
- (node (let ((file (string-append (or (getenv "TMPDIR") "/tmp")
- "/guix-build-output-"
- (number->string (getpid)))))
- (bind sock AF_UNIX file)
- (listen sock 1)
- file))
- (pipe (with-input-from-port port
- (lambda ()
-
-
- (with-clean-environment
- (setenv "GUILE_WARN_DEPRECATED" "no")
- (setenv "COLUMNS" "120")
- (when home
-
- (setenv "HOME" home))
- (open-pipe* OPEN_READ
- (derivation->output-path build)
- source system version
- (if (file-port? port)
- (number->string
- (logior major minor))
- "none")
- node))))))
- (format (current-error-port) "Computing Guix derivation for '~a'... "
- system)
-
-
-
- (match (accept sock)
- ((port . _)
- (close-port sock)
- (delete-file node)
- (proxy port (current-build-output-port))))
-
-
- (let ((str (get-string-all pipe))
- (status (close-pipe pipe)))
- (match str
- ((? eof-object?)
- (error "build program failed" (list build status)))
- ((? derivation-path? drv)
- (mbegin %store-monad
- (return (newline (current-error-port)))
- ((store-lift add-temp-root) drv)
- (return (read-derivation-from-file drv))))
- ("#f"
-
- (return #f))
- ((? string? str)
- (raise (condition
- (&message
- (message (format #f "You found a bug: the program '~a'
- failed to compute the derivation for Guix (version: ~s; system: ~s;
- host version: ~s; pull-version: ~s).
- Please report it by email to <~a>.~%"
- (derivation->output-path build)
- version system %guix-version pull-version
- %guix-bug-report-address))))))))))))
- build
|