lol
1{ pkgs
2, lib
3, haskellPackages
4, haskell
5, runCommand
6, buildPackages
7}:
8
9let
10
11 /* This derivation builds the arion tool.
12
13 It is based on the arion-compose Haskell package, but adapted and extended to
14 - have the correct name
15 - have a smaller closure size
16 - have functions to use Arion from inside Nix: arion.eval and arion.build
17 - make it self-contained by including docker-compose
18 */
19 arion =
20 (justStaticExecutables (
21 overrideCabal
22 cabalOverrides
23 arion-compose
24 )
25 ).overrideAttrs (o: {
26 # Patch away the arion-compose name. Unlike the Haskell library, the program
27 # is called arion (arion was already taken on hackage).
28 pname = "arion";
29 });
30
31 inherit (haskell.lib.compose) justStaticExecutables overrideCabal;
32
33 inherit (haskellPackages) arion-compose;
34
35 cabalOverrides = o: {
36 buildTools = (o.buildTools or []) ++ [buildPackages.makeWrapper];
37 passthru = (o.passthru or {}) // {
38 inherit eval build;
39 };
40 src = arion-compose.src;
41
42 # PYTHONPATH
43 #
44 # We close off the python module search path!
45 #
46 # Accepting directories from the environment into the search path
47 # tends to break things. Docker Compose does not have a plugin
48 # system as far as I can tell, so I don't expect this to break a
49 # feature, but rather to make the program more robustly self-
50 # contained.
51
52 postInstall = ''${o.postInstall or ""}
53 mkdir -p $out/libexec
54 mv $out/bin/arion $out/libexec
55 makeWrapper $out/libexec/arion $out/bin/arion \
56 --unset PYTHONPATH \
57 --prefix PATH : ${lib.makeBinPath [ pkgs.docker-compose_1 ]} \
58 ;
59 '';
60 };
61
62 # Unpacked sources for evaluation by `eval`
63 srcUnpacked = runCommand "arion-src" {}
64 "mkdir $out; tar -C $out --strip-components=1 -xf ${arion-compose.src}";
65
66 /* Function for evaluating a composition
67
68 Re-uses this Nixpkgs evaluation instead of `arion-pkgs.nix`.
69
70 Returns the module system's `config` and `options` variables.
71 */
72 eval = args@{...}:
73 import (srcUnpacked + "/src/nix/eval-composition.nix")
74 ({ inherit pkgs; } // args);
75
76 /* Function to derivation of the docker compose yaml file
77 NOTE: The output will change: https://github.com/hercules-ci/arion/issues/82
78
79 This function is particularly useful on CI, although the references
80 to image tarballs may not always be desirable.
81 */
82 build = args@{...}:
83 let composition = eval args;
84 in composition.config.out.dockerComposeYaml;
85
86in arion