Merge pull request #171 from hercules-ci/aeson

Aeson 1 -> 2
This commit is contained in:
Robert Hensing 2022-12-02 13:13:17 +00:00 committed by GitHub
commit 935c32afa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 246 additions and 513 deletions

View file

@ -31,7 +31,7 @@ source-repository head
common common
build-depends: base >=4.12.0.0 && <4.17
, aeson
, aeson >=2
, aeson-pretty
, async
, bytestring

View file

@ -1,6 +1,11 @@
{ pkgs ? import ./nix {}
let flake = import ./nix/compat.nix;
in
{ pkgs ? import flake.inputs.nixpkgs { }
, haskellPackages ? pkgs.haskellPackages
}:
let
pkgsWithArion = pkgs.extend flake.overlays.default;
in
{
arion = import ./nix/arion.nix { inherit pkgs haskellPackages; };
inherit (pkgsWithArion) arion;
}

20
docs/flake-module.nix Normal file
View file

@ -0,0 +1,20 @@
{
perSystem = { config, pkgs, ... }:
let
doc-options = import ./options.nix { };
in
{
packages.doc-options = pkgs.callPackage ./options.nix { };
checks.doc-options = pkgs.runCommand "doc-options-check" { } ''
if diff --color -u ${./modules/ROOT/partials/NixOSOptions.adoc} ${config.packages.doc-options}; then
touch $out
else
echo 1>&2 "The doc options have changed and need to be added."
echo 1>&2 "Please run ./update-options in the root of your arion clone."
exit 1
fi
'';
};
}

View file

@ -102,7 +102,7 @@ See link:https://docs.docker.com/compose/compose-file/#networks-top-level-elemen
[discrete]
=== details
Type:: lazy attribute set of submodules
Type:: lazy attribute set of (submodule)
No Default:: {blank}
No Example:: {blank}
@ -147,7 +147,7 @@ See link:https://docs.docker.com/compose/compose-file/#driver_opts[Docker Compos
[discrete]
=== details
Type:: lazy attribute set of raw values
Type:: lazy attribute set of raw value
No Default:: {blank}
No Example:: {blank}
@ -228,7 +228,7 @@ See link:https://docs.docker.com/compose/compose-file/#labels[Docker Compose#lab
[discrete]
=== details
Type:: attribute set of strings
Type:: attribute set of string
No Default:: {blank}
No Example:: {blank}
@ -271,7 +271,7 @@ The text of out.dockerComposeYaml.
[discrete]
=== details
Type:: attribute set of unspecifieds
Type:: attribute set of unspecified value
No Default:: {blank}
Read Only:: {blank}
No Example:: {blank}
@ -312,7 +312,7 @@ An attribute set of service configurations. A service specifies how to run an im
[discrete]
=== details
Type:: attribute set of submodules
Type:: attribute set of (submodule)
No Default:: {blank}
No Example:: {blank}
@ -350,7 +350,7 @@ No Example:: {blank}
[discrete]
=== details
Type:: list of strings
Type:: list of string
Default::
+
----
@ -368,7 +368,7 @@ Top level paths in the container.
[discrete]
=== details
Type:: list of packages
Type:: list of package
Default::
+
----
@ -453,7 +453,7 @@ v1.2.0].
[discrete]
=== details
Type:: attribute set of unspecifieds
Type:: attribute set of unspecified value
Default::
+
----
@ -494,7 +494,7 @@ NixOS configuration can be used in other ways.
[discrete]
=== details
Type:: list of unspecifieds or unspecified convertible to it
Type:: (list of unspecified value) or unspecified value convertible to it
Default::
+
----
@ -554,7 +554,7 @@ It will be inserted in `x-arion.serviceInfo.<service.name>`.
[discrete]
=== details
Type:: attribute set of unspecifieds
Type:: attribute set of unspecified value
Default::
+
----
@ -578,7 +578,7 @@ escape hatch for some.
[discrete]
=== details
Type:: attribute set of unspecifieds
Type:: attribute set of unspecified value
No Default:: {blank}
No Example:: {blank}
@ -618,7 +618,7 @@ according to Docker's link:https://docs.docker.com/engine/reference/run/#runtime
[discrete]
=== details
Type:: attribute set of null or booleans
Type:: attribute set of (null or boolean)
Default::
+
----
@ -640,7 +640,7 @@ See link:https://docs.docker.com/compose/compose-file/#command[Docker Compose#co
[discrete]
=== details
Type:: null or unspecified
Type:: null or unspecified value
Default::
+
----
@ -676,7 +676,7 @@ Container program and arguments to invoke when calling
[discrete]
=== details
Type:: list of strings
Type:: list of string
Default::
+
----
@ -693,7 +693,7 @@ See link:https://docs.docker.com/compose/compose-file/#depends_on[Docker Compose
[discrete]
=== details
Type:: list of strings or attribute set of submodules
Type:: (list of string) or attribute set of (submodule)
Default::
+
----
@ -713,7 +713,7 @@ See link:https://docs.docker.com/compose/compose-file/#devices[Docker Compose#de
[discrete]
=== details
Type:: list of strings
Type:: list of string
Default::
+
----
@ -730,7 +730,7 @@ See link:https://docs.docker.com/compose/compose-file/#dns[Docker Compose#dns]
[discrete]
=== details
Type:: list of strings
Type:: list of string
Default::
+
----
@ -769,7 +769,7 @@ See link:https://docs.docker.com/compose/compose-file/#env_file[Docker Compose#e
[discrete]
=== details
Type:: list of strings
Type:: list of string
Default::
+
----
@ -786,7 +786,7 @@ See link:https://docs.docker.com/compose/compose-file/#environment[Docker Compos
[discrete]
=== details
Type:: attribute set of string or signed integers
Type:: attribute set of (string or signed integer)
Default::
+
----
@ -803,7 +803,7 @@ See link:https://docs.docker.com/compose/compose-file/#expose[Docker Compose#exp
[discrete]
=== details
Type:: list of strings
Type:: list of string
Default::
+
----
@ -820,7 +820,7 @@ See link:https://docs.docker.com/compose/compose-file/#external_links[Docker Com
[discrete]
=== details
Type:: list of strings
Type:: list of string
Default::
+
----
@ -837,7 +837,7 @@ See link:https://docs.docker.com/compose/compose-file/#extra_hosts[Docker Compos
[discrete]
=== details
Type:: list of strings
Type:: list of string
Default::
+
----
@ -849,7 +849,7 @@ No Example:: {blank}
== services.<name>.service.healthcheck
None
See link:https://docs.docker.com/compose/compose-file/#healthcheck[Docker Compose#healthcheck]
[discrete]
=== details
@ -927,7 +927,7 @@ See link:https://docs.docker.com/compose/compose-file/#healthcheck[Docker Compos
[discrete]
=== details
Type:: null or list of strings
Type:: null or (list of string)
Default::
+
----
@ -1020,7 +1020,7 @@ See link:https://docs.docker.com/compose/compose-file/#labels[Docker Compose#lab
[discrete]
=== details
Type:: attribute set of strings
Type:: attribute set of string
Default::
+
----
@ -1042,7 +1042,7 @@ See link:https://docs.docker.com/compose/compose-file/#links[Docker Compose#link
[discrete]
=== details
Type:: list of strings
Type:: list of string
Default::
+
----
@ -1089,7 +1089,7 @@ See link:https://docs.docker.com/compose/compose-file/#networks[Docker Compose#n
[discrete]
=== details
Type:: null or list of strings
Type:: null or (list of string)
Default::
+
----
@ -1109,7 +1109,7 @@ See link:https://docs.docker.com/compose/compose-file/#ports[Docker Compose#port
[discrete]
=== details
Type:: list of unspecifieds
Type:: list of unspecified value
Default::
+
----
@ -1180,7 +1180,7 @@ See link:https://docs.docker.com/compose/compose-file/#sysctls[Docker Compose#sy
[discrete]
=== details
Type:: attribute set of string or signed integers
Type:: attribute set of (string or signed integer)
Default::
+
----
@ -1197,7 +1197,7 @@ See link:https://docs.docker.com/compose/compose-file/#tmpfs[Docker Compose#tmpf
[discrete]
=== details
Type:: list of strings
Type:: list of string
Default::
+
----
@ -1288,7 +1288,7 @@ See link:https://docs.docker.com/compose/compose-file/#volumes[Docker Compose#vo
[discrete]
=== details
Type:: list of unspecifieds
Type:: list of unspecified value
Default::
+
----

View file

@ -36,8 +36,8 @@
echo nginx:x:${toString config.users.groups.nginx.gid}:nginx >>/etc/group
echo 'nobody:x:65534:65534:Unprivileged account do not use:/var/empty:/run/current-system/sw/bin/nologin' >>/etc/passwd
echo 'nogroup:x:65534:' >>/etc/group
mkdir -p /var/log/nginx /run/nginx/ /var/cache/nginx /var/lib/nginx/{,logs,proxy_temp,client_body_temp,fastcgi_temp,scgi_temp,uwsgi_temp}
chown nginx /var/log/nginx /run/nginx/ /var/cache/nginx /var/lib/nginx/{,logs,proxy_temp,client_body_temp,fastcgi_temp,scgi_temp,uwsgi_temp}
mkdir -p /var/log/nginx /run/nginx/ /var/cache/nginx /var/lib/nginx/{,logs,proxy_temp,client_body_temp,fastcgi_temp,scgi_temp,uwsgi_temp} /tmp/nginx_client_body
chown nginx /var/log/nginx /run/nginx/ /var/cache/nginx /var/lib/nginx/{,logs,proxy_temp,client_body_temp,fastcgi_temp,scgi_temp,uwsgi_temp} /tmp/nginx_client_body
${config.systemd.services.nginx.runner}
'';
};

View file

@ -1,21 +1,61 @@
{
"nodes": {
"nixpkgs": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1601906239,
"narHash": "sha256-P1jBYbYeFswig/0FKbgh+BpVhh9iurD3m0T2ae4gdx8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c2bb4af48d26ed091e5674394bacbf8d488c7939",
"lastModified": 1669931201,
"narHash": "sha256-UnYFeaLPLj7e4eEt4GJooeJZhaZXyloQZYinwO/CeUw=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "995d6bc162c0539998ef6375c2c6b612972dc016",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
"owner": "hercules-ci",
"ref": "easyOverlay",
"repo": "flake-parts",
"type": "github"
}
},
"haskell-flake": {
"locked": {
"lastModified": 1668167720,
"narHash": "sha256-5wDTR6xt9BB3BjgKR+YOjOkZgMyDXKaX79g42sStzDU=",
"owner": "srid",
"repo": "haskell-flake",
"rev": "4fc511d93a55fedf815c1647ad146c26d7a2054e",
"type": "github"
},
"original": {
"owner": "srid",
"repo": "haskell-flake",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1669980218,
"narHash": "sha256-HBK1tIqarj7ZsSwQEKGlyvbAIFnglytG7FxuS4K3nY8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "da7988fe440ef5b8779d4f76340ad7dc79ff3b33",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "haskell-updates",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"haskell-flake": "haskell-flake",
"nixpkgs": "nixpkgs"
}
}

100
flake.nix
View file

@ -1,35 +1,76 @@
{
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;
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/haskell-updates";
haskell-flake.url = "github:srid/haskell-flake";
flake-parts.url = "github:hercules-ci/flake-parts/easyOverlay"; # TODO merge
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
};
packages = lib.genAttrs systems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
outputs = inputs@{ self, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit self; } ({ config, lib, extendModules, ... }: {
imports = [
inputs.haskell-flake.flakeModule
inputs.flake-parts.flakeModules.easyOverlay
./docs/flake-module.nix
./tests/flake-module.nix
];
systems = inputs.nixpkgs.lib.systems.flakeExposed;
perSystem = { config, self', inputs', pkgs, system, final, ... }:
let h = pkgs.haskell.lib.compose; in
{
arion = arionFromPkgs pkgs;
});
overlayAttrs = {
inherit (config.packages) arion;
arionTestingFlags = {
dockerSupportsSystemd = false;
};
};
packages.default = config.packages.arion;
packages.overlay-test = final.arion;
packages.arion = import ./nix/arion.nix { inherit pkgs; };
haskellProjects.haskell-package = {
# not autodetected: https://github.com/srid/haskell-flake/issues/49
packages.arion-compose.root = ./.;
# Does not include the eval and build functions like you may expect from Nixpkgs.
defaultPackage = lib.genAttrs systems (system:
self.packages.${system}.arion
);
overrides =
self: super: {
arion-compose =
lib.pipe super.arion-compose [
(h.addBuildTools [ pkgs.nix ])
(h.overrideCabal (o: {
src = pkgs.lib.sourceByRegex ./. [
".*[.]cabal"
"LICENSE"
"src/?.*"
"README.asciidoc"
"CHANGELOG.md"
];
preCheck = ''
export NIX_LOG_DIR=$TMPDIR
export NIX_STATE_DIR=$TMPDIR
export NIX_PATH=nixpkgs=${pkgs.path}
'';
}))
];
};
};
devShells.default = config.devShells.haskell-package.overrideAttrs (o: {
nativeBuildInputs = o.nativeBuildInputs or [ ] ++ [
pkgs.docker-compose
pkgs.nixpkgs-fmt
config.haskellProjects.haskell-package.haskellPackages.releaser
];
});
};
flake = {
debug = { inherit inputs config lib; };
defaultPackage =
lib.mapAttrs
(ps: lib.warn "arion.defaultPackage has been removed in favor of arion.packages.\${system}.default"
ps.default)
config.flake.packages;
lib = {
eval = import ./src/nix/eval-composition.nix;
@ -37,8 +78,13 @@
let composition = self.lib.eval args;
in composition.config.out.dockerComposeYaml;
};
nixosModules.arion = ./nixos-module.nix;
herculesCI.ciSystems = [
# "aarch64-darwin"
# "aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
};
});
}

View file

@ -1,46 +0,0 @@
let
sources = import ./sources.nix;
lib = import (sources."nixos-unstable" + "/lib");
inherit (import (sources."project.nix" + "/lib/dimension.nix") { inherit lib; }) dimension;
in
dimension "Nixpkgs version" {
"nixos-22_05" = {
nixpkgsSource = "nixos-22.05";
enableDoc = true;
};
"nixos-unstable" = {
nixpkgsSource = "nixos-unstable";
isReferenceNixpkgs = true; # match ./default.nix
enableDoc = true;
};
} (
_name: { nixpkgsSource, isReferenceNixpkgs ? false, enableDoc ? true,
dockerSupportsSystemd ? false, nixosHasPodmanDockerSocket ? true }:
dimension "System" {
"x86_64-linux" = { isReferenceTarget = isReferenceNixpkgs; };
"x86_64-darwin" = { enableNixOSTests = false; };
} (
system: { isReferenceTarget ? false, enableNixOSTests ? true }:
let
pkgs = import ./. {
inherit system dockerSupportsSystemd nixosHasPodmanDockerSocket;
nixpkgsSrc = sources.${nixpkgsSource};
};
in
{
inherit (pkgs) arion;
} // lib.optionalAttrs enableNixOSTests {
inherit (pkgs) tests;
} // lib.optionalAttrs enableDoc {
inherit (pkgs)
# FIXME: nixpkgs antora packaging is broken
# doc
doc-options doc-options-check;
} // lib.optionalAttrs isReferenceTarget {
inherit (pkgs.arion-project.haskellPkgs) arion-compose-checked;
}
)
)

10
nix/compat.nix Normal file
View file

@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/009399224d5e398d03b22badca40a37ac85412a1.tar.gz";
sha256 = "sha256:0xcr9fibnapa12ywzcnlf54wrmbqqb96fmmv8043zhsycws7bpqy";
}
)
{ src = ../.; }
).defaultNix

View file

@ -1,23 +0,0 @@
{ sources ? import ./sources.nix
, nixpkgsName ? "nixos-unstable" # match ./ci.nix isReferenceNixpkgs
, nixpkgsSrc ? sources.${nixpkgsName}
, system ? builtins.currentSystem
, dockerSupportsSystemd ? false
, nixosHasPodmanDockerSocket ? true
, ...
}:
import nixpkgsSrc ({
# Makes the config pure as well. See <nixpkgs>/top-level/impure.nix:
config = {
};
overlays = [
(_: _: {
arionTestingFlags = {
inherit dockerSupportsSystemd nixosHasPodmanDockerSocket;
};
})
(import ./overlay.nix)
];
inherit system;
})

View file

@ -1,16 +0,0 @@
self: super: hself: hsuper:
{
arion-compose = import ./haskell-arion-compose.nix { pkgs = self; haskellPackages = hself; };
arion-compose-checked =
let pkg = /* super.haskell.lib.buildStrictly currently broken in nixos-unstable */ hself.arion-compose;
checked = super.haskell.lib.overrideCabal pkg (o: {
postConfigure = ''${o.postConfigure or ""}
if ! ${hsuper.cabal-install}/bin/cabal check;
then
echo 1>&2 ERROR: cabal file is invalid. Above warnings were errors.
exit 1
fi
'';
});
in checked;
}

View file

@ -1,60 +0,0 @@
self: super:
let
inherit (self.arion-project) haskellPkgs;
inherit (super) lib;
sources = import ./sources.nix;
fakeRepo = src: super.runCommand "source" { inherit src; nativeBuildInputs = [super.git]; } ''
cp -r --no-preserve=mode $src $out
git init
cp -r .git $out
'';
in
{
inherit (import ./.. { pkgs = self; }) arion;
tests = super.callPackage ../tests {};
doc-options = import ../docs/options.nix {};
doc-options-check = self.runCommand "doc-options-check" {} ''
if diff --color -u ${../docs/modules/ROOT/partials/NixOSOptions.adoc} ${self.doc-options}; then
touch $out
else
echo 1>&2 "The doc options have changed and need to be added."
echo 1>&2 "Please run ./update-options in the root of your arion clone."
exit 1
fi
'';
doc = self.stdenv.mkDerivation {
name = "arion-documentation";
nativeBuildInputs = [super.antora];
src = fakeRepo ../.;
HOME = ".";
buildPhase = "antora antora-playbook";
installPhase = ''
mkdir $out
mv public/* $out/
'';
};
arion-project = super.recurseIntoAttrs {
haskellPkgs = super.haskellPackages.extend (import ./haskell-overlay.nix self super);
shell = haskellPkgs.shellFor {
packages = p: [p.arion-compose];
nativeBuildInputs = [
haskellPkgs.cabal-install
haskellPkgs.ghcid
haskellPkgs.haskell-language-server
super.docker-compose
self.niv
self.nixpkgs-fmt
self.releaser
];
};
};
inherit (import (sources.niv) {}) niv;
releaser = self.haskellPackages.callCabal2nix "releaser" sources.releaser {};
}

View file

@ -1,63 +0,0 @@
{
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",
"homepage": "https://github.com/nmattia/niv",
"owner": "nmattia",
"repo": "niv",
"rev": "fad2a6cbfb2e7cdebb7cb0ad2f5cc91e2c9bc06b",
"sha256": "0mghc1j0rd15spdjx81bayjqr0khc062cs25y5dcfzlxk4ynyc6m",
"type": "tarball",
"url": "https://github.com/nmattia/niv/archive/fad2a6cbfb2e7cdebb7cb0ad2f5cc91e2c9bc06b.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixos-22.05": {
"branch": "nixos-22.05",
"description": "Nix Packages collection",
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a634c8f6c1fbf9b9730e01764999666f3436f10a",
"sha256": "1d40v43x972li5fg7jadxkj341li41mf2cl6vv7xi6j80rkq45q4",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/a634c8f6c1fbf9b9730e01764999666f3436f10a.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixos-unstable": {
"branch": "lib-modules-allow-disable-_modules.args-docs-internal",
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
"homepage": "https://github.com/NixOS/nixpkgs",
"owner": "hercules-ci",
"repo": "nixpkgs",
"rev": "14aa201b658f43546b00153bb2ada7206ba8dd26",
"sha256": "0xn43gdn3rfys1d8ni3y6x7vxyc263qsbhfsjwc5x7pcd3dfrcjw",
"type": "tarball",
"url": "https://github.com/hercules-ci/nixpkgs/archive/14aa201b658f43546b00153bb2ada7206ba8dd26.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
"version": ""
},
"project.nix": {
"branch": "master",
"description": "A configuration manager for your projects",
"homepage": null,
"owner": "hercules-ci",
"repo": "project.nix",
"rev": "2e598501e7fda6993d2a1a281aa296b26d01e10c",
"sha256": "1rkzpzxpg69px6qwchdlg4xf5irv0snrzk2l6vrs9rsx48gqax9j",
"type": "tarball",
"url": "https://github.com/hercules-ci/project.nix/archive/2e598501e7fda6993d2a1a281aa296b26d01e10c.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"releaser": {
"branch": "master",
"description": "Automation of Haskell package release process.",
"homepage": null,
"owner": "domenkozar",
"repo": "releaser",
"rev": "52a2bb0b2ce0bc15d4e7b11d8761a28d82c0c083",
"sha256": "178lv0a0qxd8six0rm83j7wjwlsad1hysdrk4mb38fagbb8csagb",
"type": "tarball",
"url": "https://github.com/domenkozar/releaser/archive/52a2bb0b2ce0bc15d4e7b11d8761a28d82c0c083.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}

View file

@ -1,171 +0,0 @@
# This file has been generated by Niv.
let
#
# The fetchers. fetch_<type> fetches specs of type <type>.
#
fetch_file = pkgs: name: spec:
let
name' = sanitizeName name + "-src";
in
if spec.builtin or true then
builtins_fetchurl { inherit (spec) url sha256; name = name'; }
else
pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
fetch_tarball = pkgs: name: spec:
let
name' = sanitizeName name + "-src";
in
if spec.builtin or true then
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
else
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
fetch_git = name: spec:
let
ref =
if spec ? ref then spec.ref else
if spec ? branch then "refs/heads/${spec.branch}" else
if spec ? tag then "refs/tags/${spec.tag}" else
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
in
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
fetch_local = spec: spec.path;
fetch_builtin-tarball = name: throw
''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
$ niv modify ${name} -a type=tarball -a builtin=true'';
fetch_builtin-url = name: throw
''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
$ niv modify ${name} -a type=file -a builtin=true'';
#
# Various helpers
#
# https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
sanitizeName = name:
(
concatMapStrings (s: if builtins.isList s then "-" else s)
(
builtins.split "[^[:alnum:]+._?=-]+"
((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
)
);
# The set of packages used when specs are fetched using non-builtins.
mkPkgs = sources: system:
let
sourcesNixpkgs =
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in
if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> {}
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';
# The actual fetching function.
fetch = pkgs: name: spec:
if ! builtins.hasAttr "type" spec then
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
else if spec.type == "file" then fetch_file pkgs name spec
else if spec.type == "tarball" then fetch_tarball pkgs name spec
else if spec.type == "git" then fetch_git name spec
else if spec.type == "local" then fetch_local spec
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
else if spec.type == "builtin-url" then fetch_builtin-url name
else
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
# If the environment variable NIV_OVERRIDE_${name} is set, then use
# the path directly as opposed to the fetched source.
replace = name: drv:
let
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
in
if ersatz == "" then drv else ersatz;
# Ports of functions for older nix versions
# a Nix version of mapAttrs if the built-in doesn't exist
mapAttrs = builtins.mapAttrs or (
f: set: with builtins;
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
concatMapStrings = f: list: concatStrings (map f list);
concatStrings = builtins.concatStringsSep "";
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
optionalAttrs = cond: as: if cond then as else {};
# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else
fetchTarball attrs;
# fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, name ? null, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12" then
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else
fetchurl attrs;
# Create the final "sources" from the config
mkSources = config:
mapAttrs (
name: spec:
if builtins.hasAttr "outPath" spec
then abort
"The values in sources.json should not have an 'outPath' attribute"
else
spec // { outPath = replace name (fetch config.pkgs name spec); }
) config.sources;
# The "config" used by the fetchers
mkConfig =
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
, sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
, system ? builtins.currentSystem
, pkgs ? mkPkgs sources system
}: rec {
# The sources, i.e. the attribute set of spec name to spec
inherit sources;
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
inherit pkgs;
};
in
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }

View file

@ -1 +1 @@
args@{...}: (import ./nix args).arion-project.shell
(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default

View file

@ -9,6 +9,7 @@ import Prelude()
import Protolude hiding (to)
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Key as AK
import Arion.Aeson (decodeFile)
import Control.Lens
@ -20,4 +21,4 @@ getDefaultExec fp service = do
v <- decodeFile fp
pure ((v :: Aeson.Value) ^.. key "x-arion" . key "serviceInfo" . key service . key "defaultExec" . _Array . traverse . _String)
pure ((v :: Aeson.Value) ^.. key "x-arion" . key "serviceInfo" . key (AK.fromText service) . key "defaultExec" . _Array . traverse . _String)

View file

@ -117,6 +117,7 @@ in
description = dockerComposeRef "depends_on";
};
service.healthcheck = mkOption {
description = dockerComposeRef "healthcheck";
type = submodule ({ config, options, ...}: {
options = {
_out = mkOption {

View file

@ -1,4 +1,4 @@
{ usePodman ? false, pkgs, lib, ... }:
{ usePodman ? false, pkgs, lib ? pkgs.lib, ... }:
let
# To make some prebuilt derivations available in the vm

View file

@ -1,46 +0,0 @@
{ pkgs ? import ../pkgs.nix, arionTestingFlags ? {} }:
let
inherit (pkgs) nixosTest recurseIntoAttrs arion lib;
hasEvalModulesType = (lib.evalModules { modules = [ {} ]; })?type;
in
recurseIntoAttrs {
test = nixosTest ./arion-test;
nixosModuleWithDocker =
lib.optionalAttrs
hasEvalModulesType
(
import ./nixos-virtualization-arion-test/test.nix pkgs {
virtualisation.arion.backend = "docker";
}
);
nixosModuleWithPodman =
lib.optionalAttrs
(hasEvalModulesType && arionTestingFlags.nixosHasPodmanDockerSocket)
(
import ./nixos-virtualization-arion-test/test.nix pkgs {
virtualisation.arion.backend = "podman-socket";
}
);
testWithPodman =
if arionTestingFlags.nixosHasPodmanDockerSocket
then nixosTest (import ./arion-test { usePodman = true; inherit pkgs lib; })
else {};
testBuild = arion.build {
# To be more accurately, you can do
# pkgs = import ../examples/minimal/arion-pkgs.nix;
# but this is quite efficient:
inherit pkgs;
modules = [ ../examples/minimal/arion-compose.nix ];
};
}

35
tests/flake-module.nix Normal file
View file

@ -0,0 +1,35 @@
{
perSystem = { pkgs, final, ... }:
let
inherit (final) nixosTest arion lib;
in
{
checks = lib.optionalAttrs pkgs.stdenv.isLinux {
test = nixosTest ./arion-test;
nixosModuleWithDocker =
import ./nixos-virtualization-arion-test/test.nix final {
virtualisation.arion.backend = "docker";
};
nixosModuleWithPodman =
import ./nixos-virtualization-arion-test/test.nix final {
virtualisation.arion.backend = "podman-socket";
};
testWithPodman =
nixosTest (import ./arion-test { usePodman = true; pkgs = final; });
testBuild = arion.build {
# To be more accurate, we could do
# pkgs = import ../examples/minimal/arion-pkgs.nix;
# But let's avoid re-evaluating Nixpkgs
pkgs = final;
modules = [ ../examples/minimal/arion-compose.nix ];
};
};
};
}

View file

@ -1,9 +1,9 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash
#!nix-shell -i bash -p jq
set -eu -o pipefail
cd "$(dirname ${BASH_SOURCE[0]})"
doc_options="$(nix-build nix -A doc-options)"
doc_options="$(nix build .#doc-options --json | jq -r .[].outputs.out)"
cat "$doc_options" >docs/modules/ROOT/partials/NixOSOptions.adoc