profile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env guile
  2. !#
  3. ;;; profile.scm --- Populate my Guix profiles
  4. ;; Copyright © 2015, 2016 Alex Kost
  5. ;; Author: Alex Kost <alezost@gmail.com>
  6. ;; Created: 30 Nov 2015
  7. ;; This program is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; This program is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Just a little script to reduce writing for populating my Guix
  19. ;; profiles using manifest files.
  20. ;;
  21. ;; My Guix config: <https://gitlab.com/alezost-config/guix>.
  22. ;;; Code:
  23. (use-modules
  24. (ice-9 format)
  25. (ice-9 ftw)
  26. (ice-9 match)
  27. (ice-9 regex)
  28. (srfi srfi-1)
  29. (srfi srfi-26)
  30. (al files)
  31. (al places))
  32. (define (show-help)
  33. (format #t "Usage: ~a [OPTION] NAME [ARGS ...]
  34. Populate profile with manifest file using the following command:
  35. guix package --profile='~a' --manifest='~a' ARGS ..."
  36. (car (command-line))
  37. (guix-profile "NAME")
  38. (guix-manifest-file "NAME"))
  39. (display "
  40. NAME may also be 'all' which means populate profiles with all available
  41. manifests.
  42. Options:
  43. -h, --help display this help and exit
  44. -l, --list list available NAMEs and exit")
  45. (newline))
  46. (define (names)
  47. "Return a list of available profile names."
  48. (let ((file-names (scandir (guix-manifest-file)))
  49. (rx (make-regexp "\\`manifest-(.*)\\.scm\\'")))
  50. (filter-map (lambda (file-name)
  51. (and=> (regexp-exec rx file-name)
  52. (cut match:substring <> 1)))
  53. file-names)))
  54. (define (display-names names)
  55. (display "Available profile names:\n")
  56. (format #t "~{~a~%~}" (sort names string-ci<)))
  57. (define (make-profile-directory-maybe profile)
  58. "Create PROFILE's directory if it does not exist.
  59. PROFILE itself is a symlink, so make all its parent directories."
  60. (let ((parent (parent-directory profile)))
  61. (unless (file-exists? parent)
  62. (mkdir-with-parents parent))))
  63. (define (populate-profile name . rest-args)
  64. (let ((profile (guix-profile name))
  65. (manifest (guix-manifest-file name)))
  66. (make-profile-directory-maybe profile)
  67. (if (file-exists? manifest)
  68. (apply system*
  69. "guix" "package"
  70. (string-append "--profile=" profile)
  71. (string-append "--manifest=" manifest)
  72. rest-args)
  73. (format (current-error-port)
  74. "Manifest file '~a' does not exist~%"
  75. manifest))))
  76. (define (main args)
  77. (match (cdr args)
  78. (((or "-h" "--help" "help") _ ...)
  79. (show-help))
  80. (((or "-l" "--list" "list") _ ...)
  81. (display-names (names)))
  82. (("all" rest-args ...)
  83. (map (lambda (name)
  84. (apply populate-profile name rest-args))
  85. (names)))
  86. ((name rest-args ...)
  87. (apply populate-profile name rest-args))
  88. (_ (show-help))))
  89. (when (batch-mode?)
  90. (main (command-line)))
  91. ;;; profile.scm ends here