projects.xml and declarative-projects.xml were merged with xmllint, and then I ran that to convert files for i in *.xml; do pandoc -s -f docbook -t markdown $i -o ${i/xml/md}; done
3JXCTKEC3EXJZHWSVRZMUHYH6HGDHKQUTPHDVJ4LACRMXBNLCEIAC GCYZUWR5SHKR7BHOB3GWO4UBG35OUYZZCD3ZLXQEFFDLFK5Q5YAAC GN345X5J7DGI5UEELNCNKJON3RN2SC4DWYDQGLYNMH46HEUJMY4AC NL5Q432BDGTTLXESZ5YCJRKHJNACNEJNTIP7B73HWNWVIAYSMS2AC ME5HLRWOE6IJAT45QWEAO5DKL3CFJO4ABZVV7G3M4NOQIVVZNYIAC WFJGOVMJBCS4NLRBK7JI6WYQ2RM5IRJE6LDG42JHPWJWCVPSZ4ZAC FV2M6MOTAP4BJMEKU5XUDVEACWEJGEIRCCE2MRY3F6SF2SFOE3MQC PKE6I67S7TDGKEFCKIQZOZ5PSDZXCSPOQGSKDAE5NST3NOOLRUXAC PD4VHG3KAUMXTQPTKJGQECNKWR4EGWG4XXK7JDKE5DU2EJEHS6JQC V4OIX3FIYPAWJAQZGGCFCXSOUKNC7K4M25KCDZU2ITMCVG4NKQ7QC 6U6KBFYPWI2WJPZFEK6W4RN5JSRKFCBEPMKHDYEPGOROC5EWI2EAC FVMVRIRRI2HXFXC46B66L5R5P2RRF3ZAWJD3OJJYVSRCPC24YB6AC X7IAG7JTV4W6JH34JBC6KOVUGBAG643V4Y5MX4GTJL2BV5PP5VIQC 6A6CZ7SC2VGEGRC5LSNTDDM3LFWVYO6Z6QNDF74SBJWO5P6T3ARQC 7HFOCQ2HMWFMHEQEH673QALNMDWCTAGA4X3DMUTL23ZIDX2BV5KQC RWNXH3H26EQHKJNMP4DUJCJKUYQBMV347234ZLE26SIFTVLSUWXQC DOCBOOK_FILES = installation.xml introduction.xml manual.xml projects.xml hacking.xmlEXTRA_DIST = $(DOCBOOK_FILES)xsltproc_opts = \--param callout.graphics.extension \'.gif\' \--param section.autolabel 1 \--param section.label.includes.component.label 1
MD_FILES = src/*.md
# Embed Docbook's callout images in the distribution.EXTRA_DIST += imagesmanual.html: $(DOCBOOK_FILES)$(XSLTPROC) $(xsltproc_opts) --nonet --xinclude \--output manual.html \$(docbookxsl)/xhtml/docbook.xsl manual.xmlimages:$(MKDIR_P) images/calloutscp $(docbookxsl)/images/callouts/*.gif images/calloutschmod +wx images images/calloutsinstall-data-hook: images$(INSTALL) -d $(DESTDIR)$(htmldir)/images/callouts$(INSTALL_DATA) images/callouts/* $(DESTDIR)$(htmldir)/images/calloutsln -sfn manual.html $(DESTDIR)$(htmldir)/index.htmldistclean-hook:-rm -rf images
install: $(MD_FILES)mdbook build . -d $(docdir)
# Hydra User's Guide- [Introduction](introduction.md)- [Installation](installation.md)- [Creating and Managing Projects](projects.md)- [Using the external API](api.md)-----------[About](about.md)[Hacking](hacking.md)
# Authors* Eelco Dolstra, Delft University of Technology, Department of Software Technology* Rob Vermaas, Delft University of Technology, Department of Software Technology* Eelco Visser, Delft University of Technology, Department of Software Technology* Ludovic Courtès
Using the external API======================To be able to create integrations with other services, Hydra exposes anexternal API that you can manage projects with.The API is accessed over HTTP(s) where all data is sent and received asJSON.Creating resources requires the caller to be authenticated, whileretrieving resources does not.The API does not have a separate URL structure for it\'s endpoints.Instead you request the pages of the web interface as `application/json`to use the API.List projects-------------To list all the `projects` of the Hydra install:GET /Accept: application/jsonThis will give you a list of `projects`, where each `project` containsgeneral information and a list of its `job sets`.**Example**curl -i -H 'Accept: application/json' \https://hydra.nixos.org**Note:** this response is truncatedGET https://hydra.nixos.org/HTTP/1.1 200 OKContent-Type: application/json[{"displayname": "Acoda","name": "acoda","description": "Acoda is a tool set for automatic data migration along an evolving data model","enabled": 0,"owner": "sander","hidden": 1,"jobsets": ["trunk"]},{"displayname": "cabal2nix","name": "cabal2nix","description": "Convert Cabal files into Nix build instructions","enabled": 0,"owner": "simons@cryp.to","hidden": 1,"jobsets": ["master"]}]Get a single project--------------------To get a single `project` by identifier:GET /project/:project-identifierAccept: application/json**Example**curl -i -H 'Accept: application/json' \https://hydra.nixos.org/project/hydraGET https://hydra.nixos.org/project/hydraHTTP/1.1 200 OKContent-Type: application/json{"description": "Hydra, the Nix-based continuous build system","hidden": 0,"displayname": "Hydra","jobsets": ["hydra-master","hydra-ant-logger-trunk","master","build-ng"],"name": "hydra","enabled": 1,"owner": "eelco"}Get a single job set--------------------To get a single `job set` by identifier:GET /jobset/:project-identifier/:jobset-identifierContent-Type: application/json**Example**curl -i -H 'Accept: application/json' \https://hydra.nixos.org/jobset/hydra/build-ngGET https://hydra.nixos.org/jobset/hydra/build-ngHTTP/1.1 200 OKContent-Type: application/json{"errormsg": "evaluation failed due to signal 9 (Killed)","fetcherrormsg": null,"nixexprpath": "release.nix","nixexprinput": "hydraSrc","emailoverride": "rob.vermaas@gmail.com, eelco.dolstra@logicblox.com","jobsetinputs": {"officialRelease": {"jobsetinputalts": ["false"]},"hydraSrc": {"jobsetinputalts": ["https://github.com/NixOS/hydra.git build-ng"]},"nixpkgs": {"jobsetinputalts": ["https://github.com/NixOS/nixpkgs.git release-14.12"]}},"enabled": 0}List evaluations----------------To list the `evaluations` of a `job set` by identifier:GET /jobset/:project-identifier/:jobset-identifier/evalsContent-Type: application/json**Example**curl -i -H 'Accept: application/json' \https://hydra.nixos.org/jobset/hydra/build-ng/evals**Note:** this response is truncatedGET https://hydra.nixos.org/jobset/hydra/build-ng/evalsHTTP/1.1 200 OKContent-Type: application/json{"evals": [{"jobsetevalinputs": {"nixpkgs": {"dependency": null,"type": "git","value": null,"uri": "https://github.com/NixOS/nixpkgs.git","revision": "f60e48ce81b6f428d072d3c148f6f2e59f1dfd7a"},"hydraSrc": {"dependency": null,"type": "git","value": null,"uri": "https://github.com/NixOS/hydra.git","revision": "48d6f0de2ab94f728d287b9c9670c4d237e7c0f6"},"officialRelease": {"dependency": null,"value": "false","type": "boolean","uri": null,"revision": null}},"hasnewbuilds": 1,"builds": [24670686,24670684,24670685,24670687],"id": 1213758}],"first": "?page=1","last": "?page=1"}Get a single build------------------To get a single `build` by its id:GET /build/:build-idContent-Type: application/json**Example**curl -i -H 'Accept: application/json' \https://hydra.nixos.org/build/24670686GET /build/24670686HTTP/1.1 200 OKContent-Type: application/json{"job": "tests.api.x86_64-linux","jobsetevals": [1213758],"buildstatus": 0,"buildmetrics": null,"project": "hydra","system": "x86_64-linux","priority": 100,"releasename": null,"starttime": 1439402853,"nixname": "vm-test-run-unnamed","timestamp": 1439388618,"id": 24670686,"stoptime": 1439403403,"jobset": "build-ng","buildoutputs": {"out": {"path": "/nix/store/lzrxkjc35mhp8w7r8h82g0ljyizfchma-vm-test-run-unnamed"}},"buildproducts": {"1": {"path": "/nix/store/lzrxkjc35mhp8w7r8h82g0ljyizfchma-vm-test-run-unnamed","defaultpath": "log.html","type": "report","sha256hash": null,"filesize": null,"name": "","subtype": "testlog"}},"finished": 1}
Hacking=======This section provides some notes on how to hack on Hydra. To get thelatest version of Hydra from GitHub:$ git clone git://github.com/NixOS/hydra.git$ cd hydraTo build it and its dependencies:$ nix-build release.nix -A build.x86_64-linuxTo build all dependencies and start a shell in which all environmentvariables (such as PERL5LIB) are set up so that those dependencies canbe found:$ nix-shellTo build Hydra, you should then do:[nix-shell]$ ./bootstrap[nix-shell]$ configurePhase[nix-shell]$ makeYou can run the Hydra web server in your source tree as follows:$ ./src/script/hydra-server
Installation============This chapter explains how to install Hydra on your own build farmserver.Prerequisites-------------To install and use Hydra you need to have installed the followingdependencies:- Nix- PostgreSQL- many Perl packages, notably Catalyst, EmailSender, and NixPerl (seethe [Hydra expression inNixpkgs](https://github.com/NixOS/hydra/blob/master/release.nix) forthe complete list)At the moment, Hydra runs only on GNU/Linux (*i686-linux* and*x86\_64\_linux*).For small projects, Hydra can be run on any reasonably modern machine.For individual projects you can even run Hydra on a laptop. However, thecharm of a buildfarm server is usually that it operates withoutdisturbing the developer\'s working environment and can serve releasesover the internet. In conjunction you should typically have your sourcecode administered in a version management system, such as subversion.Therefore, you will probably want to install a server that is connectedto the internet. To scale up to large and/or many projects, you willneed at least a considerable amount of diskspace to store builds. SinceHydra can schedule multiple simultaneous build jobs, it can be useful tohave a multi-core machine, and/or attach multiple build machines in anetwork to the central Hydra server.Of course we think it is a good idea to use the[NixOS](http://nixos.org/nixos) GNU/Linux distribution for yourbuildfarm server. But this is not a requirement. The Nix softwaredeployment system can be installed on any GNU/Linux distribution inparallel to the regular package management system. Thus, you can useHydra on a Debian, Fedora, SuSE, or Ubuntu system.Getting Nix-----------If your server runs NixOS you are all set to continue with installationof Hydra. Otherwise you first need to install Nix. The latest stableversion can be found one [the Nix website](http://nixos.org/nix/download.html), along with a manual, whichincludes installation instructions.Installation------------The latest development snapshot of Hydra can be installed by visitingthe URL[`http://hydra.nixos.org/view/hydra/unstable`](http://hydra.nixos.org/view/hydra/unstable)and using the one-click install available at one of the build pages. Youcan also install Hydra through the channel by performing the followingcommands:nix-channel --add http://hydra.nixos.org/jobset/hydra/master/channel/latestnix-channel --updatenix-env -i hydraCommand completion should reveal a number of command-line tools fromHydra, such as `hydra-queue-runner`.Creating the database---------------------Hydra stores its results in a PostgreSQL database.To setup a PostgreSQL database with *hydra* as database name and username, issue the following commands on the PostgreSQL server:createuser -S -D -R -P hydracreatedb -O hydra hydraNote that *\$prefix* is the location of Hydra in the nix store.Hydra uses an environment variable to know which database should beused, and a variable which point to a location that holds some state. Toset these variables for a PostgreSQL database, add the following to thefile `~/.profile` of the user running the Hydra services.export HYDRA_DBI="dbi:Pg:dbname=hydra;host=dbserver.example.org;user=hydra;"export HYDRA_DATA=/var/lib/hydraYou can provide the username and password in the file `~/.pgpass`, e.g.dbserver.example.org:*:hydra:hydra:passwordMake sure that the *HYDRA\_DATA* directory exists and is writable forthe user which will run the Hydra services.Having set these environment variables, you can now initialise thedatabase by doing:hydra-initTo create projects, you need to create a user with *admin* privileges.This can be done using the command `hydra-create-user`:$ hydra-create-user alice --full-name 'Alice Q. User' \--email-address 'alice@example.org' --password foobar --role adminAdditional users can be created through the web interface.Upgrading---------If you\'re upgrading Hydra from a previous version, you should do thefollowing to perform any necessary database schema migrations:hydra-initGetting Started---------------To start the Hydra web server, execute:hydra-serverWhen the server is started, you can browse to [http://localhost:3000/]()to start configuring your Hydra instance.The `hydra-server` command launches the web server. There are two otherprocesses that come into play:- Theevaluatoris responsible for periodically evaluating job sets, checking outtheir dependencies off their version control systems (VCS), andqueueing new builds if the result of the evaluation changed. It islaunched by thehydra-evaluatorcommand.- Thequeue runnerlaunches builds (using Nix) as they are queued by the evaluator,scheduling them onto the configured Nix hosts. It is launched usingthehydra-queue-runnercommand.All three processes must be running for Hydra to be fully functional,though it\'s possible to temporarily stop any one of them formaintenance purposes, for instance.Serving behind reverse proxy----------------------------To serve hydra web server behind reverse proxy like *nginx* or *httpd*some additional configuration must be made.Edit your `hydra.conf` file in a similar way to this example:using_frontend_proxy 1base_uri example.com`base_uri` should be your hydra servers proxied URL. If you are usingHydra nixos module then setting `hydraURL` option should be enough.If you want to serve Hydra with a prefix path, for example[http://example.com/hydra]() then you need to configure your reverseproxy to pass `X-Request-Base` to hydra, with prefix path as value. Forexample if you are using nginx, then use configuration similar tofollowing:server {listen 433 ssl;server_name example.com;.. other configuration ..location /hydra/ {proxy_pass http://127.0.0.1:3000;proxy_redirect http://127.0.0.1:3000 https://example.com/hydra;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header X-Request-Base /hydra;}}Using LDAP as authentication backend (optional)-----------------------------------------------Instead of using Hydra\'s built-in user management you can optionallyuse LDAP to manage roles and users.The `hydra-server` accepts the environment variable*HYDRA\_LDAP\_CONFIG*. The value of the variable should point to a validYAML file containing the Catalyst LDAP configuration. The format of theconfiguration file is describe in the[*Catalyst::Authentication::Store::LDAP*documentation](https://metacpan.org/pod/Catalyst::Authentication::Store::LDAP#CONFIGURATION-OPTIONS).An example is given below.Roles can be assigned to users based on their LDAP group membership(*use\_roles: 1* in the below example). For a user to have the role*admin* assigned to them they should be in the group *hydra\_admin*. Ingeneral any LDAP group of the form *hydra\_some\_role* (notice the*hydra\_* prefix) will work.credential:class: Passwordpassword_field: passwordpassword_type: self_checkstore:class: LDAPldap_server: localhostldap_server_options.timeout: 30binddn: "cn=root,dc=example"bindpw: notapasswordstart_tls: 0start_tls_optionsverify: noneuser_basedn: "ou=users,dc=example"user_filter: "(&(objectClass=inetOrgPerson)(cn=%s))"user_scope: oneuser_field: cnuser_search_options:deref: alwaysuse_roles: 1role_basedn: "ou=groups,dc=example"role_filter: "(&(objectClass=groupOfNames)(member=%s))"role_scope: onerole_field: cnrole_value: dnrole_search_options:deref: always
Introduction============About Hydra-----------Hydra is a tool for continuous integration testing and software releasethat uses a purely functional language to describe build jobs and theirdependencies. Continuous integration is a simple technique to improvethe quality of the software development process. An automated systemcontinuously or periodically checks out the source code of a project,builds it, runs tests, and produces reports for the developers. Thus,various errors that might accidentally be committed into the code baseare automatically caught. Such a system allows more in-depth testingthan what developers could feasibly do manually:- Portability testing: The software may need to be built and tested on many differentplatforms. It is infeasible for each developer to do this beforeevery commit.- Likewise, many projects have very large test sets (e.g., regressiontests in a compiler, or stress tests in a DBMS) that can take hoursor days to run to completion.- Many kinds of static and dynamic analyses can be performed as partof the tests, such as code coverage runs and static analyses.- It may also be necessary to build many differentvariantsof the software. For instance, it may be necessary to verify thatthe component builds with various versions of a compiler.- Developers typically use incremental building to test their changes(since a full build may take too long), but this is unreliable withmany build management tools (such as Make), i.e., the result of theincremental build might differ from a full build.- It ensures that the software can be built from the sources underrevision control. Users of version management systems such as CVSand Subversion often forget to place source files under revisioncontrol.- The machines on which the continuous integration system runs ideallyprovides a clean, well-defined build environment. If thisenvironment is administered through proper SCM techniques, thenbuilds produced by the system can be reproduced. In contrast,developer work environments are typically not under any kind of SCMcontrol.- In large projects, developers often work on a particular componentof the project, and do not build and test the composition of thosecomponents (again since this is likely to take too long). To preventthe phenomenon of \`\`big bang integration\'\', where components areonly tested together near the end of the development process, it isimportant to test components together as soon as possible (hencecontinuous integration).- It allows software to bereleasedby automatically creating packages that users can download andinstall. To do this manually represents an often prohibitive amountof work, as one may want to produce releases for many differentplatforms: e.g., installers for Windows and Mac OS X, RPM or Debianpackages for certain Linux distributions, and so on.In its simplest form, a continuous integration tool sits in a loopbuilding and releasing software components from a version managementsystem. For each component, it performs the following tasks:- It obtains the latest version of the component\'s source code fromthe version management system.- It runs the component\'s build process (which presumably includesthe execution of the component\'s test set).- It presents the results of the build (such as error logs andreleases) to the developers, e.g., by producing a web page.Examples of continuous integration tools include Jenkins, CruiseControlTinderbox, Sisyphus, Anthill and BuildBot. These tools have variouslimitations.- They do not manage thebuild environment. The build environment consists of the dependencies necessary toperform a build action, e.g., compilers, libraries, etc. Setting upthe environment is typically done manually, and without proper SCMcontrol (so it may be hard to reproduce a build at a later time).Manual management of the environment scales poorly in the number ofconfigurations that must be supported. For instance, suppose that wewant to build a component that requires a certain compiler X. Wethen have to go to each machine and install X. If we later need anewer version of X, the process must be repeated all over again. Anever worse problem occurs if there are conflicting, mutuallyexclusive versions of the dependencies. Thus, simply installing thelatest version is not an option. Of course, we can install thesecomponents in different directories and manually pass theappropriate paths to the build processes of the various components.But this is a rather tiresome and error-prone process.- They do not easily supportvariability in software systems. A system may have a great deal of build-time variability: optionalfunctionality, whether to build a debug or production version,different versions of dependencies, and so on. (For instance, theLinux kernel now has over 2,600 build-time configuration switches.)It is therefore important that a continuous integration tool caneasily select and test different instances from the configurationspace of the system to reveal problems, such as erroneousinteractions between features. In a continuous integration setting,it is also useful to test different combinations of versions ofsubsystems, e.g., the head revision of a component against stablereleases of its dependencies, and vice versa, as this can revealvarious integration problems.*Hydra*, is a continuous integration tool that solves these problems. Itis built on top of the [Nix package manager](http://nixos.org/nix/),which has a purely functional language for describing package buildactions and their dependencies. This allows the build environment forprojects to be produced automatically and deterministically, andvariability in components to be expressed naturally using functions; andas such is an ideal fit for a continuous build system.About Us--------Hydra is the successor of the Nix Buildfarm, which was developed intandem with the Nix software deployment system. Nix was originallydeveloped at the Department of Information and Computing Sciences,Utrecht University by the TraCE project (2003-2008). The project wasfunded by the Software Engineering Research Program Jacquard to improvethe support for variability in software systems. Funding for thedevelopment of Nix and Hydra is now provided by the NIRICT LaQuSo BuildFarm project.About this Manual-----------------This manual tells you how to install the Hydra buildfarm software onyour own server and how to operate that server using its web interface.License-------Hydra is free software: you can redistribute it and/or modify it underthe terms of the GNU General Public License as published by the FreeSoftware Foundation, either version 3 of the License, or (at youroption) any later version.Hydra is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY; without even the implied warranty of MERCHANTABILITY orFITNESS FOR A PARTICULAR PURPOSE. See the [GNU General PublicLicense](http://www.gnu.org/licenses/) for more details.Hydra at `nixos.org`--------------------The `nixos.org` installation of Hydra runs at[`http://hydra.nixos.org/`](http://hydra.nixos.org/). That installationis used to build software components from the [Nix](http://nixos.org),[NixOS](http://nixos.org/nixos), [GNU](http://www.gnu.org/),[Stratego/XT](http://strategoxt.org), and related projects.If you are one of the developers on those projects, it is likely thatyou will be using the NixOS Hydra server in some way. If you need toadminister automatic builds for your project, you should pull the rightstrings to get an account on the server. This manual will tell you howto set up new projects and build jobs within those projects and write arelease.nix file to describe the build process of your project to Hydra.You can skip the next chapter.If your project does not yet have automatic builds within the NixOSHydra server, it may actually be eligible. We are in the process ofsetting up a large buildfarm that should be able to support open sourceand academic software projects. Get in touch.Hydra on your own buildfarm---------------------------If you need to run your own Hydra installation,[installation chapter](installation.md) explains how to download and install thesystem on your own server.
Creating and Managing Projects==============================Once Hydra is installed and running, the next step is to add projects tothe build farm. We follow the example of the [Patchelfproject](http://nixos.org/patchelf.html), a software tool written in Cand using the GNU Build System (GNU Autoconf and GNU Automake).Log in to the web interface of your Hydra installation using the username and password you inserted in the database (by default, Hydra\'s webserver listens on [`localhost:3000`](http://localhost:3000/)). Thenfollow the \"Create Project\" link to create a new project.Project Information-------------------A project definition consists of some general information and a set ofjob sets. The general information identifies a project, its owner, andcurrent state of activity. Here\'s what we fill in for the patchelfproject:Identifier: patchelfThe *identifier* is the identity of the project. It is used in URLs andin the names of build results.The identifier should be a unique name (it is the primary database keyfor the project table in the database). If you try to create a projectwith an already existing identifier you\'d get an error message from thedatabase. So try to create the project after entering just the generalinformation to figure out if you have chosen a unique name. Job sets canbe added once the project has been created.Display name: PatchelfThe *display name* is used in menus.Description: A tool for modifying ELF binariesThe *description* is used as short documentation of the nature of theproject.Owner: eelcoThe *owner* of a project can create and edit job sets.Enabled: YesOnly if the project is *enabled* are builds performed.Once created there should be an entry for the project in the sidebar. Goto the project page for the[Patchelf](http://localhost:3000/project/patchelf) project.Job Sets--------A project can consist of multiple *job sets* (hereafter *jobsets*),separate tasks that can be built separately, but may depend on eachother (without cyclic dependencies, of course). Go to the[Edit](http://localhost:3000/project/patchelf/edit) page of the Patchelfproject and \"Add a new jobset\" by providing the following\"Information\":Identifier: trunkDescription: TrunkNix expression: release.nix in input patchelfSrcThis states that in order to build the `trunk` jobset, the Nixexpression in the file `release.nix`, which can be obtained from input`patchelfSrc`, should be evaluated. (We\'ll have a look at `release.nix`later.)To realize a job we probably need a number of inputs, which can bedeclared in the table below. As many inputs as required can be added.For patchelf we declare the following inputs.patchelfSrc'Git checkout' https://github.com/NixOS/patchelfnixpkgs 'Git checkout' https://github.com/NixOS/nixpkgsofficialRelease Boolean falsesystem String value "i686-linux"Building Jobs-------------Build Recipes-------------Build jobs and *build recipes* for a jobset are specified in a text filewritten in the [Nix language](http://nixos.org/nix/). The recipe isactually called a *Nix expression* in Nix parlance. By convention thisfile is often called `release.nix`.The `release.nix` file is typically kept under version control, and therepository that contains it one of the build inputs of thecorresponding--often called `hydraConfig` by convention. The repositoryfor that file and the actual file name are specified on the webinterface of Hydra under the `Setup` tab of the jobset\'s overview page,under the `Nixexpression` heading. See, for example, the [jobset overviewpage](http://hydra.nixos.org/jobset/patchelf/trunk) of the PatchELFproject, and [the corresponding Nixfile](https://github.com/NixOS/patchelf/blob/master/release.nix).Knowledge of the Nix language is recommended, but the example belowshould already give a good idea of how it works:letpkgs = import <nixpkgs> {}; ①jobs = rec { ②tarball = ③pkgs.releaseTools.sourceTarball { ④name = "hello-tarball";src = <hello>; ⑤buildInputs = (with pkgs; [ gettext texLive texinfo ]);};build = ⑥{ system ? builtins.currentSystem }: ⑦let pkgs = import <nixpkgs> { inherit system; }; inpkgs.releaseTools.nixBuild { ⑧name = "hello";src = jobs.tarball;configureFlags = [ "--disable-silent-rules" ];};};injobs ⑨This file shows what a `release.nix` file for[GNU Hello](http://www.gnu.org/software/hello/) would look like.GNU Hello is representative of many GNU and non-GNU free softwareprojects:- it uses the GNU Build System, namely GNU Autoconf, and GNU Automake;for users, it means it can be installed using theusual./configure && make installprocedure;- it uses Gettext for internationalization;- it has a Texinfo manual, which can be rendered as PDF with TeX.The file defines a jobset consisting of two jobs: `tarball`, and`build`. It contains the following elements (referenced from the figureby numbers):1. This defines a variable `pkgs` holding the set of packages providedby [Nixpkgs](http://nixos.org/nixpkgs/).Since `nixpkgs` appears in angle brackets, there must be a buildinput of that name in the Nix search path. In this case, the webinterface should show a `nixpkgs` build input, which is a checkoutof the Nixpkgs source code repository; Hydra then adds this andother build inputs to the Nix search path when evaluating`release.nix`.2. This defines a variable holding the two Hydra jobs--an *attributeset* in Nix.3. This is the definition of the first job, named `tarball`. Thepurpose of this job is to produce a usable source code tarball.4. The `tarball` job calls the `sourceTarball` function, which(roughly) runs `autoreconf && ./configure &&make dist` on the checkout. The `buildInputs` attributespecifies additional software dependencies for the job.> The package names used in `buildInputs`--e.g., `texLive`--are the> names of the *attributes* corresponding to these packages in> Nixpkgs, specifically in the> [`all-packages.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix)> file. See the section entitled "Package Naming" in the Nixpkgs> manual for more information.5. The `tarball` jobs expects a `hello` build input to be available inthe Nix search path. Again, this input is passed by Hydra and ismeant to be a checkout of GNU Hello\'s source code repository.6. This is the definition of the `build` job, whose purpose is to buildHello from the tarball produced above.7. The `build` function takes one parameter, `system`, which should bea string defining the Nix system type--e.g., `"x86_64-linux"`.Additionally, it refers to `jobs.tarball`, seen above.Hydra inspects the formal argument list of the function (here, the`system` argument) and passes it the corresponding parameterspecified as a build input on Hydra\'s web interface. Here, `system`is passed by Hydra when it calls `build`. Thus, it must be definedas a build input of type string in Hydra, which could take one ofseveral values.The question mark after `system` defines the default value for thisargument, and is only useful when debugging locally.8. The `build` job calls the `nixBuild` function, which unpacks thetarball, then runs `./configure && make&& make check && make install`.9. Finally, the set of jobs is returned to Hydra, as a Nix attributeset.Building from the Command Line------------------------------It is often useful to test a build recipe, for instance before it isactually used by Hydra, when testing changes, or when debugging a buildissue. Since build recipes for Hydra jobsets are just plain Nixexpressions, they can be evaluated using the standard Nix tools.To evaluate the `tarball` jobset of the above example, justrun:$ nix-build release.nix -A tarballHowever, doing this with the example as is will probablyyield an error like this:error: user-thrown exception: file `hello' was not found in the Nix search path (add it using $NIX_PATH or -I)The error is self-explanatory. Assuming `$HOME/src/hello` points to acheckout of Hello, this can be fixed this way:$ nix-build -I ~/src release.nix -A tarballSimilarly, the `build` jobset can be evaluated:$ nix-build -I ~/src release.nix -A buildThe `build` job reuses the result of the `tarball` job, rebuilding itonly if it needs to.Adding More Jobs----------------The example illustrates how to write the most basicjobs, `tarball` and `build`. In practice, much more can be done by usingfeatures readily provided by Nixpkgs or by creating new jobs ascustomizations of existing jobs.For instance, test coverage report for projects compiled with GCC can beautomatically generated using the `coverageAnalysis` function providedby Nixpkgs instead of `nixBuild`. Back to our GNU Hello example, we candefine a `coverage` job that produces an HTML code coverage reportdirectly readable from the corresponding Hydra build page:coverage ={ system ? builtins.currentSystem }:let pkgs = import nixpkgs { inherit system; }; inpkgs.releaseTools.coverageAnalysis {name = "hello";src = jobs.tarball;configureFlags = [ "--disable-silent-rules" ];};As can be seen, the only difference compared to `build` is the use of`coverageAnalysis`.Nixpkgs provides many more build tools, including the ability to runbuild in virtual machines, which can themselves run another GNU/Linuxdistribution, which allows for the creation of packages for thesedistributions. Please see [the `pkgs/build-support/release`directory](https://github.com/NixOS/nixpkgs/tree/master/pkgs/build-support/release)of Nixpkgs for more. The NixOS manual also contains information aboutwhole-system testing in virtual machine.Now, assume we want to build Hello with an old version of GCC, and withdifferent `configure` flags. A new `build_exotic` job can be writtenthat simply *overrides* the relevant arguments passed to `nixBuild`:build_exotic ={ system ? builtins.currentSystem }:letpkgs = import nixpkgs { inherit system; };build = jobs.build { inherit system; };inpkgs.lib.overrideDerivation build (attrs: {buildInputs = [ pkgs.gcc33 ];preConfigure = "gcc --version";configureFlags =attrs.configureFlags ++ [ "--disable-nls" ];});The `build_exotic` job reuses `build` and overrides some of itsarguments: it adds a dependency on GCC 3.3, a pre-configure phase thatruns `gcc --version`, and adds the `--disable-nls` configure flags.This customization mechanism is very powerful. For instance, it can beused to change the way Hello and *all* its dependencies--including the Clibrary and compiler used to build it--are built. See the Nixpkgs manualfor more.Declarative projects--------------------Hydra supports declaratively configuring a project\'s jobsets. Thisconfiguration can be done statically, or generated by a build job.> **Note**>> Hydra will treat the project\'s declarative input as a static definition> if and only if the spec file contains a dictionary of dictionaries. If> the value of any key in the spec is not a dictionary, it will treat the> spec as a generated declarative spec.### Static, Declarative ProjectsHydra supports declarative projects, where jobsets are configured from astatic JSON document in a repository.To configure a static declarative project, take the following steps:1. Create a Hydra-fetchable source like a Git repository or local path.2. In that source, create a file called `spec.json`, and add thespecification for all of the jobsets. Each key is jobset and eachvalue is a jobset\'s specification. For example:``` {.json}{"nixpkgs": {"enabled": 1,"hidden": false,"description": "Nixpkgs","nixexprinput": "nixpkgs","nixexprpath": "pkgs/top-level/release.nix","checkinterval": 300,"schedulingshares": 100,"enableemail": false,"emailoverride": "","keepnr": 3,"inputs": {"nixpkgs": {"type": "git","value": "git://github.com/NixOS/nixpkgs.git master","emailresponsible": false}}},"nixos": {"enabled": 1,"hidden": false,"description": "NixOS: Small Evaluation","nixexprinput": "nixpkgs","nixexprpath": "nixos/release-small.nix","checkinterval": 300,"schedulingshares": 100,"enableemail": false,"emailoverride": "","keepnr": 3,"inputs": {"nixpkgs": {"type": "git","value": "git://github.com/NixOS/nixpkgs.git master","emailresponsible": false}}}}```3. Create a new project, and set the project\'s declarative input type,declarative input value, and declarative spec file to point to thesource and JSON file you created in step 2.Hydra will create a special jobset named `.jobsets`. When the `.jobsets`jobset is evaluated, this static specification will be used forconfiguring the rest of the project\'s jobsets.### Generated, Declarative ProjectsHydra also supports generated declarative projects, where jobsets areconfigured automatically from specification files instead of beingmanaged through the UI. A jobset specification is a JSON objectcontaining the configuration of the jobset, for example:``` {.json}{"enabled": 1,"hidden": false,"description": "js","nixexprinput": "src","nixexprpath": "release.nix","checkinterval": 300,"schedulingshares": 100,"enableemail": false,"emailoverride": "","keepnr": 3,"inputs": {"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }}}```To configure a declarative project, take the following steps:1. Create a jobset repository in the normal way (e.g. a git repo with a`release.nix` file, any other needed helper files, and taking anykind of hydra input), but without adding it to the UI. The nixexpression of this repository should contain a single job, named`jobsets`. The output of the `jobsets` job should be a JSON filecontaining an object of jobset specifications. Each member of theobject will become a jobset of the project, configured by thecorresponding jobset specification.2. In some hydra-fetchable source (potentially, but not necessarily,the same repo you created in step 1), create a JSON file containinga jobset specification that points to the jobset repository youcreated in the first step, specifying any needed inputs(e.g. nixpkgs) as necessary.3. In the project creation/edit page, set declarative input type,declarative input value, and declarative spec file to point to thesource and JSON file you created in step 2.Hydra will create a special jobset named `.jobsets`, which wheneverevaluated will go through the steps above in reverse order:1. Hydra will fetch the input specified by the declarative input typeand value.2. Hydra will use the configuration given in the declarative spec fileas the jobset configuration for this evaluation. In addition to anyinputs specified in the spec file, hydra will also pass the`declInput` argument corresponding to the input fetched in step 1.3. As normal, hydra will build the jobs specified in the jobsetrepository, which in this case is the single `jobsets` job. Whenthat job completes, hydra will read the created jobsetspecifications and create corresponding jobsets in the project,disabling any jobsets that used to exist but are not present in thecurrent spec.Email Notifications-------------------Hydra can send email notifications when the status of a build changes.This provides immediate feedback to maintainers or committers when achange causes build failures.The simplest approach to enable Email Notifications is to use the ssmtppackage, which simply hands off the emails to another SMTP server. Fordetails on how to configure ssmtp, see the documentation for the`networking.defaultMailServer` option. To use ssmtp for the Hydra emailnotifications, add it to the path option of the Hydra services in your`/etc/nixos/configuration.nix` file:systemd.services.hydra-queue-runner.path = [ pkgs.ssmtp ];systemd.services.hydra-server.path = [ pkgs.ssmtp ];