diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..1e71ffbc --- /dev/null +++ b/.envrc @@ -0,0 +1,4 @@ +# shellcheck shell=bash +# For use with direnv. +# Installing nix-direnv will ensure a smoother experience. +use flake \ No newline at end of file diff --git a/.nix/catala.nix b/.nix/catala.nix deleted file mode 100644 index 06869e25..00000000 --- a/.nix/catala.nix +++ /dev/null @@ -1,81 +0,0 @@ -{ lib -, alcotest -, ansiterminal -, benchmark -, bindlib -, buildDunePackage -, cmdliner -, cppo -, dates_calc -, js_of_ocaml -, js_of_ocaml-ppx -, menhir -, menhirLib -, ocamlgraph -, pkgs -, ppx_deriving -, ppx_yojson_conv -, re -, sedlex -, ubase -, unionfind -, visitors -, z3 -, zarith -, zarith_stubs_js -, ocaml-crunch -, cohttp-lwt-unix -, ocolor -, dune-build-info -}: - -buildDunePackage { - pname = "catala"; - version = "0.8.0"; # TODO parse `catala.opam` with opam2json - - minimumOCamlVersion = "4.11"; - - src = ../.; - - duneVersion = "3"; - - nativeBuildInputs = [ cppo menhir ocaml-crunch ]; - - propagatedBuildInputs = [ - alcotest - ansiterminal - benchmark - bindlib - cmdliner - dates_calc - js_of_ocaml - js_of_ocaml-ppx - menhirLib - ocamlgraph - pkgs.z3 - ppx_deriving - ppx_yojson_conv - re - sedlex - ubase - unionfind - visitors - z3 - zarith - zarith_stubs_js - cohttp-lwt-unix - ocolor - dune-build-info - ]; - - # Currently there is no unit tests in catala and Cram tests are handled by clerk - doCheck = false; - - meta = with lib; { - homepage = "https://catala-lang.org"; - description = - "Catala is a domain-specific programming language designed for deriving correct-by-construction implementations from legislative texts."; - license = licenses.asl20; - maintainers = with maintainers; [ ]; - }; -} diff --git a/.nix/clerk.nix b/.nix/clerk.nix deleted file mode 100644 index 7d269b78..00000000 --- a/.nix/clerk.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ lib -, buildDunePackage -, odoc -, re -, ansiterminal -, cmdliner -, ninja_utils -, alcotest -, catala -, ninja -, colordiff -}: - -buildDunePackage { - pname = "clerk"; - version = "0.8.0"; # TODO parse `catala.opam` with opam2json - - minimumOCamlVersion = "4.11"; - - src = ../.; - - duneVersion = "3"; - - propagatedBuildInputs = [ - odoc - re - ansiterminal - cmdliner - ninja_utils - alcotest - catala - ]; - - # todo: the current colordiff in nixpkgs always prints the banner. This make the logs totally unreadable. - nativeBuildInputs = [ catala ninja colordiff ]; - doCheck = true; - - meta = with lib; { - homepage = "https://github.com/CatalaLang/catala"; - description = - "Build system for Catala, a specification language for tax and social benefits computation rules"; - license = licenses.asl20; - maintainers = with maintainers; [ ]; - }; -} diff --git a/.nix/dates_calc.nix b/.nix/dates_calc.nix deleted file mode 100644 index d32e7c7b..00000000 --- a/.nix/dates_calc.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ lib, fetchurl, buildDunePackage }: - -buildDunePackage rec { - pname = "dates_calc"; - version = "0.0.4"; - - minimumOCamlVersion = "4.11.0"; - - duneVersion = "2"; - - src = fetchurl - { - url = "https://github.com/CatalaLang/dates-calc/archive/${version}.tar.gz"; - sha256 = "sha256-lWhNBK50r3qhY3PXRHZVvqDee6Y4+3vC51ZfjLxGryg="; - }; -} diff --git a/.nix/french_law.nix b/.nix/french_law.nix deleted file mode 100644 index ff5c73e0..00000000 --- a/.nix/french_law.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ lib -, buildDunePackage -, odoc -, catala -}: - -buildDunePackage { - pname = "french_law"; - version = "0.8.0"; # TODO parse `catala.opam` with opam2json - - minimumOCamlVersion = "4.11"; - - src = ../.; - - duneVersion = "3"; - - propagatedBuildInputs = [ - odoc - catala - ]; - - nativeBuildInputs = [ catala ]; - doCheck = true; - - meta = with lib; { - homepage = "https://github.com/CatalaLang/catala"; - description = - "Build system for Catala, a specification language for tax and social benefits computation rules"; - license = licenses.asl20; - maintainers = with maintainers; [ ]; - }; -} diff --git a/.nix/ninja_utils.nix b/.nix/ninja_utils.nix deleted file mode 100644 index 36262477..00000000 --- a/.nix/ninja_utils.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ lib -, buildDunePackage -, odoc -, re -}: - -buildDunePackage rec { - pname = "ninja_utils"; - version = "0.8.0"; # TODO parse `catala.opam` with opam2json - - minimumOCamlVersion = "4.11"; - - src = ../.; - - duneVersion = "3"; - - propagatedBuildInputs = [ - odoc - re - ]; - doCheck = true; - - meta = with lib; { - homepage = "https://catala-lang.org"; - description = - "A collection of utility functions used to generate Ninja build files"; - license = licenses.asl20; - maintainers = with maintainers; [ ]; - }; -} diff --git a/.nix/ocolor.nix b/.nix/ocolor.nix deleted file mode 100644 index 4157841d..00000000 --- a/.nix/ocolor.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ lib -, buildDunePackage -, odoc -, cppo -, ounit -, fetchurl -}: - -buildDunePackage rec { - pname = "ocolor"; - version = "1.3.0"; - - minimumOCamlVersion = "4.11"; - - src = fetchurl - { - url = "https://github.com/marc-chevalier/${pname}/archive/${version}.tar.gz"; - sha256 = "sha256-V7xuBRNbWWi3OpDRe7WakOO4Vz6nyoV8/gyn45fpmYA="; - }; - - duneVersion = "3"; - - propagatedBuildInputs = [ - odoc - ounit - cppo - ]; - - nativeBuildInputs = [ cppo ]; - doCheck = true; - - meta = with lib; { - homepage = "https://github.com/marc-chevalier/ocolor"; - description = - "OColor is an OCaml library which help to format nicely using ANSI escape codes."; - license = licenses.mit; - maintainers = [ ]; - }; -} diff --git a/.nix/packages.nix b/.nix/packages.nix deleted file mode 100644 index 26c25e75..00000000 --- a/.nix/packages.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ ocamlPackages, fetchurl }: - -ocamlPackages.overrideScope' (self: super: { - alcotest = (super.alcotest.override {}).overrideAttrs (_: { - doCheck = false; - }); - catala = self.callPackage ./catala.nix { }; - unionfind = self.callPackage ./unionfind.nix { }; - ninja_utils = self.callPackage ./ninja_utils.nix { }; - clerk = self.callPackage ./clerk.nix { }; - ubase = self.callPackage ./ubase.nix { }; - dates_calc = self.callPackage ./dates_calc.nix { }; - french_law = self.callPackage ./french_law.nix { }; - ocolor = self.callPackage ./ocolor.nix { }; -}) diff --git a/.nix/ubase.nix b/.nix/ubase.nix deleted file mode 100644 index e2f6acbd..00000000 --- a/.nix/ubase.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ lib, fetchurl, buildDunePackage, uutf }: - -buildDunePackage rec { - pname = "ubase"; - version = "0.05"; - - minimumOCamlVersion = "4.05.0"; - - useDune2 = true; - - propagatedBuildInputs = [ - uutf - ]; - - src = fetchurl - { - url = "https://github.com/sanette/${pname}/archive/${version}.tar.gz"; - sha256 = "sha256-D7/aCobZDS9/e5hLxd6pO9MJ4xXaSTACUXeQU4j5u0E="; - }; -} diff --git a/.nix/unionfind.nix b/.nix/unionfind.nix deleted file mode 100644 index cb26f67e..00000000 --- a/.nix/unionfind.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ lib, fetchurl, buildDunePackage }: - -buildDunePackage rec { - pname = "unionFind"; - version = "20220122"; - - minimumOCamlVersion = "4.0.8"; - - useDune2 = true; - - src = fetchurl { - url = - "https://gitlab.inria.fr/fpottier/${pname}/-/archive/${version}/archive.tar.gz"; - hash = "sha256-85+5KNYKXsNAH568qR8/AFC9UDviLJEO/Fztc9cRHZA="; - }; - - meta = with lib; { - homepage = "https://gitlab.inria.fr/fpottier/unionFind/"; - description = "Implementations of the union-find data structure"; - license = licenses.gpl2; - maintainers = [ ]; - }; -} diff --git a/flake.lock b/flake.lock index c6adec9f..79a73a9b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1627913399, + "narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -18,26 +34,141 @@ "type": "github" } }, - "nixpkgs": { + "flake-utils_2": { "locked": { - "lastModified": 1690640159, - "narHash": "sha256-5DZUYnkeMOsVb/eqPYb9zns5YsnQXRJRC8Xx/nPMcno=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "e6ab46982debeab9831236869539a507f670a129", + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", "type": "github" }, "original": { - "owner": "NixOS", + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "mirage-opam-overlays": { + "flake": false, + "locked": { + "lastModified": 1661959605, + "narHash": "sha256-CPTuhYML3F4J58flfp3ZbMNhkRkVFKmBEYBZY5tnQwA=", + "owner": "dune-universe", + "repo": "mirage-opam-overlays", + "rev": "05f1c1823d891ce4d8adab91f5db3ac51d86dc0b", + "type": "github" + }, + "original": { + "owner": "dune-universe", + "repo": "mirage-opam-overlays", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1682362401, + "narHash": "sha256-/UMUHtF2CyYNl4b60Z2y4wwTTdIWGKhj9H301EDcT9M=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "884ac294018409e0d1adc0cae185439a44bd6b0b", + "type": "github" + }, + "original": { + "owner": "nixos", "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, + "opam-nix": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "mirage-opam-overlays": "mirage-opam-overlays", + "nixpkgs": "nixpkgs", + "opam-overlays": "opam-overlays", + "opam-repository": [ + "opam-repository" + ], + "opam2json": "opam2json" + }, + "locked": { + "lastModified": 1716292162, + "narHash": "sha256-UOJNCbqvxABD56JZtZkv3C9ufdqrs7/Ep4AKkCHgPuo=", + "owner": "tweag", + "repo": "opam-nix", + "rev": "1d3cbd6d3f247db77cb581c88c9a1d72e4acad60", + "type": "github" + }, + "original": { + "owner": "tweag", + "repo": "opam-nix", + "type": "github" + } + }, + "opam-overlays": { + "flake": false, + "locked": { + "lastModified": 1654162756, + "narHash": "sha256-RV68fUK+O3zTx61iiHIoS0LvIk0E4voMp+0SwRg6G6c=", + "owner": "dune-universe", + "repo": "opam-overlays", + "rev": "c8f6ef0fc5272f254df4a971a47de7848cc1c8a4", + "type": "github" + }, + "original": { + "owner": "dune-universe", + "repo": "opam-overlays", + "type": "github" + } + }, + "opam-repository": { + "flake": false, + "locked": { + "lastModified": 1722612394, + "narHash": "sha256-djcSMr+mKRyTAm2QEICJBmqRT4ftsy4th4/OR1HWGjM=", + "owner": "ocaml", + "repo": "opam-repository", + "rev": "fe8dffac61bbab376897c0f4e7cc5b7b8c4eecc1", + "type": "github" + }, + "original": { + "owner": "ocaml", + "repo": "opam-repository", + "type": "github" + } + }, + "opam2json": { + "inputs": { + "nixpkgs": [ + "opam-nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1671540003, + "narHash": "sha256-5pXfbUfpVABtKbii6aaI2EdAZTjHJ2QntEf0QD2O5AM=", + "owner": "tweag", + "repo": "opam2json", + "rev": "819d291ea95e271b0e6027679de6abb4d4f7f680", + "type": "github" + }, + "original": { + "owner": "tweag", + "repo": "opam2json", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": [ + "opam-nix", + "nixpkgs" + ], + "opam-nix": "opam-nix", + "opam-repository": "opam-repository" } }, "systems": { diff --git a/flake.nix b/flake.nix index 300a3be2..ca2e7af5 100644 --- a/flake.nix +++ b/flake.nix @@ -1,44 +1,63 @@ { inputs = { + opam-repository = { + url = "github:ocaml/opam-repository"; + flake = false; + }; + opam-nix.url = "github:tweag/opam-nix"; + opam-nix.inputs.opam-repository.follows = "opam-repository"; flake-utils.url = "github:numtide/flake-utils"; - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixpkgs.follows = "opam-nix/nixpkgs"; }; - - outputs = {nixpkgs, flake-utils, ...}: - let - systems = nixpkgs.lib.systems.flakeExposed; - in flake-utils.lib.eachSystem systems (system: + outputs = { self, flake-utils, opam-nix, nixpkgs, ... }@inputs: + flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system; }; - ocamlPackages = pkgs.callPackage ./.nix/packages.nix {}; - in - rec { - packages = { - catala = ocamlPackages.catala; - clerk = ocamlPackages.clerk; - french_law = ocamlPackages.french_law; + pkgs = nixpkgs.legacyPackages.${system}; + on = opam-nix.lib.${system}; + localPackagesQuery = builtins.mapAttrs (_: pkgs.lib.last) + (on.listRepo (on.makeOpamRepo ./.)); + devPackagesQuery = { + # You can add "development" packages here. They will get added to the devShell automatically. + ocaml-lsp-server = "*"; + ocamlformat = "*"; + }; + query = devPackagesQuery // { + ## You can force versions of certain packages here, e.g: + ## - force the ocaml compiler to be taken from opam-repository: + # ocaml-base-compiler = "*"; + ## - or force the compiler to be taken from nixpkgs and be a certain version: + # ocaml-system = "4.14.0"; + ## - or force ocamlfind to be a certain version: + # ocamlfind = "1.9.2"; + }; + scope = on.buildOpamProject' { } ./. query; + overlay = final: prev: + { + conf-ninja = prev.conf-ninja.overrideAttrs (old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.ninja ]; + }); + # You can add overrides here }; - defaultPackage = packages.clerk; - devShell = pkgs.mkShell { - inputsFrom = [ packages.clerk packages.catala ]; - buildInputs = [ - pkgs.inotify-tools - ocamlPackages.merlin - pkgs.ocamlformat_0_26_0 - ocamlPackages.ocp-indent - ocamlPackages.utop - ocamlPackages.odoc - ocamlPackages.ocaml-lsp - pkgs.groff - pkgs.obelisk - pkgs.ninja - pkgs.colordiff - pkgs.pandoc - pkgs.python3.pkgs.pygments - pkgs.nodejs - pkgs.nodePackages.npm - ]; - }; - } - ); + scope' = scope.overrideScope' overlay; + # Packages from devPackagesQuery + devPackages = builtins.attrValues + (pkgs.lib.getAttrs (builtins.attrNames devPackagesQuery) scope'); + # Packages in this workspace + packages = + pkgs.lib.getAttrs (builtins.attrNames localPackagesQuery) scope'; + in { + legacyPackages = scope'; + + #inherit packages; + + ## If you want to have a "default" package which will be built with just `nix build`, do this instead of `inherit packages;`: + packages = packages // { default = packages.catala; }; + + devShells.default = pkgs.mkShell { + inputsFrom = builtins.attrValues packages; + buildInputs = devPackages ++ [ + # You can add packages from nixpkgs here + ]; + }; + }); }