diff --git a/coq-nix-toolbox.nix.mustache b/coq-nix-toolbox.nix.mustache new file mode 100644 index 0000000..0679266 --- /dev/null +++ b/coq-nix-toolbox.nix.mustache @@ -0,0 +1,4 @@ +# This file was generated from meta.yml, please do not edit manually. +# Follow the instructions on https://github.com/coq-community/templates to regenerate. +# However, it not handled by mustache, but by a special eval command +\"$(git ls-remote https://github.com/coq-community/coq-nix-toolbox refs/heads/master | cut -f1)\" \ No newline at end of file diff --git a/default.nix.mustache b/default.nix.mustache index a69ae3c..457bfd9 100644 --- a/default.nix.mustache +++ b/default.nix.mustache @@ -1,36 +1,36 @@ # This file was generated from `meta.yml`, please do not edit manually. # Follow the instructions on https://github.com/coq-community/templates to regenerate. - -{ pkgs ? (import {}), coq-version-or-url, shell ? false }: - +{{# nix-default}} +{ config ? {}, withEmacs ? false, print-env ? false, do-nothing ? false, + update-nixpkgs ? false, ci-matrix ? false, ci-job ? null, + override ? {}, ocaml-override ? {}, global-override ? {}, + ci ? (!isNull ci-job), inNixShell ? null +}@args: let - coq-version-parts = builtins.match "([0-9]+).([0-9]+)" coq-version-or-url; - coqPackages = - if coq-version-parts == null then - pkgs.mkCoqPackages (import (fetchTarball coq-version-or-url) {}) - else - pkgs."coqPackages_${builtins.concatStringsSep "_" coq-version-parts}"; +{{# src}} + auto = {{src}}; +{{/ src}} +{{^ src}} + auto = let p = ./nix/.coq-nix-toolbox.nix; in fetchGit { + url = "{{url}}{{^ url}}https://github.com/{{owner}}{{^ owner}}coq-community{{/ owner}}/coq-nix-toolbox.git{{/ url}}"; + ref = "{{ref}}{{^ ref}}master{{/ ref}}"; + rev = import ./.nix/coq-nix-toolbox.nix; + }; +{{/ src}} in +(import auto ({src = ./.;} // args)).{{attribute}}{{^ attribute}}nix-auto{{/ attribute}} +{{/ nix-default}} +{{^ nix-default}} +{ config ? {}, withEmacs ? false, print-env ? false, do-nothing ? false, + update-nixpkgs ? false, ci-matrix ? false, ci-job ? null, + override ? {}, ocaml-override ? {}, global-override ? {}, + ci ? (!isNull ci-job), inNixShell ? null +}@args: +let auto = fetchGit { + url = "https://github.com/coq-community/coq-nix-toolbox.git"; + ref = "master"; + rev = import ./.nix/coq-nix-toolbox.nix; +}; in +(import auto ({src = ./.;} // args)).nix-auto +{{/ nix-default}} -with coqPackages; - -pkgs.stdenv.mkDerivation { - - name = "{{ shortname }}"; - -{{# plugin }} - buildInputs = with coq.ocamlPackages; [ ocaml findlib ] - ++ pkgs.lib.optionals shell [ merlin ocp-indent ocp-index ]; - -{{/ plugin }} - propagatedBuildInputs = [ - coq -{{# dependencies }} - {{ nix }} -{{/ dependencies }} - ]; - - src = if shell then null else ./.; - - installFlags = "COQMF_COQLIB=$(out)/lib/coq/${coq.coq-version}/"; -} diff --git a/fallback-config.nix.mustache b/fallback-config.nix.mustache new file mode 100644 index 0000000..2ea2001 --- /dev/null +++ b/fallback-config.nix.mustache @@ -0,0 +1,77 @@ +# This file was generated from `meta.yml`, please do not edit manually. +# Follow the instructions on https://github.com/coq-community/templates to regenerate. + +# *However*, you may copy paste it to `config.nix` +# in the same subdirectory .nix and extend it as needed. +# Note that this would completely deactivate this file. + +{ + ## DO NOT CHANGE THIS + format = "1.0.0"; + ## unless you made an automated or manual update + ## to another supported format. + + ## The attribute to build, either from nixpkgs + ## of from the overlays located in `.nix/coq-overlays` + coq-attribute = "{{nix_name}}"; + + ## If you want to select a different attribute + ## to serve as a basis for nix-shell edit this + # coq-shell-attribute = "{{nix_name}}"; + + ## Maybe the shortname of the library is different from + ## the name of the nixpkgs attribute, if so, set it here: + {{^ shortname}}#{{/ shortname}}pname = "{{ shortname }}"; + + ## Lists the dependencies, phrased in terms of nix attributes. + ## No need to list Coq, it is already included. + ## These dependencies will systematically be added to the currently + ## known dependencies, if any more than Coq. + ## /!\ Remove this field as soon as the package is available on nixpkgs. + ## /!\ Manual overlays in `.nix/coq-overlays` should be preferred then. + {{^ nix-dependencies}}#{{/ nix-dependencies}}buildInputs = [ {{# nix-dependencies }}"{{.}}" {{/ nix-dependencies }}]; + + ## Indicate the relative location of your _CoqProject + ## If not specified, it defaults to "_CoqProject" + # coqproject = "_CoqProject"; + + ## select an entry to build in the following `tasks` set + ## defaults to "default" + select = "default"; + + ## write one `tasks.name` attribute set per + ## alternative configuration, the can be used to + ## compute several ci jobs as well + tasks.default = { + + ## You can override Coq and other Coq coqPackages + ## through the following attribute + # coqPackages.coq.override.version = "8.11"; + + ## In some cases, light overrides are not available/enough + ## in which case you can use either + # coqPackages..overrideAttrs = o: ; + ## or a "long" overlay to put in `.nix/coq-overlays + ## you may use `nix-shell --run fetchOverlay ` + ## to automatically retrieve the one from nixpkgs + ## if it exists and is correctly named/located + + ## You can override Coq and other Coq coqPackages + ## throught the following attribute + ## If does not support lights overrides, + ## you may use `overrideAttrs` or long overlays + ## located in `.nix/ocaml-overlays` + ## (there is no automation for this one) + # ocamlPackages..override.version = "x.xx"; + + ## You can also override packages from the nixpkgs toplevel + # .override.overrideAttrs = o: ; + ## Or put an overlay in `.nix/overlays` + + ## you may mark a package as a CI job as follows + # coqPackages..ci.job = "test"; + ## It can then be built throught + ## nix-build --argstr ci "default" --arg ci-job "test"; + + }; +} diff --git a/generate.sh b/generate.sh index 0402135..84f85a3 100755 --- a/generate.sh +++ b/generate.sh @@ -14,20 +14,21 @@ get_yaml() { for f in "$srcdir"/{,.}*.mustache; do target=$(basename "$f" .mustache) + eval_instead_of_mustache=false case "$target" in coq.opam) mustache='{{ opam_name }}' opam_name=$(get_yaml meta.yml <<<"$mustache") - if [ -n "$opam_name" ]; then - target=${target/coq/$opam_name} - else - mustache='{{ shortname }}' - shortname=$(get_yaml meta.yml <<<"$mustache") - if [ -n "$shortname" ]; then - target=${target/coq/coq-$shortname} + if [ -n "$opam_name" ]; then + target=${target/coq/$opam_name} else - continue - fi + mustache='{{ shortname }}' + shortname=$(get_yaml meta.yml <<<"$mustache") + if [ -n "$shortname" ]; then + target=${target/coq/coq-$shortname} + else + continue + fi fi ;; extracted.opam) @@ -95,20 +96,39 @@ for f in "$srcdir"/{,.}*.mustache; do continue fi ;; - config.yml) - mustache='{{ circleci }}' - bool=$(get_yaml meta.yml <<<"$mustache") + config.yml) + mustache='{{ circleci }}' + bool=$(get_yaml meta.yml <<<"$mustache") + if [ -n "$bool" ] && [ "$bool" != false ]; then + mkdir -p -v .circleci && target=".circleci/$target" + else + continue + fi + ;; + default.nix) + mustache='{{ nix }}' + bool=$(get_yaml meta.yml <<<"$mustache") if [ -n "$bool" ] && [ "$bool" != false ]; then - mkdir -p -v .circleci && target=".circleci/$target" + : noop else continue fi ;; - default.nix) + coq-nix-toolbox.nix) mustache='{{ nix }}' bool=$(get_yaml meta.yml <<<"$mustache") if [ -n "$bool" ] && [ "$bool" != false ]; then - : noop + mkdir -p -v .nix && target=".nix/$target" + eval_instead_of_mustache=true + else + continue + fi + ;; + fallback-config.nix) + mustache='{{ nix }}' + bool=$(get_yaml meta.yml <<<"$mustache") + if [ -n "$bool" ] && [ "$bool" != false ]; then + mkdir -p -v .nix && target=".nix/$target" else continue fi @@ -123,6 +143,10 @@ for f in "$srcdir"/{,.}*.mustache; do if [ $# -gt 0 ] && [ $listed != true ]; then continue fi - echo "Generating $target..." - mustache meta.yml "$f" > "$target" + echo "Generating $target" + if [ "$eval_instead_of_mustache" = true ]; then + eval "echo \"$(cat $f)\"" > "$target" + else + mustache meta.yml "$f" > "$target" + fi done diff --git a/nix-action.yml.mustache b/nix-action.yml.mustache index 68b52fa..8bdc694 100644 --- a/nix-action.yml.mustache +++ b/nix-action.yml.mustache @@ -1,39 +1,139 @@ # This file was generated from `meta.yml`, please do not edit manually. # Follow the instructions on https://github.com/coq-community/templates to regenerate. +{{!# From now on we switch template variable syntax to <%X%>}} +{{=<% %>=}} name: Nix CI on: push: branches: - - {{branch}}{{^branch}}master{{/branch}} + - <%branch%><%^branch%>master<%/branch%> pull_request: branches: - '**' jobs: - build: + dependencies: runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Cachix install + uses: cachix/install-nix-action@v12 + with: + nix_path: nixpkgs=channel:nixpkgs-unstable +<%# cachix%> + - name: Cachix setup <%name%> + uses: cachix/cachix-action@v8 + with: + # Name of a cachix cache to pull/substitute + name: <%name%> +<%# key%> + signingKey: '${{ secrets.<%key%> }}' +<%/ key%> +<%# token%> + authToken: '${{ secrets.<%token%> }}' +<%/ token%> +<%/ cachix%> + - name: Git checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 +<%# submodule %> + - name: Checkout submodules + uses: textbook/git-checkout-submodule-action@2.1.1 +<%/ submodule %> +<%! Change delimiters to avoid the next line being parsed as mustache syntax. %> + - name: Building/fetching dependencies + run: nix-build --no-out-link --argstr ci-job dependencies + - name: Setup build matrix + id: set-matrix + run: | + matrix=$(nix-shell --arg do-nothing true --run nixTasks) + echo ::set-output name=matrix::{\"task\":$(echo $matrix)}\" + + main: + runs-on: ubuntu-latest + needs: + - dependencies strategy: - matrix: - version_or_url: -{{# tested_coq_nix_versions }} - - '{{ version_or_url }}' -{{/ tested_coq_nix_versions }}{{^ tested_coq_nix_versions }} - 'https://github.com/coq/coq-on-cachix/tarball/master' -{{/ tested_coq_nix_versions }} - fail-fast: false + matrix: ${{fromJson(needs.dependencies.outputs.matrix)}} steps: - - uses: cachix/install-nix-action@v12 - with: - nix_path: nixpkgs=channel:nixpkgs-unstable - - uses: cachix/cachix-action@v8 - with: - # Name of a cachix cache to pull/substitute - name: coq - - uses: actions/checkout@v2 -{{# submodule }} - - name: Checkout submodules - uses: textbook/git-checkout-submodule-action@2.1.1 -{{/ submodule }} -{{! Change delimiters to avoid the next line being parsed as mustache syntax. }} -{{=<% %>=}} - - run: nix-build --argstr coq-version-or-url "${{ matrix.version_or_url }}" + - name: Cachix install + uses: cachix/install-nix-action@v12 + with: + nix_path: nixpkgs=channel:nixpkgs-unstable +<%# cachix%> + - name: Cachix setup <%name%> + uses: cachix/cachix-action@v8 + with: + # Name of a cachix cache to pull/substitute + name: <%name%> +<%# key%> + signingKey: '${{ secrets.<%key%> }}' +<%/ key%> +<%# token%> + authToken: '${{ secrets.<%token%> }}' +<%/ token%> +<%/ cachix%> + - name: Git checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 +<%# submodule %> + - name: Checkout submodules + uses: textbook/git-checkout-submodule-action@2.1.1 +<%/ submodule %> +<%! Change delimiters to avoid the next line being parsed as mustache syntax. %> + - name: Building/fetching dependencies + run: nix-build --no-out-link --argstr ci "${{ matrix.task }}" --argstr ci-job dependencies + - name: Building/fetching current project + run: nix-build --no-out-link --argstr ci "${{ matrix.task }}" --argstr ci-job main + +<%# nix-ci%> + <%name%><%^ name%><%job%><%^ job%>all<%/ job%><%/ name%>: + runs-on: ubuntu-latest + needs: + - dependencies +<%# needs%> + - <%.%> +<%/ needs%> +<%^ needs%> + - main +<%/ needs%> + strategy: + matrix: ${{fromJson(needs.dependencies.outputs.matrix)}} + steps: + - name: Cachix install + uses: cachix/install-nix-action@v12 + with: + nix_path: nixpkgs=channel:nixpkgs-unstable +<%# cachix%> + - name: Cachix setup <%name%> + uses: cachix/cachix-action@v8 + with: + # Name of a cachix cache to pull/substitute + name: <%name%> +<%# key%> + signingKey: '${{ secrets.<%key%> }}' +<%/ key%> +<%# token%> + authToken: '${{ secrets.<%token%> }}' +<%/ token%> +<%/ cachix%> + - name: Git checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 +<%# submodule %> + - name: Checkout submodules + uses: textbook/git-checkout-submodule-action@2.1.1 +<%/ submodule %> +<%! Change delimiters to avoid the next line being parsed as mustache syntax. %> + - name: Building/fetching dependencies + run: nix-build --no-out-link --argstr ci "${{ matrix.task }}" --argstr ci-job dependencies + - name: Building/fetching current project + run: nix-build --no-out-link --argstr ci "${{ matrix.task }}" --argstr ci-job main + - name: Building/fetching current CI target + run: nix-build --no-out-link --argstr ci "${{ matrix.task }}" --argstr ci-job <%job%><%^ job%>all<%/ job%> +<%/ nix-ci%> \ No newline at end of file diff --git a/ref.yml b/ref.yml index 19d4325..e2a6fab 100644 --- a/ref.yml +++ b/ref.yml @@ -40,6 +40,11 @@ fields: - docker-action.yml - dune-project - dune + - nix_name: + required: false + default: "{{ shortname }}" + used: + - fallback-config.nix - organization: required: true used: @@ -246,7 +251,8 @@ fields: required: true description: > The list of Coq packages in nixpkgs can be seen here: - https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/top-level/coq-packages.nix + https://github.com/NixOS/nixpkgs/blob/\ + nixpkgs-unstable/pkgs/top-level/coq-packages.nix Casing matters and might differ from the opam name. The leading coq- is present only if it is really an integral part of the package name. @@ -341,7 +347,7 @@ fields: type: list item_fields: - description: - requied: true + required: true used: - README.md - extracted.opam @@ -360,7 +366,8 @@ fields: required: true description: > Docker tag supported by coqorg/coq: - https://github.com/coq-community/docker-coq/wiki#supported-tags + https://github.com/coq-community/docker-coq/wiki\ + #supported-tags. Quote the strings, otherwise '8.10' becomes '8.1'. examples: - '8.11' @@ -392,29 +399,119 @@ fields: used: - coq.opam - .travis.yml - - tested_coq_nix_versions: + - cachix: + used: + - nix-action.yml.nix type: list - description: If empty, the master branch of Coq will be tested. + description: Cachix repositories to use item_fields: - - version_or_url: + - name: required: true - description: > - This can be a version number of a version packaged in - nixpkgs (example: 8.5, 8.11). Cf. the coqPackages_8_XX - attributes defined at the end of this file: - https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/top-level/coq-packages.nix - (Quote the version number, otherwise '8.10' becomes '8.1'.) - - Or this can be a URL, to test your project with a - version of Coq under development. Typically this is - https://github.com/coq/coq-on-cachix/tarball/master but - 'master' may be replaced by any valid reference like one - of the branches available at - https://github.com/coq/coq-on-cachix/branches or a valid - commit hash. + description: Name of the cachix repository + examples: + - "coq" + - "math-comp" + - key: + required: false + description: | + Secret signingKey for the repository, the secret should + be set from GitHub interface in + https://github.com/OWNER/REPO/settings/secrets/actions + and generated from https://cachix.org + /!\ This is the legacy authentification method and + should be deprecated in favor of `token` below. + example: + - "CACHIX_SIGNING_KEY" + - token: + required: false + description: | + Secret authToken for the repository, the secret should + be set from GitHub interface in + https://github.com/OWNER/REPO/settings/secrets/actions + and generated from https://cachix.org + example: + - "CACHIX_AUTH_TOKEN" + - nix-default: used: - - .travis.yml - - nix-action.yml + - default.nix + description: > + Configure the default.nix to fetch from the generic coq nix toolbox + fields: + - src: + required: false + type: string + description: Sets a local path instead of a github source + examples: + - "~/git/coq-nix-toolbox/master" + - url: + required: false + type: string + description: Change the git url to fetch from + default: "https://github.com/coq-community/coq-nix-toolbox.git" + - owner: + required: false + type: string + description: Switch to the github fork of another "owner" + default: "coq-community" + - ref: + required: false + type: string + description: Change the branch of coq-nix-toolbox to clone + default: master + - nix-dependencies: + used: + - fallback-config.nix + description: | + Lists the dependencies, phrased in terms of nix attributes. + No need to list Coq, it is already included. + These dependencies will systematically be added to the currently + known dependencies, if any more than Coq. + /!\ Remove this field as soon as the package is available on nixpkgs. + /!\ Manual overlays in `.nix/coq-overlays` should be preferred then. + required: false + type: list + item_fields: + type: string + description: nix attribute of a dependency + example: + - "mathcomp" + - "coquelicot" + - nix-ci: + used: + - nix-action.yml.nix + description: | + Generate a nix github action using the following metadata and + the contents of the `.nix/config.nix` file, that the user must + create. Otherwise, this attribute cannot be of any use. + /!\ It is strongly recommended to activate cachix with at least + /!\ the coq cachix activated `cachix: [ {"name": "coq" } ]`` + type: list + item_fields: + - job: + required: false + type: string + description: | + The name of the job as described in `.nix/config.nix` + as in e.g. tasks..coqPackages..ci.job = ; + The default is a `all` job which will run **everything** + default: "all" + - name: + required: false + type: string + description: | + The name to display in the github action web interface. + Defaults to the job above. + example: "My job" + - needs: + required: false + type: list + description: | + The list of jobs to wait for before executing these ones. + default: "main" + item_fields: + required: false + type: string + description: A job to wait for - tested_coq_opam_versions: type: list item_fields: