Merge pull request from hercules-ci/flake

Flake
This commit is contained in:
Robert Hensing 2021-05-19 17:13:43 +02:00 committed by GitHub
commit b83cf51efd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 170 additions and 43 deletions
docs/modules/ROOT/pages
flake.lockflake.nix
nix

View file

@ -244,13 +244,12 @@ Nope, its just Nix and Docker Compose under the hood.
=== What about garbage collection? === What about garbage collection?
Arion removes the need for garbage collecting docker images, delegating Arion removes the need for garbage collecting docker images, delegating
this task to Nix. this task to Nix when using `service.useHostStore`.
Arion creates a garbage collection root and cleans it up after Arion creates a garbage collection root that it cleans up after completing
completing the command. This means that `arion up` without `-d` is safe the command. This means that `arion up -d` should not be used with `useHostStore`
with respect to garbage collection. A deployment that is more serious in production. Instead, disable `useHostStore`, which will use `dockerTools` to
than local development must leave a GC root on the deployment host. This generate images that can be used in production.
use case is not supported as of now.
=== Why is my container not running latest code? === Why is my container not running latest code?

25
flake.lock generated Normal file
View file

@ -0,0 +1,25 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1601906239,
"narHash": "sha256-P1jBYbYeFswig/0FKbgh+BpVhh9iurD3m0T2ae4gdx8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c2bb4af48d26ed091e5674394bacbf8d488c7939",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

42
flake.nix Normal file
View file

@ -0,0 +1,42 @@
{
description = "Arion - use Docker Compose via Nix";
outputs = { self, nixpkgs }:
let
lib = import (nixpkgs + "/lib");
systems = [
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
arionFromPkgs = pkgs: import ./nix/arion.nix { inherit pkgs; };
in {
# The overlay is currently the recommended way to integrate arion,
# because its arion attribute behaves just like Nixpkgs.
overlay = final: prev: {
arion = arionFromPkgs final;
};
packages = lib.genAttrs systems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
arion = arionFromPkgs pkgs;
});
# Does not include the eval and build functions like you may expect from Nixpkgs.
defaultPackage = lib.genAttrs systems (system:
self.packages.${system}.arion
);
lib = {
eval = import ./src/nix/eval-composition.nix;
build = args@{...}:
let composition = self.lib.eval args;
in composition.config.out.dockerComposeYaml;
};
};
}

View file

@ -1,42 +1,13 @@
# Like the upstreamable expression but wired up for the local arion.
{ pkgs ? import ./. {} { pkgs ? import ./. {}
, lib ? pkgs.lib , lib ? pkgs.lib
, haskell ? pkgs.haskell
, haskellPackages ? pkgs.haskellPackages , haskellPackages ? pkgs.haskellPackages
, arion-compose ? import ./haskell-arion-compose.nix { inherit pkgs haskellPackages; } , arion-compose ? import ./haskell-arion-compose.nix { inherit pkgs haskellPackages; }
, runCommand ? pkgs.runCommand
}: }:
import ./upstreamable/default.nix {
let inherit pkgs lib haskell runCommand;
inherit (pkgs.haskell.lib) justStaticExecutables overrideCabal; haskellPackages = haskellPackages // { inherit arion-compose; };
evalSrc = ./..;
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 ]} \
;
'';
}))

View file

@ -0,0 +1,90 @@
args@
{ pkgs
, lib
, haskellPackages
, haskell
, runCommand
# Allow this expression file to be used more efficiently in situations where
# the sources are more readily available. Unpacking haskellPackages.arion-compose.src
# is not always the best choice for arion.eval.
, evalSrc ? null
}:
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`
evalSrc' = args.evalSrc or (runCommand "arion-src" {}
"mkdir $out; tar -C $out --strip-components=1 -xf ${arion-compose.src}");
/* 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 (evalSrc' + "/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. On Nixpkgs >= 20.09 this will
not store the image tarballs but executables to produce them reliably via
streamLayeredImage.
*/
build = args@{...}:
let composition = eval args;
in composition.config.out.dockerComposeYaml;
in arion