diff --git a/.gitignore b/.gitignore index d1b9bdf5f..296c86a9e 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,12 @@ setup.log *.install # editor config files -.vscode \ No newline at end of file +.vscode + +# Ignore direnv files +.envrc +.direnv/ + +# Ignore Nix/Flake related files/folders +result +result-* diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..b1e30b321 --- /dev/null +++ b/flake.lock @@ -0,0 +1,189 @@ +{ + "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" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "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": 1705008664, + "narHash": "sha256-TTjTal49QK2U0yVOmw6rJhTGYM7tnj3Kv9DiEEiLt7E=", + "owner": "ocaml", + "repo": "opam-repository", + "rev": "fa77046c6497f8ca32926acdb7eb1e61777d4c17", + "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": [ + "opam-nix", + "nixpkgs" + ], + "opam-nix": "opam-nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..a70b637c7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,61 @@ +{ + inputs = { + opam-nix.url = "github:tweag/opam-nix"; + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.follows = "opam-nix/nixpkgs"; + }; + outputs = { self, flake-utils, opam-nix, nixpkgs }@inputs: + flake-utils.lib.eachDefaultSystem (system: + let + 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"; + ocaml-compiler-libs = "*"; + alcotest = "*"; + dune-configurator = "*"; + bigarray-compat = "*"; + }; + scope = on.buildOpamProject' { } ./. query; + overlay = final: prev: + { + # You can add overrides here + # dune = prev.dune.overrideAttrs (_: { buildPhase = "make && make install"; }); + }; + 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.owl; }; + + devShells.default = pkgs.mkShell { + inputsFrom = builtins.attrValues packages; + buildInputs = devPackages ++ [ + # You can add packages from nixpkgs here + pkgs.openblas + ]; + }; + }); +}