This page discusses the guidelines for writing an Artanis application such as LIMS*Nucleus that is suitable for Guix packaging. If you are looking for modifications needed in the Artanis source code, look here.
Write a Guix packageable Artanis application
First read the discussion on modifications required to the Artanis source code so you are aware that all temporary files created by your application must be moved to a directory outside the application directory. In addition, Artanis’ cache must be move outside the application directory, as well as artanis.conf so it remains editable. These activities can be handled with a post installation initialization file.
One time initialization
Because your artanis app needs some directories outside of the application directory to work with temporary files, configuration files etc., a one time initialization script can be run to set up your server. The overall process would look like:
- guix package -i limsn
- init-limsn.sh
- install-pg-aws.sh
- start-limsn.sh
The initialization file would create required directories and copy over the artanis.conf file. Note that the placeholder PATH_INTO_STORE is replaced on installation by the path into the store.
1 |
|
artanis.conf
Because a configuration file outside the project directory is being used, you can use a startup script to launch your application:
1 |
|
In this example -h0.0.0.0 is needed for running on Amazon Web Services
GNUPLOT
With regular Artanis Gnuplot can be run on the server and generate *.png files in the ../pub directory that are accessible to the .html.tpl file via:
1 | <image src= <%= myplot %>> |
Where in the above snippet the variable myplot == “../pub/myplot.png”. With guix modified Artanis, the .png file would have to go into /tmp/limsn and would become inaccessible due to security restrictions. To get around this, load the myplot variable with svg commands. This is accomplished by first creating the gnuplot script with the following commands:
1 | reset session |
The ‘save’-’’ statement will save to standard output so that you can pipe into your variable. Here is a helper function that will collect the svg commands:
1 | (use-modules (ice-9 regex) ;;list-matches |
Then in your controller:
1 | (let* ((myplot-svg (get-svg-content gnuplot-script-file)) |
And in the web page template: 1
<%= myplot-svg %>
Now in the above snippet myplot-svg == ’<svg width=“600” height=“350” viewBox=“0 0 600 350” xmlns=“http://www.w3.org/2000/svg” xmlns:xlink=“http://www…etc….”
Application specific variables
Application specific variables are defined in ENTRY such as:
1
2
3...
(conf-set! 'maxnumplates 100)
...
Since ENTRY is in the store, this will only work for variables that are not available to the end user for (re)setting. To provide editable application specific variables, put them in artanis.conf. Variables are grouped in artanis.conf. LIMS*Nucleus specific variable ‘maxnumplates’ is placed in the ‘cookie’ group for convenience, even though it is not a cookie.
1 | cookie.maxnumplates = 100 |
artanis/config.scm must be patched appropriately: 1
2
3
4
5
6
7
8(substitute* "artanis/config.scm"
((" \\(else \\(error parse-namespace-cache \"Config: Invalid item\" item\\)\\)\\)\\)")
"(else (error parse-namespace-cache \"Config: Invalid item\" item))))\n\n(define (parse-namespace-cookie item)\n (match item\n (('expire expire) (conf-set! '(cookie expire) (->integer expire)))\n (('maxplates maxplates) (conf-set! '(cookie maxplates) (->integer maxplates)))\n (else (error parse-namespace-cookie \"Config: Invalid item\" item))))"))
(substitute* "artanis/config.scm"
(("debug.monitor = <PATHs>\")")
"debug.monitor = <PATHs>\")\n ((cookie expire)\n 3600\n \"Cookie expiration time in seconds.\n 1 hour is 3600\n 6 hours 21600\n 1 month 2592000\n cookie.expire = <integer>\")\n\n ((cookie maxplates)\n 10\n \"Maximum number of plates per plate-set.\n cookie.maxplates = <integer>\")"))
Modify controller syntax
Controllers as they are written will generate a warning:
guix package: warning: failed to load ‘(limsn app controllers
plates)’: no code for module (lims app controllers plates)
/home/mbc/.guix-profile/share/guile/site/3.0/myapp/app/controllers/pages.scm:4:0:
warning: module name (app controllers plates) does not match file name
‘limsn/app/controllers/plates.scm’ hint: File
`/home/mbc/.guix-profile/share/guile/site/3.0/limsn/app/controllers/plates.scm’
should probably start with: (define-module (limsn app controllers
plates))
Guix expects the first statement in a module to
begin with (define-module (
Artanis wants modules
to (use-modules (artanis mvc controller))
Satisfy both requirements
with:
1 | (define-module (limsn app controllers plates) |
Be sure to import libraries after (define-artanis-controller
Make Libraries accessible
Artanis provides the ….
(add-to-load-path (string-append (find-ENTRY-path identity #t) “/..”))
Another option is to create a separate package for your library, package separately, and make it available as an input.