mirror of
https://github.com/dhall-lang/dhall-kubernetes.git
synced 2024-09-17 10:27:08 +03:00
2ed2ffd073
This improves the documentation and scripts responsible for generating files. The main changes from the user's point of view are: * The `generate` script now supports four subcommands: * `generate kubernetes` - Generate all Kubernetes bindings * `generate examples` - Generate examples for the preferred Kubernetes version * `generate readme` - Generate the README from the Dhall template * `generate preferred` - Generate top-level files that re-export the preferred Kubernetes version The `generate` script without arguments generates everything * Generation should be faster and more incremental now For example, regenerating the `README` by itself should go more quickly since it no longer requires regenerating any examples or Kubernetes bindings if they haven't changed This required overhauling the internal Nix code for generating these files to support more granular builds. Another consequence of this change is that the preferred Kubernetes version no longer packages `Prelude.dhall`, `README.dhall` or the `examples`. Those are now only stored within the top-level directory.
155 lines
5.1 KiB
Nix
155 lines
5.1 KiB
Nix
let
|
|
spec = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
|
|
|
|
nixpkgs = builtins.fetchGit {
|
|
inherit (spec) url rev;
|
|
};
|
|
|
|
overlay = pkgsNew: pkgsOld: {
|
|
make-dhall-kubernetes = spec:
|
|
let
|
|
frozenFiles = [
|
|
"defaults.dhall"
|
|
"types.dhall"
|
|
"schemas.dhall"
|
|
"typesUnion.dhall"
|
|
"package.dhall"
|
|
];
|
|
|
|
freeze = file: ''
|
|
echo 'Freezing ./${file}'
|
|
${pkgsNew.coreutils}/bin/chmod u+w "$out/${file}"
|
|
${pkgsNew.dhall}/bin/dhall freeze --all --inplace "$out/${file}"
|
|
echo 'Checking ./${file}'
|
|
${pkgsNew.dhall}/bin/dhall type --quiet --file "$out/${file}"
|
|
'';
|
|
|
|
in
|
|
pkgsNew.runCommand "dhall-${spec.name}" { XDG_CACHE_HOME=".cache"; } ''
|
|
${pkgsNew.coreutils}/bin/mkdir "$out"
|
|
cd $out
|
|
${pkgsNew.haskellPackages.dhall-openapi}/bin/openapi-to-dhall '${spec}'
|
|
${pkgsNew.lib.concatMapStringsSep "\n" freeze frozenFiles}
|
|
${pkgsNew.coreutils}/bin/rm --recursive .cache
|
|
'';
|
|
|
|
examples =
|
|
let
|
|
preferredVersion =
|
|
let
|
|
preferredVersionText = builtins.readFile ./preferred.txt;
|
|
|
|
in
|
|
builtins.replaceStrings [ "\n" ] [ "" ] preferredVersionText;
|
|
|
|
examplePaths =
|
|
pkgsNew.lib.filterAttrs (name: _: name != "out")
|
|
(builtins.readDir ../examples);
|
|
|
|
exampleNames =
|
|
pkgsNew.lib.mapAttrsToList
|
|
(name: _: builtins.replaceStrings [ ".dhall" ] [ "" ] name)
|
|
examplePaths;
|
|
|
|
copyExample =
|
|
example: "${pkgsNew.coreutils}/bin/cp ${./../examples + "/${example}.dhall"} ./examples/${example}.dhall";
|
|
|
|
freeze = example:
|
|
let
|
|
file = "./examples/${example}.dhall";
|
|
|
|
in
|
|
''
|
|
echo 'Freezing ${file}'
|
|
${pkgsNew.coreutils}/bin/chmod u+w ${file}
|
|
${pkgsNew.dhall}/bin/dhall freeze --all --inplace ${file}
|
|
echo 'Checking ${file}'
|
|
${pkgsNew.dhall}/bin/dhall type --quiet --file ${file}
|
|
'';
|
|
|
|
|
|
buildExample =
|
|
example:
|
|
let
|
|
inputFile = "./examples/${example}.dhall";
|
|
|
|
outputFile = "./examples/out/${example}.yaml";
|
|
|
|
in
|
|
''
|
|
echo '${inputFile} → ${outputFile}'
|
|
${pkgsNew.dhall-json}/bin/dhall-to-yaml --file ${inputFile} > ${outputFile}
|
|
'';
|
|
|
|
in
|
|
pkgsNew.runCommand "examples" { XDG_CACHE_HOME=".cache"; } ''
|
|
${pkgsNew.coreutils}/bin/mkdir --parents ./examples/out
|
|
${pkgsNew.lib.concatMapStringsSep "\n" copyExample exampleNames}
|
|
${pkgsNew.coreutils}/bin/cp ${../Prelude.dhall} ./Prelude.dhall
|
|
${pkgsNew.rsync}/bin/rsync --recursive ${pkgsNew.dhall-kubernetes."${preferredVersion}"}/ ./
|
|
${pkgsNew.lib.concatMapStringsSep "\n" freeze exampleNames}
|
|
${pkgsNew.lib.concatMapStringsSep "\n" buildExample exampleNames}
|
|
${pkgsNew.coreutils}/bin/mkdir "$out"
|
|
${pkgsNew.rsync}/bin/rsync --recursive ./examples/ $out/
|
|
'';
|
|
|
|
readme =
|
|
pkgsNew.runCommand "README.md" {} ''
|
|
${pkgsNew.coreutils}/bin/mkdir ./docs
|
|
${pkgsNew.coreutils}/bin/ln --symbolic ${pkgsNew.examples} ./examples
|
|
${pkgsNew.coreutils}/bin/ln --symbolic ${../docs/README.md.dhall} ./docs/README.md.dhall
|
|
|
|
${pkgsNew.dhall}/bin/dhall text --file "./docs/README.md.dhall" | ${pkgsNew.gnused}/bin/sed 's_\.\./package.dhall_https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/master/package.dhall_g' > "$out"
|
|
'';
|
|
|
|
dhall-kubernetes = pkgsNew.callPackage ./dhall-kubernetes.nix {};
|
|
|
|
dhall-kubernetes-tests =
|
|
let
|
|
process = version: derivation: {
|
|
name = "${version}-test";
|
|
value =
|
|
pkgsNew.runCommand "test-dhall-kubernetes-${version}" {} ''
|
|
${pkgsNew.rsync}/bin/rsync --archive ${derivation}/ ./${version}.expected
|
|
${pkgsNew.rsync}/bin/rsync --archive ${../. + "/${version}"}/ ./${version}.actual
|
|
|
|
${pkgsNew.diffutils}/bin/diff --recursive ./${version}.{actual,expected}
|
|
|
|
touch $out
|
|
'';
|
|
};
|
|
|
|
in
|
|
pkgsNew.lib.mapAttrs' process pkgsNew.dhall-kubernetes;
|
|
|
|
haskellPackages = pkgsOld.haskellPackages.override (old: {
|
|
overrides =
|
|
let
|
|
previous = old.overrides or (_: _: {});
|
|
|
|
extension = haskellPackagesNew: haskellPackagesOld: {
|
|
dhall-openapi =
|
|
let
|
|
json =
|
|
builtins.fromJSON (builtins.readFile ./dhall-haskell.json);
|
|
|
|
dhall-haskell = pkgsNew.fetchFromGitHub {
|
|
owner = "dhall-lang";
|
|
repo = "dhall-haskell";
|
|
inherit (json) rev sha256 fetchSubmodules;
|
|
};
|
|
|
|
in
|
|
(import "${dhall-haskell}/default.nix").dhall-openapi;
|
|
|
|
};
|
|
|
|
in
|
|
pkgsNew.lib.composeExtensions (_: _: {}) extension;
|
|
}
|
|
);
|
|
};
|
|
|
|
in
|
|
import nixpkgs { config = {}; overlays = [ overlay ]; }
|