You've already forked guix-tribes
280 lines
12 KiB
Scheme
280 lines
12 KiB
Scheme
(define-module (tribes packages mix)
|
|
#:use-module (guix base32)
|
|
#:use-module (guix build-system trivial)
|
|
#:use-module (guix gexp)
|
|
#:use-module (guix packages)
|
|
#:use-module (guix utils)
|
|
#:use-module (gnu packages admin)
|
|
#:use-module (gnu packages bash)
|
|
#:use-module (gnu packages base)
|
|
#:use-module (gnu packages erlang)
|
|
#:use-module (gnu packages nss)
|
|
#:use-module (gnu packages version-control)
|
|
#:use-module (tribes packages otp)
|
|
#:export (fetch-mix-deps
|
|
mix-release-package))
|
|
|
|
(define* (fetch-mix-deps source
|
|
#:key
|
|
(name "mix-deps")
|
|
version
|
|
sha256
|
|
(mix-env "prod")
|
|
(mix-target "host"))
|
|
"Return a fixed-output store item that vendors the Mix dependency tree for
|
|
SOURCE according to mix.lock."
|
|
(computed-file
|
|
(string-append name "-" version)
|
|
(with-imported-modules '((guix build utils))
|
|
#~(begin
|
|
(use-modules (guix build utils))
|
|
|
|
(define out #$output)
|
|
(define work (string-append (getcwd) "/build"))
|
|
(define app-dir (string-append work "/app"))
|
|
(define deps-dir (string-append work "/deps"))
|
|
(define certs-dir
|
|
#$(file-append nss-certs "/etc/ssl/certs"))
|
|
(define cert-file
|
|
(string-append work "/ca-certificates.crt"))
|
|
(define path
|
|
(string-join
|
|
(list #$(file-append elixir-otp28 "/bin")
|
|
#$(file-append elixir-hex-otp28 "/bin")
|
|
#$(file-append rebar3 "/bin")
|
|
#$(file-append bash-minimal "/bin")
|
|
#$(file-append coreutils "/bin")
|
|
#$(file-append findutils "/bin")
|
|
#$(file-append git-minimal "/bin")
|
|
(or (getenv "PATH") ""))
|
|
":"))
|
|
|
|
(mkdir-p work)
|
|
(copy-recursively #+source app-dir #:follow-symlinks? #t)
|
|
(invoke #$(file-append coreutils "/bin/chmod") "-R" "u+w" app-dir)
|
|
(invoke #$(file-append bash-minimal "/bin/sh")
|
|
"-c"
|
|
(string-append
|
|
#$(file-append coreutils "/bin/cat")
|
|
" "
|
|
certs-dir
|
|
"/*.pem > "
|
|
cert-file))
|
|
|
|
(setenv "PATH" path)
|
|
(setenv "HOME" (string-append work "/home"))
|
|
(setenv "MIX_HOME" (string-append work "/mix"))
|
|
(setenv "HEX_HOME" (string-append work "/hex"))
|
|
(setenv "MIX_DEPS_PATH" deps-dir)
|
|
(setenv "MIX_ENV" #$mix-env)
|
|
(setenv "MIX_TARGET" #$mix-target)
|
|
(setenv "MIX_OS_CONCURRENCY_LOCK" "0")
|
|
(setenv "MIX_REBAR3" #$(file-append rebar3 "/bin/rebar3"))
|
|
(setenv "REBAR_GLOBAL_CONFIG_DIR" (string-append work "/rebar3"))
|
|
(setenv "REBAR_CACHE_DIR" (string-append work "/rebar3.cache"))
|
|
(setenv "LANG" "C.UTF-8")
|
|
(setenv "LC_CTYPE" "C.UTF-8")
|
|
(setenv "ELIXIR_ERL_OPTIONS" "+fnu")
|
|
(setenv "SSL_CERT_DIR" certs-dir)
|
|
(setenv "SSL_CERT_FILE" cert-file)
|
|
(setenv "HEX_CACERTS_PATH" cert-file)
|
|
(setenv "HEX_HTTP_CONCURRENCY" "1")
|
|
(setenv "HEX_HTTP_TIMEOUT" "120")
|
|
(mkdir-p (getenv "HOME"))
|
|
(mkdir-p (getenv "MIX_HOME"))
|
|
(mkdir-p (getenv "HEX_HOME"))
|
|
|
|
(with-directory-excursion app-dir
|
|
(invoke "mix" "deps.get" "--only" #$mix-env))
|
|
|
|
(mkdir-p out)
|
|
(copy-recursively deps-dir out #:follow-symlinks? #t)
|
|
;; Match nixpkgs fetchMixDeps behavior for SCM deps: keep .git/HEAD so
|
|
;; Mix still considers the checkout available, but discard the rest of
|
|
;; the repository metadata from the fixed-output tree.
|
|
(invoke #$(file-append findutils "/bin/find")
|
|
out
|
|
"-path" "*/.git/*"
|
|
"-a" "!" "-name" "HEAD"
|
|
"-exec"
|
|
#$(file-append coreutils "/bin/rm") "-rf"
|
|
"{}"
|
|
"+")))
|
|
#:options
|
|
`(#:hash ,(base32 sha256)
|
|
#:hash-algo sha256
|
|
#:recursive? #t
|
|
#:leaked-env-vars ("http_proxy" "https_proxy"
|
|
"LC_ALL" "LC_MESSAGES" "LANG" "COLUMNS"))))
|
|
|
|
(define* (mix-release-package source
|
|
#:key
|
|
mix-fod-deps
|
|
name
|
|
version
|
|
home-page
|
|
synopsis
|
|
description
|
|
license
|
|
(native-inputs '())
|
|
(inputs '())
|
|
(path-inputs '())
|
|
(aclocal-inputs '())
|
|
(mix-env "prod")
|
|
(mix-target "host")
|
|
(compile-flags '())
|
|
(mix-release-name "")
|
|
(remove-cookie? #t)
|
|
(setup-gexp #~(begin))
|
|
(configure-gexp #f)
|
|
(build-gexp #f)
|
|
(install-gexp #f))
|
|
"Return a package that builds SOURCE as an offline Mix release using
|
|
MIX-FOD-DEPS as a pre-fetched dependency tree."
|
|
(let* ((extra-path-dirs (map (lambda (input)
|
|
(file-append input "/bin"))
|
|
path-inputs))
|
|
(aclocal-dirs (map (lambda (input)
|
|
(file-append input "/share/aclocal"))
|
|
aclocal-inputs))
|
|
(default-configure-gexp
|
|
#~(invoke "mix" "deps.compile" "--no-deps-check"
|
|
"--skip-umbrella-children"))
|
|
(default-build-gexp
|
|
#~(invoke "mix" "compile" "--no-deps-check" #$@compile-flags))
|
|
(default-install-gexp
|
|
(if (string=? mix-release-name "")
|
|
#~(invoke "mix" "release" "--no-deps-check" "--path" out)
|
|
#~(invoke "mix" "release" #$mix-release-name
|
|
"--no-deps-check" "--path" out)))
|
|
(configure-gexp (or configure-gexp default-configure-gexp))
|
|
(build-gexp (or build-gexp default-build-gexp))
|
|
(install-gexp (or install-gexp default-install-gexp))
|
|
(builder-gexp
|
|
#~(begin
|
|
(use-modules (guix build utils))
|
|
|
|
(define out #$output)
|
|
(define work (string-append (getcwd) "/build"))
|
|
(define app-dir (string-append work "/app"))
|
|
(define deps-dir (string-append app-dir "/deps"))
|
|
(define certs-dir
|
|
#$(file-append nss-certs "/etc/ssl/certs"))
|
|
(define cert-file
|
|
(string-append work "/ca-certificates.crt"))
|
|
(define hex-lib-dir
|
|
#$(file-append elixir-hex-otp28
|
|
"/lib/elixir/"
|
|
(version-major+minor
|
|
(package-version elixir-otp28))))
|
|
(define aclocal-path
|
|
(string-join (list #$@aclocal-dirs) ":"))
|
|
(define path
|
|
(string-join
|
|
(list #$(file-append elixir-otp28 "/bin")
|
|
#$(file-append elixir-hex-otp28 "/bin")
|
|
#$(file-append rebar3 "/bin")
|
|
#$(file-append bash-minimal "/bin")
|
|
#$(file-append coreutils "/bin")
|
|
#$(file-append findutils "/bin")
|
|
#$(file-append git-minimal "/bin")
|
|
#$@extra-path-dirs
|
|
(or (getenv "PATH") ""))
|
|
":"))
|
|
|
|
(mkdir-p work)
|
|
(copy-recursively #+source app-dir #:follow-symlinks? #t)
|
|
(invoke #$(file-append coreutils "/bin/chmod") "-R" "u+w" app-dir)
|
|
#$@(if mix-fod-deps
|
|
(list
|
|
#~(begin
|
|
(copy-recursively #+mix-fod-deps deps-dir
|
|
#:follow-symlinks? #t)
|
|
(invoke #$(file-append coreutils "/bin/chmod")
|
|
"-R" "u+w" deps-dir)))
|
|
'())
|
|
(invoke #$(file-append bash-minimal "/bin/sh")
|
|
"-c"
|
|
(string-append
|
|
#$(file-append coreutils "/bin/cat")
|
|
" "
|
|
certs-dir
|
|
"/*.pem > "
|
|
cert-file))
|
|
|
|
(setenv "PATH" path)
|
|
(setenv "HOME" (string-append app-dir "/.home"))
|
|
(setenv "MIX_HOME" (string-append app-dir "/.mix-home"))
|
|
(setenv "HEX_HOME" (string-append app-dir "/.hex"))
|
|
(setenv "XDG_CACHE_HOME" (string-append app-dir "/.cache"))
|
|
(setenv "MIX_ENV" #$mix-env)
|
|
(setenv "MIX_TARGET" #$mix-target)
|
|
(setenv "MIX_OS_CONCURRENCY_LOCK" "0")
|
|
(setenv "HEX_OFFLINE" "1")
|
|
(setenv "MIX_REBAR" #$(file-append rebar3 "/bin/rebar3"))
|
|
(setenv "MIX_REBAR3" #$(file-append rebar3 "/bin/rebar3"))
|
|
(setenv "REBAR_GLOBAL_CONFIG_DIR" (string-append work "/rebar3"))
|
|
(setenv "REBAR_CACHE_DIR" (string-append work "/rebar3.cache"))
|
|
(setenv "SHELL" #$(file-append bash-minimal "/bin/sh"))
|
|
(setenv "CONFIG_SHELL" #$(file-append bash-minimal "/bin/sh"))
|
|
(setenv "SSL_CERT_DIR" certs-dir)
|
|
(setenv "SSL_CERT_FILE" cert-file)
|
|
(setenv "HEX_CACERTS_PATH" cert-file)
|
|
(setenv "HEX_HTTP_CONCURRENCY" "1")
|
|
(setenv "HEX_HTTP_TIMEOUT" "120")
|
|
(setenv "LANG" "C.UTF-8")
|
|
(setenv "LC_CTYPE" "C.UTF-8")
|
|
(setenv "ELIXIR_ERL_OPTIONS" "+fnu")
|
|
(when (positive? (string-length aclocal-path))
|
|
(setenv "ACLOCAL_PATH" aclocal-path))
|
|
(let ((existing-elixir-libs (getenv "GUIX_ELIXIR_LIBS")))
|
|
(setenv "GUIX_ELIXIR_LIBS"
|
|
(if existing-elixir-libs
|
|
(string-append hex-lib-dir ":" existing-elixir-libs)
|
|
hex-lib-dir)))
|
|
#$@(if mix-fod-deps
|
|
(list #~(setenv "MIX_DEPS_PATH" deps-dir))
|
|
'())
|
|
(mkdir-p (getenv "HOME"))
|
|
(mkdir-p (getenv "MIX_HOME"))
|
|
(mkdir-p (getenv "HEX_HOME"))
|
|
(mkdir-p (getenv "XDG_CACHE_HOME"))
|
|
|
|
#$setup-gexp
|
|
|
|
(with-directory-excursion app-dir
|
|
#$configure-gexp
|
|
#$build-gexp
|
|
#$install-gexp)
|
|
|
|
(let ((cookie (string-append out "/releases/COOKIE")))
|
|
(when (and #$remove-cookie?
|
|
(file-exists? cookie))
|
|
(delete-file cookie)))))
|
|
(package-arguments
|
|
(list
|
|
#:modules '((guix build utils))
|
|
#:builder builder-gexp)))
|
|
(package
|
|
(name name)
|
|
(version version)
|
|
(source source)
|
|
(build-system trivial-build-system)
|
|
(native-inputs
|
|
(append
|
|
(list bash-minimal
|
|
coreutils
|
|
findutils
|
|
git-minimal
|
|
nss-certs
|
|
rebar3
|
|
elixir-otp28
|
|
elixir-hex-otp28)
|
|
native-inputs))
|
|
(inputs inputs)
|
|
(arguments package-arguments)
|
|
(home-page home-page)
|
|
(synopsis synopsis)
|
|
(description description)
|
|
(license license))))
|