(zilch): document most exported symbols

Change-Id: I6a6a6964d3be7b8c6306a21d810c639f30253d38
This commit is contained in:
puck 2025-06-23 12:22:20 +00:00
parent 6a1efc6a92
commit a80266d9d8
13 changed files with 186 additions and 81 deletions

View file

@ -7,20 +7,17 @@
(chicken base) (chicken format))
(export
<derivation> derivation?
derivation-name derivation-outputs derivation-input-drvs
derivation-input-src derivation-system derivation-builder
derivation-args derivation-env derivation-equal?
derivation-meta set-derivation-meta!
%derivation-compatible
<derivation-output> derivation-output?
derivation-output-path derivation-output-hash
derivation-output-algo derivation-output-recursive
derivation-output-placeholder? derivation-output-path-length
write-quoted-string
<derivation> derivation?
derivation-name derivation-outputs derivation-input-drvs
derivation-input-src derivation-system derivation-builder
derivation-args derivation-env derivation-equal?
derivation-meta set-derivation-meta!
drv-is-fod
derivation-serialize derivation-path-references derivation-path derivation-read read-drv-path
@ -28,7 +25,7 @@
modulo-hash-drv-contents)
(begin
;; If `#t`, outputs environment variables not used by Nix, but required for compatibility with Nix's output.
;; If `#t`, `make-[..]-derivation` will output environment variables not used by Nix, but required for compatibility with Nix's output.
;; This adds `name`, `builder`, and `system` to the environment; as well as `outputHash`, `outputHashAlgo`,
;; and `outputHashMode` for fixed-output derivations.
(define %derivation-compatible (make-parameter #t))
@ -37,11 +34,10 @@
;; whether or not it the hash is of the NAR file, if it is a content-addressed output.
;; The path can be read using `(derivation-output-path)`.
;;
;; - `(path #u8() "" #f)` is an input-addressed derivation output. TODO(puck): empty bytevector?
;; - `(path #f #f #f)` is an input-addressed derivation output. TODO(puck): empty bytevector?
;; - `(path #u8() "" #f)` is an input-addressed derivation output.
;; - `(path #f #f #f)` is an input-addressed derivation output.
;; - `(path hash-value hash-algo rec)` is a content-addressed derivation output.
;; - `(#f 'floating hash-algo rec)` is a floating content-addressed derivation output.
;; - `(#f 'impure hash-algo rec)` is an impure content-addressed derivation output.
(define-record-type <derivation-output>
(make-derivation-output path hash algo recursive)
derivation-output?
@ -57,9 +53,11 @@
(derivation-output-algo drvout)
(derivation-output-recursive drvout)))
;; Returns whether the `derivation-output-path` of this output is a placeholder (floating hash)
(define (derivation-output-placeholder? drvout)
(member (derivation-output-hash drvout) '(floating)))
;; Returns the final (post-placeholder substitution) length of a derivation's output.
(define (derivation-output-path-length drv output-name)
; /nix/store/a0a3n97c93ckfg3a920aqnycxdznbbmi-module-output
(+ (string-length (%store-dir)) 34 (string-length (derivation-name drv)) (if (string=? output-name "out") 0 (+ 1 (string-length output-name)))))
@ -74,9 +72,10 @@
(serialized derivation-metadata-serialized set-derivation-metadata-serialized!)
(meta derivation-metadata-meta set-derivation-metadata-meta!))
;; An arbitrary Scheme object stored in the `<derivation>`.
(define (derivation-meta drv)
(derivation-metadata-meta (derivation-metadata drv)))
;; Sets the object stored within the `<derivation>`.
(define (set-derivation-meta! drv meta)
(set-derivation-metadata-meta! (derivation-metadata drv) meta))
@ -88,9 +87,11 @@
(not (not (derivation-metadata-serialized drv)))))
;; An entire derivation.
;; `outputs` is stored as an alist of output name to `<derivation-output>` object.
;; `input-drvs` is stored as an alist of `<derivation>` to a (sorted) list of its outputs that are used.
;; The `outputs`, `input-drvs`, `input-src`, and `env` are expected to be sorted.
;;
;; - `outputs` is an alist of output name to `<derivation-output>` record.
;; - `input-drvs` is an alist of `<derivation>` to a (sorted) list of the outputs of said derivation that are depended on.
;;
;; `outputs`, `input-drvs`, `input-src`, and `env` are expected to be sorted.
(define-record-type <derivation>
(make-derivation name outputs input-drvs input-src system builder args env metadata)
derivation?
@ -182,7 +183,7 @@
(define (env-pair< left right)
(string<? (car left) (car right)))
;; Calculate the "modulo" contents (that will have to be hashed) of a derivation.
;; Calculate the "modulo" contents of a derivation. The modulo hash of a derivation is used in the store paths of the outputs of said derivation.
(define (modulo-hash-drv-contents drv)
(cond
((drv-is-fod drv)
@ -310,6 +311,7 @@
path)
(derivation-metadata-path (derivation-metadata drv))))
;; Equality comparison for a `<derivation>`. Checks whether the argument represent the same derivation, not just referential equality.
(define (derivation-equal? left right)
(define left-cached-path (derivation-metadata-path (derivation-metadata left)))
(define right-cached-path (derivation-metadata-path (derivation-metadata right)))
@ -494,8 +496,9 @@
(write-bracket-list (lambda (l) (write-paren-list write-quoted-string (list (car l) (cdr l)))) (derivation-env drv))
(write-u8 #x29)))
;; Writes the derivation to the specified port, or current-output-port if none is supplied.
;; If masked is set, writes the derivation using the passed-in input derivations, rather than the default one.
;; Writes the derivation to the specified port, or `(current-output-port)` if none is supplied.
;; If `masked` is set, writes the derivation using it as `input-drvs` value, rather than the one stored in the `<derivation>`.
;; This is used for generating the modulo-hashed derivation.
(define derivation-serialize
(case-lambda
((drv) (derivation-serialize drv (current-output-port)))