system 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env guile
  2. !#
  3. ;;; system.scm --- Check, build or reconfigure Guix system
  4. ;; Copyright © 2015–2017 Alex Kost
  5. ;; Author: Alex Kost <alezost@gmail.com>
  6. ;; Created: 13 Jun 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. ;;
  12. ;; This program is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;;
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;; Just a little script to reduce writing for building/reconfiguring my
  21. ;; Guix system.
  22. ;;
  23. ;; My Guix config: <https://gitlab.com/alezost-config/guix>.
  24. ;;; Code:
  25. (use-modules
  26. (ice-9 match)
  27. (ice-9 regex)
  28. (al places))
  29. (define %config (guix-system-file "main"))
  30. (define (show-help)
  31. (format #t "Usage: ~a ACTION [ARGS ...]
  32. Check, build or reconfigure Guix system using the following config file:
  33. ~a"
  34. (car (command-line)) %config)
  35. (display "\n
  36. ARGS are the rest arguments that are passed to the according command.
  37. Actions:
  38. c(heck) run 'guild compile' with some warning flags;
  39. b(uild) run 'guix system build';
  40. r(econfigure) run 'guix system reconfigure'.")
  41. (newline))
  42. (define (action->command action . rest-args)
  43. "Return a list with command and its arguments to perform ACTION.
  44. Return #f if ACTION is unknown."
  45. (define (action? real-action)
  46. (string-match (string-append "\\`" action)
  47. real-action))
  48. (cond
  49. ((action? "check")
  50. `("guild" "compile"
  51. "-Wunbound-variable" "-Wunused-variable" "-Wunused-toplevel"
  52. ,@rest-args ,%config))
  53. ((action? "build")
  54. `("guix" "system" "build" "--no-bootloader" ,@rest-args ,%config))
  55. ((action? "reconfigure")
  56. `("sudo" "--preserve-env"
  57. "guix" "system" "reconfigure" "--no-bootloader" ,@rest-args ,%config))
  58. (else #f)))
  59. (define (main args)
  60. (match (cdr args)
  61. ((action rest-args ...)
  62. (let ((cmd (apply action->command action rest-args)))
  63. (if cmd
  64. (apply system* cmd)
  65. (show-help))))
  66. (_ (show-help))))
  67. (when (batch-mode?)
  68. (main (command-line)))
  69. ;;; system.scm ends here