[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/02: hydra: Add (sysadmin web) module.
From: |
Ludovic Courtès |
Subject: |
02/02: hydra: Add (sysadmin web) module. |
Date: |
Thu, 4 Jul 2019 09:00:46 -0400 (EDT) |
civodul pushed a commit to branch master
in repository maintenance.
commit abe479d057ef957f08b399947d1dd60cb7a2fa9c
Author: Ludovic Courtès <address@hidden>
Date: Thu Jul 4 15:00:28 2019 +0200
hydra: Add (sysadmin web) module.
* hydra/modules/sysadmin/web.scm: New file.
---
hydra/modules/sysadmin/web.scm | 65 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/hydra/modules/sysadmin/web.scm b/hydra/modules/sysadmin/web.scm
new file mode 100644
index 0000000..9ca53a4
--- /dev/null
+++ b/hydra/modules/sysadmin/web.scm
@@ -0,0 +1,65 @@
+;;; GNU Guix system administration tools.
+;;;
+;;; Copyright © 2019 Ludovic Courtès <address@hidden>
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (sysadmin web)
+ #:use-module (guix git)
+ #:use-module (guix packages)
+ #:use-module (gnu packages)
+ #:use-module (ice-9 match)
+ #:export (build-program))
+
+(define guix-extensions
+ (match (package-transitive-propagated-inputs
+ (specification->package "guix"))
+ (((labels packages) ...)
+ (cons (specification->package "guix") packages))))
+
+(define (build-program url root)
+ "Return a program that pulls code from URL, builds it using its 'guix.scm'
+file, and registers the result as ROOT (an indirect GC root) upon success.
+
+The typical use case is polling from the source repository of a web site
+that's built with Haunt or similar."
+ (define build
+ (with-extensions guix-extensions
+ #~(begin
+ (use-modules (guix) (guix git) (guix ui)
+ (srfi srfi-11))
+
+ (define (root-installed drv root)
+ (mbegin %store-monad
+ ((store-lift add-indirect-root) root)
+ (let ((pivot (string-append root ".tmp")))
+ (symlink (derivation->output-path drv) pivot)
+ (rename-file pivot root)
+ (return #t))))
+
+ (define-values (checkout commit)
+ (update-cached-checkout #$url))
+
+ (define obj
+ (primitive-load (string-append checkout "/guix.scm")))
+
+ (with-store store
+ (run-with-store store
+ (mlet %store-monad ((drv (lower-object obj)))
+ (mbegin %store-monad
+ (show-what-to-build* (list drv))
+ (built-derivations (list drv))
+ (root-installed drv #$root))))))))
+
+ (program-file "build-program" build))