#!/run/current-system/profile/bin/guile \
--no-auto-compile -e (youtube-build) -s
!#

;;;; youtube-build --- SYNOPSIS
;;;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com>
;;;; Released under the GNU GPLv3 or any later version.

(define-module (youtube-build)
  #:use-module (srfi srfi-37)
  #:use-module (guix discovery)
  #:use-module (guix packages)
  #:use-module (guix monads)
  #:use-module (guix store)
  #:use-module (guix derivations)
  #:export (main))

;;; Commentary:
;;;
;;; DESCRIPTION
;;;
;;; Code:

(define %options
  (let ((display-and-exit-proc (lambda (msg)
                                 (lambda (opt name arg loads)
                                   (display msg) (quit)))))
    (list (option '(#\v "version") #f #f
                  (display-and-exit-proc "youtube-build version 0.0.1\n"))
          (option '(#\h "help") #f #f
                  (display-and-exit-proc
                   "Usage: youtube-build ...")))))

(define %default-options
  '())

(define c (open-connection))

(define (main args)
  (define opts
    (args-fold (cdr (program-arguments))
               %options
               (lambda (opt name arg loads)
                 (error "Unrecognized option `~A'" name))
               (lambda (op loads)
                 (cons op loads))
               %default-options))
  (add-to-load-path "/home/oleg/src/music")
  (map (lambda (package)
         (run-with-store c (package->derivation package)))
       (fold-module-public-variables cons '()
                                     (all-modules (map (lambda (entry)
                                                         `(,entry . "music"))
                                                       %load-path)))))

;;; youtube-build ends here
