Use flake-parts
This commit is contained in:
parent
8159c4faa3
commit
4aff7e3a11
16 changed files with 210 additions and 478 deletions
|
@ -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
20
docs/flake-module.nix
Normal 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
|
||||
'';
|
||||
};
|
||||
}
|
56
flake.lock
56
flake.lock
|
@ -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": 1649668654,
|
||||
"narHash": "sha256-XLLs2mjsnl4Yl9rBpfEwgvm+Tzd+RIta0N7lYdsbxHY=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "14aa201b658f43546b00153bb2ada7206ba8dd26",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "14aa201b658f43546b00153bb2ada7206ba8dd26",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-parts": "flake-parts",
|
||||
"haskell-flake": "haskell-flake",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
|
|
125
flake.nix
125
flake.nix
|
@ -1,44 +1,91 @@
|
|||
{
|
||||
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;
|
||||
};
|
||||
|
||||
nixosModules.arion = ./nixos-module.nix;
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/14aa201b658f43546b00153bb2ada7206ba8dd26"; # TODO nixos-unstable
|
||||
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";
|
||||
};
|
||||
|
||||
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
|
||||
];
|
||||
# FIXME use: systems = inputs.nixpkgs.lib.systems.flakeExposed;
|
||||
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||
perSystem = { config, self', inputs', pkgs, system, final, ... }:
|
||||
let h = pkgs.haskell.lib.compose; in
|
||||
{
|
||||
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 = ./.;
|
||||
|
||||
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;
|
||||
build = args@{ ... }:
|
||||
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"
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
46
nix/ci.nix
46
nix/ci.nix
|
@ -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
10
nix/compat.nix
Normal 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
|
|
@ -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;
|
||||
})
|
|
@ -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;
|
||||
}
|
|
@ -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 {};
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
171
nix/sources.nix
171
nix/sources.nix
|
@ -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); }
|
|
@ -1 +1 @@
|
|||
args@{...}: (import ./nix args).arion-project.shell
|
||||
(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{ usePodman ? false, pkgs, lib, ... }:
|
||||
{ usePodman ? false, pkgs, lib ? pkgs.lib, ... }:
|
||||
|
||||
let
|
||||
# To make some prebuilt derivations available in the vm
|
||||
|
|
|
@ -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
35
tests/flake-module.nix
Normal 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 ];
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue