 
 (require 'cl-lib)
 
-(defun nyxt-pure-env (&rest preserve-vars)
+(defun nyxt--pure-env (&rest preserve-vars)
   "Return a pure `env' command as a list of string."
   (append '("env" "-i")
           (mapcar (lambda (var) (concat var "=" (getenv var)))

  (setq image-path (expand-file-name
                    (or image-path
                        (concat (nyxt-cache-dir) "/sbcl-nyxt.image"))))
  (let ((guix-def (concat nyxt-checkout "/build-scripts/guix.scm"))
        (output (get-buffer-create " *Guix SBCL for Nyxt*")))
    (when (or force
              (not (file-exists-p image-path))
              (time-less-p (nyxt-mtime image-path) (nyxt-mtime guix-def)))
      (ignore-errors (delete-file image-path))
      (make-directory (file-name-directory image-path) :parents)
      (let ((status (apply #'call-process
                           "guix"
                           nil (list output t) nil
                           "environment"
                           `(,@(when no-grafts
                                 '("--no-grafts"))
                             "-l" ,guix-def
                             ,@(if container
                                   (list
                                    "--container"
                                    (concat "--share=" (file-name-directory image-path))
                                    (concat "--share=" nyxt-checkout "=/nyxt"))
                                 '("--pure"))
                             "--ad-hoc" "lisp-repl-core-dumper"
                             "--"
                             "sbcl" "--noinform" "--no-userinit" "--eval" "(require :asdf)"
                             "--eval" ,(prin1-to-string (nyxt--cl-dump-call image-path))
                             "--quit"))))
        (if (= status)
            (kill-buffer output)
          (error "Guix environment failed, see %s" output)
          (switch-to-buffer-other-window output))))
    `((,@(apply #'nyxt-pure-env preserve) ,image-path))))

(provide 'nyxt-guix)

                     "TERM"
                     "USER")
                   preserve-vars))))

(defun nyxt--guix-preserve-vars (&rest preserve-vars)
  "Return the arguments to pass to `guix environment' to preserve PRESERVE-VARS."
  (mapcar (lambda (var) (format "--preserve=^%s$" var))
          preserve-vars))

(defun nyxt-mtime (file)
  "Return modification time of FILE."
