From 46b7d349c3cb7f9f228fdfbc39119801ab38a233 Mon Sep 17 00:00:00 2001 From: Quentin Guilloteau Date: Thu, 11 Jul 2024 16:05:08 +0200 Subject: [PATCH] Add POC for using nickel as a configuration lang The `check.ncl` file contains the commands what we could use directly from snakemake to validate the configs and generate the json/yaml for ecg --- artifact_contract.ncl | 59 ++++++++++++++++++++++++++++++++++++ artifacts_nickel/example.ncl | 14 +++++++++ check.ncl | 4 +++ flake.nix | 1 + 4 files changed, 78 insertions(+) create mode 100644 artifact_contract.ncl create mode 100644 artifacts_nickel/example.ncl create mode 100644 check.ncl diff --git a/artifact_contract.ncl b/artifact_contract.ncl new file mode 100644 index 0000000..cbb50cd --- /dev/null +++ b/artifact_contract.ncl @@ -0,0 +1,59 @@ +let + conf = { + ARCHIVE_FORMATS = [ "zip", "tar" ], + PACKAGE_MANAGERS = [ "dpkg", "conda", "pip"] + } +in +{ + PackageManager = std.contract.from_predicate ( + fun value => std.array.any (fun x => x == value) conf.PACKAGE_MANAGERS + ), + ArchiveType = std.contract.from_predicate ( + fun value => std.array.any (fun x => x == value) conf.ARCHIVE_FORMATS + ), + GitPackage = { + name + | doc "Name of the package for future identification" + | String, + location + | doc "Path where cloned in the container" + | String + }, + MiscPackage = { + name + | doc "Name of the package for future identification" + | String, + url + | doc "URL of the package. Will be used to compute the hash" + | String, + type + | doc "Type of the archive (zip, tar, ...)" + | ArchiveType, + }, + Artifact = { + artefact_url + | doc "URL where to download the artifact" + | String, + type + | doc "Type of the archive (zip, tar, ...)" + | ArchiveType, + doi + | doc "DOI of the artifact" + | String, + image_name + | doc "Name to give the image when building" + | String, + location + | doc "Path to the dockerfile in the artifact" + | String, + package_managers + | doc "Package Managers used in the container" + | Array PackageManager, + git_packages + | doc "Git repositories cloned in the container" + | Array GitPackage, + misc_packages + | doc "Misc. packages downloaded from the container" + | Array MiscPackage, + } +} diff --git a/artifacts_nickel/example.ncl b/artifacts_nickel/example.ncl new file mode 100644 index 0000000..732f293 --- /dev/null +++ b/artifacts_nickel/example.ncl @@ -0,0 +1,14 @@ +{ + artefact_url = "https://example.com/artifact.zip", + type = "zip", + doi = "...", + image_name = "image:version", + location = "path/to/docker/folder", + package_managers = [ "dpkg" ], + git_packages = [ + { name = "pkg1", location = "path/to/git/repo"} + ], + misc_packages = [ + { name = "mpkg1", url = "https://", type = "zip" } + ], +} diff --git a/check.ncl b/check.ncl new file mode 100644 index 0000000..aa87899 --- /dev/null +++ b/check.ncl @@ -0,0 +1,4 @@ +let { Artifact, .. } = import "artifact_contract.ncl" in +( + (import "artifacts_nickel/example.ncl") | Artifact +) diff --git a/flake.nix b/flake.nix index fab3a1e..11b75a3 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,7 @@ devShells = { default = pkgs.mkShell { packages = with pkgs; [ + nickel (python3.withPackages (ps: with ps; [ requests pyyaml -- 2.39.5