Beyond started with the Guix workflow language


In the previous section we defined a workflow. This section builds on the knowledge from the previous section, so if you haven't read that, now is the time to get beyond started.

Extending workflows

In the dynamic-workflow we create files and compressed those files. In the following workflow we will delete those compressed files to learn how we can extend a workflow at any point in a new workflow.

(define-module (extended-example-workflow)
  #:use-module (gwl processes)
  #:use-module (gwl workflows)
  ;; We use a prefix here because "zip" is a package but also a
  ;; procedure in srfi-1.
  #:use-module ((gnu packages compression) #:prefix package:)
  #:use-module (srfi srfi-1)
  #:use-module (example-workflow)) ; We are going to extend "example-workflow".

(define (delete-file-template filename)
   (name (string-append "delete-file-" (basename filename)))
   (run-time (complexity
              (space (megabytes 20))
              (time 10)))
    `(delete-file ,filename))))

(define-public extended-dynamic-workflow
  (let* (;; Get all processes of the other workflow.
         (foreign-processes (workflow-processes dynamic-workflow))

         ;; Get the processes that we want to extend on.
         (compress-file-processes (processes-filter-by-name
                                   foreign-processes "compress-file"))

         ;; Create the new processes.
         (delete-file-processes (map delete-file-template
                                     (map (compose first process-outputs)
     (name "extended-dynamic-workflow")
      (append foreign-processes delete-file-processes))
       (workflow-restrictions dynamic-workflow)
       (zip delete-file-processes compress-file-processes))))))

With delete-file-template we created a function that returns a process that removes a file. We use this function in extended-dynamic-workflow to run after each compress-file process.

In the processes and restrictions fields we include the contents of dynamic-workflow. Explicitly expressing the new restrictions displays how this workflow extends the other in a concise way. Because dynamic-workflow is defined in a Scheme module, we can use the #:use-module facility to refer to it.

Further reading

The GNU Guile and GNU Guix manuals are good places to learn the language and concepts on which GWL builds.