executable_jenkins-nix-version 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/run/current-system/profile/bin/guile \
  2. --no-auto-compile -e (jenkins-nix-version) -s
  3. !#
  4. ;;;; nixos --- SYNOPSIS
  5. ;;;; Copyright © 2020, 2022 Oleg Pykhalov <go.wigust@gmail.com>
  6. ;;;; Released under the GNU GPLv3 or any later version.
  7. (define-module (jenkins-nix-version)
  8. #:use-module (srfi srfi-1)
  9. #:use-module (srfi srfi-37)
  10. #:use-module (ice-9 popen)
  11. #:use-module (ice-9 rdelim)
  12. #:use-module (ice-9 regex)
  13. #:export (main))
  14. ;;; Commentary:
  15. ;;;
  16. ;;; DESCRIPTION
  17. ;;;
  18. ;;; Code:
  19. (define %options
  20. (let ((display-and-exit-proc (lambda (msg)
  21. (lambda (opt name arg loads)
  22. (display msg) (quit)))))
  23. (list (option '(#\c "commit") #f #t
  24. (lambda (opt name arg loads)
  25. (alist-cons 'commit arg loads)))
  26. (option '(#\o "no-overlays") #f #f
  27. (lambda (opt name arg result . rest)
  28. (apply values
  29. (alist-cons 'overlay? #f
  30. (alist-delete 'overlay? result eq?))
  31. rest)))
  32. (option '(#\v "version") #f #f
  33. (display-and-exit-proc "nixos version 0.0.1\n"))
  34. (option '(#\h "help") #f #f
  35. (display-and-exit-proc
  36. "Usage: nixos ...")))))
  37. (define %default-options
  38. '((overlay? . #t)))
  39. (define (system->string prog args)
  40. (let* ((port (apply open-pipe* OPEN_READ prog args))
  41. (output (read-string port)))
  42. (close-pipe port)
  43. output))
  44. (define (main args)
  45. (define opts
  46. (args-fold (cdr (program-arguments))
  47. %options
  48. (lambda (opt name arg loads)
  49. (error "Unrecognized option `~A'" name))
  50. (lambda (op loads)
  51. (cons op loads))
  52. %default-options))
  53. (define nix-commit
  54. (or (assoc-ref opts 'commit)
  55. (last (string-split (match:substring
  56. (regexp-exec (make-regexp "([[:digit:]]*\\.[[:digit:]]*\\.[[:digit:]]*\\.[[:alnum:]]*)")
  57. (system->string "ssh"
  58. '("jenkins.intr"
  59. "--"
  60. "nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'"))))
  61. #\.))))
  62. (define nix-expression
  63. (format #f "\
  64. with (import (builtins.fetchTarball {
  65. url = \"https://github.com/nixos/nixpkgs/archive/~a.tar.gz\";
  66. }) {
  67. overlays = [
  68. ~a
  69. ];
  70. }); ~a" nix-commit
  71. (if (assoc-ref opts 'overlay?) "(import /home/oleg/src/gitlab.intr/_ci/nixpkgs)" "")
  72. (car opts)))
  73. (define nix-command
  74. (list "nix-build"
  75. "--no-out-link"
  76. "--option" "trusted-public-keys"
  77. (format #f "~s"
  78. (string-join (list "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
  79. "cache.nixos.intr:6VD7bofl5zZFTEwsIDsUypprsgl7r9I+7OGY4WsubFA=")))
  80. "--option" "builders" (format #f "~s" "ssh://nixos.intr x86_64-linux")
  81. "--arg" "debug" "true"
  82. "--substituters"
  83. (format #f "~s"
  84. (string-join (list "https://cache.nixos.org/"
  85. "https://cache.nixos.intr/")))
  86. "--expr"
  87. (format #f "~s"
  88. (string-join
  89. (map string-trim
  90. (string-split nix-expression
  91. #\newline))))))
  92. (with-output-to-port (current-error-port)
  93. (lambda ()
  94. (format #t "Invoking:~%~a~%" (string-join nix-command))))
  95. (system (string-join nix-command)))
  96. ;;; nixos ends here