Compare commits

...

3 Commits

5 changed files with 88 additions and 58 deletions

2
.gitignore vendored
View File

@ -70,3 +70,5 @@ tmp
/Makefile.am
/ChangeLog
/AUTHORS
/scripts/guix-cantrips
/.envrc

View File

@ -14,14 +14,16 @@
#:use-module (gnu packages texinfo))
(define vcs-file?
(or (git-predicate (current-source-directory))
(or (git-predicate "../..")
(const #t)))
(define-public guix-cantrips
(package
(name "guix-cantrips")
(version "0.1-src")
(source (local-file "../.." "guix-cantrips" #:recursive? #t))
(source (local-file "../.." "guix-cantrips"
#:recursive? #t
#:select? vcs-file?))
(build-system gnu-build-system)
(arguments
(list

View File

@ -1 +1,40 @@
(define-module (guix-cantrips summon))
(define-module (guix-cantrips summon)
#:use-module (config)
#:use-module (ice-9 ftw)
#:use-module (ice-9 match)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 regex)
#:use-module (os process)
#:export (summon))
(define (summon opts)
"Options -> Void
Downloads the source code of a package and extracts it to a directory"
(define proj-dir (option-ref opts 'project-dir))
(define package-name (option-ref opts '(package)))
(define (tarball? filename)
(string-match ".*[.]tar[.](gz|xz)$" filename))
(define (untar! tarball destination)
(run "tar" (format #f "--directory=~a" destination) "-xf" tarball))
(define (zip? filename)
(string-match ".*[.]zip$"))
(let* ((package-build-out (run-with-pipe "r" "guix" "build" "--source" package-name))
(package-source-dir (read-line (cdr package-build-out))))
(cond
((tarball? package-source-dir)
(untar! package-source-dir proj-dir)
(format #t "Package ~a extracted to ~a~&" package-source-dir proj-dir))
((zip? package-source-dir) (format #t "Zip!: ~a" package-source-dir))
((directory-exists? package-source-dir) (format #t "I think this is a directory: ~a" package-source-dir))
(else (format #t "I dunno what this is: ~a" package-source-dir)))))
; If file
;; If *.tar.[gr/xz/bz] then decompress to project directory
;; If .zip then above but different program to decompress is used
; If directory
;; Recursively copy dir to project directory
;; After, chmod everything to be writable

View File

@ -12,7 +12,7 @@
(dependencies
`(("guile-git" ,guile-git)
("guile-config" ,guile-config)))
(skip ())
(skip (".envrc"))
(files (libraries
((directory
"guix-cantrips"

View File

@ -8,6 +8,7 @@
(config api)
(config licenses)
(config parser sexp)
(guix-cantrips summon)
(ice-9 exceptions)
(ice-9 match)
(srfi srfi-26))
@ -15,59 +16,45 @@
;; Commandline handling
(define %configuration
(let* ((csv-test (match-lambda (((? string?) ...) #t)
(_ #f)))
(csv-test-allow-empty (λ (a)
(or (csv-test a)
(string=? a ""))))
(csv-handler (cut string-split <> #\,))
(manifest-exists?
(λ (path opts)
(file-exists? (format #f "~a/~a"
(option-ref opts 'config-dir)
path)))))
(configuration
(name 'guix-cantrips)
(version @HVERSION@)
(author @AUTHOR@)
(copyright @COPYRIGHT@)
(license @LICENSE@)
(synopsis "Utilities and modules to make guix even more magical")
(description "guix-cantrips provides function to quickly get source code from packages and set the repo up to get going FAST")
(keywords
(list
(setting (name 'project-dir)
(default (format #f "~a/src"
(getenv "HOME")))
(test file-exists?)
(handler canonicalize-path)
(synopsis "Directory to download source code to")
(example "~/src"))
(setting (name 'config-dir)
(default (or (getenv "XDG_CONFIG_HOME")
(format #f "~a/.config" (getenv "HOME"))))
(test file-exists?)
(handler canonicalize-path)
(synopsis "Directory to search for profile manifests")
(example "~/.config/guix-conjure"))))
(subcommands
(list
(configuration
(name 'summon)
(synopsis "Retrieves the source code of a package, and places it within the project directory, while configuring all permissions.")
(description
"Uses guix build --source to obtain a package's source code, decompressing if required, and places the resulting source in the project directory.")
(wanted '((keywords project-dir)))
(arguments
(list
(argument (name 'package)
(test csv-test)
(handler csv-handler)
(synopsis "name of the package to download the source of")
(example "guix")))))))
(directory (in-home ".config/"))
(parser simple-sexp-parser)
(generate-cmdtree? #t))))
(configuration
(name 'guix-cantrips)
(version @HVERSION@)
(author @AUTHOR@)
(copyright @COPYRIGHT@)
(license @LICENSE@)
(synopsis "Utilities and modules to make guix even more magical")
(description "guix-cantrips provides function to quickly get source code from packages and set the repo up to get going FAST")
(keywords
(list
(setting (name 'project-dir)
(default (format #f "~a/src"
(getenv "HOME")))
(handler canonicalize-path)
(synopsis "Directory to download source code to")
(example "~/src"))
(setting (name 'config-dir)
(default (or (getenv "XDG_CONFIG_HOME")
(format #f "~a/.config" (getenv "HOME"))))
(test file-exists?)
(handler canonicalize-path)
(synopsis "Directory to search for profile manifests")
(example "~/.config/guix-conjure"))))
(subcommands
(list
(configuration
(name 'summon)
(synopsis "Retrieves the source code of a package, and places it within the project directory, while configuring all permissions.")
(description
"Uses guix build --source to obtain a package's source code, decompressing if required, and places the resulting source in the project directory.")
(wanted '((keywords project-dir)))
(arguments
(list
(argument (name 'package)
(synopsis "name of the package to download the source of")
(example "hello")))))))
(directory (in-home ".config/"))
(parser simple-sexp-parser)
(generate-cmdtree? #t)))
(define (main args)
"(Listof String) -> Int
@ -75,7 +62,7 @@ program entrypoint; handle commandline args and call appropriate procedures"
(define options (getopt-config-auto args %configuration))
(match (full-command options)
((_ "summon")
((λ (options) ()) options))))
(summon options))))
;;; Local Variables: