diff --git a/nix/arion.nix b/nix/arion.nix index b53b1f4..0374853 100644 --- a/nix/arion.nix +++ b/nix/arion.nix @@ -1,42 +1,12 @@ +# Like the upstreamable expression but wired up for the local arion. { pkgs ? import ./. {} , lib ? pkgs.lib +, haskell ? pkgs.haskell , haskellPackages ? pkgs.haskellPackages , arion-compose ? import ./haskell-arion-compose.nix { inherit pkgs haskellPackages; } +, runCommand ? pkgs.runCommand }: - -let - inherit (pkgs.haskell.lib) justStaticExecutables overrideCabal; - - srcDir = ../src; - eval = import (srcDir + "/nix/eval-composition.nix"); - build = args@{...}: - let composition = eval args; - in composition.config.out.dockerComposeYaml; - -in - justStaticExecutables (overrideCabal arion-compose (o: { - buildTools = o.buildTools ++ [pkgs.makeWrapper]; - passthru = o.passthru // { - inherit eval build; - }; - pname = "arion"; # Cover up the needlessly long Haskell package name - - # PYTHONPATH - # - # We close off the python module search path! - # - # Accepting directories from the environment into the search path - # tends to break things. Docker Compose does not have a plugin - # system as far as I can tell, so I don't expect this to break a - # feature, but rather to make the program more robustly self- - # contained. - - postInstall = ''${o.postInstall or ""} - mkdir -p $out/libexec - mv $out/bin/arion $out/libexec - makeWrapper $out/libexec/arion $out/bin/arion \ - --unset PYTHONPATH \ - --prefix PATH : ${lib.makeBinPath [ pkgs.docker-compose ]} \ - ; - ''; - })) +import ./upstreamable/default.nix { + inherit pkgs lib haskell runCommand; + haskellPackages = haskellPackages // { inherit arion-compose; }; +} diff --git a/nix/upstreamable/default.nix b/nix/upstreamable/default.nix new file mode 100644 index 0000000..149beec --- /dev/null +++ b/nix/upstreamable/default.nix @@ -0,0 +1,89 @@ +{ pkgs +, lib +, haskellPackages +, haskell +, runCommand +}: + +let + + /* This derivation builds the arion tool. + + It is based on the arion-compose Haskell package, but adapted and extended to + - have the correct name + - have a smaller closure size + - have functions to use Arion from inside Nix: arion.eval and arion.build + - make it self-contained by including docker-compose + */ + arion = + justStaticExecutables ( + overrideCabal + arion-compose + cabalOverrides + ); + + inherit (haskell.lib) justStaticExecutables overrideCabal; + + inherit (haskellPackages) arion-compose; + + cabalOverrides = o: { + buildTools = (o.buildTools or []) ++ [pkgs.makeWrapper]; + passthru = (o.passthru or {}) // { + inherit eval build; + }; + # Patch away the arion-compose name. Unlike the Haskell library, the program + # is called arion (arion was already taken on hackage). + pname = "arion"; + src = arion-compose.src; + + # PYTHONPATH + # + # We close off the python module search path! + # + # Accepting directories from the environment into the search path + # tends to break things. Docker Compose does not have a plugin + # system as far as I can tell, so I don't expect this to break a + # feature, but rather to make the program more robustly self- + # contained. + + postInstall = ''${o.postInstall or ""} + mkdir -p $out/libexec + mv $out/bin/arion $out/libexec + makeWrapper $out/libexec/arion $out/bin/arion \ + --unset PYTHONPATH \ + --prefix PATH : ${lib.makeBinPath [ pkgs.docker-compose ]} \ + ; + ''; + }; + + # Unpacked sources for evaluation by `eval` + srcUnpacked = pkgs.stdenv.mkDerivation { + name = "arion-src"; + inherit (arion-compose) src; + buildPhase = '' + cp -r $src $out + ''; + installPhase = ""; + }; + + /* Function for evaluating a composition + + Re-uses this Nixpkgs evaluation instead of `arion-pkgs.nix`. + + Returns the module system's `config` and `options` variables. + */ + eval = args@{...}: + import (srcUnpacked + "/src/nix/eval-composition.nix") + ({ inherit pkgs; } // args); + + /* Function to derivation of the docker compose yaml file + NOTE: The output will change: https://github.com/hercules-ci/arion/issues/82 + + This function is particularly useful on CI, although the references + to image tarballs may not always be desirable. + */ + build = args@{...}: + let composition = eval args; + in composition.config.out.dockerComposeYaml; + +in arion