diff --git a/README.md b/README.md index 794fa0b..d71616b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ can set up a development environment. # 3 Steps to happy Hasktorch coding 1. Fork this repo and clone it locally. -2. Launch a Nix shell with (optionally) CUDA, `ghcide`, and VS Code, `nix-shell --arg cudaSupport true --argstr cudaMajorVersion 10 --command "code ."` -3. Install the [Haskell Language Server plugin](https://marketplace.visualstudio.com/items?itemName=alanz.vscode-hie-server) and set the `HIE Variant` to `ghcide`. +2. (optional) Disable CUDA by editing `flake.nix` and setting + `cudaSupport` to `false`. +3. Start a Nix development shell with `nix develop .`. Happy Hasktorch hacking! diff --git a/cabal.project b/cabal.project index 009fa9f..42f023c 100644 --- a/cabal.project +++ b/cabal.project @@ -1,23 +1,2 @@ packages: *.cabal - -source-repository-package - type: git - location: https://github.com/hasktorch/hasktorch - tag: d7dd1f0a83971621526caf80c0dfafc5eb0bc8be - --sha256: 1rh6xssbzcp6gix80w55qdv9ilynsrjlyn9m283bi5c5i876hrvl - subdir: libtorch-ffi-helper - -source-repository-package - type: git - location: https://github.com/hasktorch/hasktorch - tag: d7dd1f0a83971621526caf80c0dfafc5eb0bc8be - --sha256: 1rh6xssbzcp6gix80w55qdv9ilynsrjlyn9m283bi5c5i876hrvl - subdir: libtorch-ffi - -source-repository-package - type: git - location: https://github.com/hasktorch/hasktorch - tag: d7dd1f0a83971621526caf80c0dfafc5eb0bc8be - --sha256: 1rh6xssbzcp6gix80w55qdv9ilynsrjlyn9m283bi5c5i876hrvl - subdir: hasktorch \ No newline at end of file diff --git a/flake.lock b/flake.lock index f93f4fc..c1456ee 100644 --- a/flake.lock +++ b/flake.lock @@ -1,176 +1,108 @@ { "nodes": { - "hackageSrc": { - "flake": false, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, "locked": { - "lastModified": 1621386693, - "narHash": "sha256-iDI16Wc28HOuvnab2vsuCku7XqVBeVWABRZEyhSQ2RM=", - "owner": "input-output-hk", - "repo": "hackage.nix", - "rev": "1ca8be1a4695af150ae81e6c9a2fad068c03c008", + "lastModified": 1717285511, + "narHash": "sha256-iKzJcpdXih14qYVcZ9QC9XuZYnPc6T8YImb6dX166kw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "2a55567fcf15b1b1c7ed712a2c6fadaec7412ea8", "type": "github" }, "original": { - "owner": "input-output-hk", - "repo": "hackage.nix", + "owner": "hercules-ci", + "repo": "flake-parts", "type": "github" } }, - "haskell-nix": { + "flake-parts_2": { "inputs": { - "nixpkgs": "nixpkgs", - "nixpkgs-2003": "nixpkgs-2003", - "nixpkgs-2009": "nixpkgs-2009", - "nixpkgs-unstable": "nixpkgs-unstable" + "nixpkgs-lib": "nixpkgs-lib_2" }, "locked": { - "lastModified": 1621386783, - "narHash": "sha256-s25SqEJfUuIvW3vGclNU/cLwRjLbctOGPhS1ceDOwoY=", - "owner": "input-output-hk", - "repo": "haskell.nix", - "rev": "125fb28555bf7da35b19d75766da1933861c280f", + "lastModified": 1715865404, + "narHash": "sha256-/GJvTdTpuDjNn84j82cU6bXztE0MSkdnTWClUCRub78=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8dc45382d5206bd292f9c2768b8058a8fd8311d9", "type": "github" }, "original": { - "owner": "input-output-hk", - "repo": "haskell.nix", + "owner": "hercules-ci", + "repo": "flake-parts", "type": "github" } }, - "libtorch-nix": { - "flake": false, + "hasktorch": { + "inputs": { + "flake-parts": "flake-parts_2", + "nixpkgs": "nixpkgs" + }, "locked": { - "lastModified": 1621467457, - "narHash": "sha256-EX9gbDxio9/2LkepDKOcrAvzBRF89Ppn4ao6SExXXcw=", + "lastModified": 1718282624, + "narHash": "sha256-dnKAwgeo7FVGHvXafGLrWBbzHVaR35AqhLDLZgaQV+U=", "owner": "hasktorch", - "repo": "libtorch-nix", - "rev": "d14b0fd10b96d192b92b8ccc7254ade4b3489331", + "repo": "hasktorch", + "rev": "a28facd7a3e783c340335cd96b77d89e3179d9a1", "type": "github" }, "original": { "owner": "hasktorch", - "repo": "libtorch-nix", - "rev": "d14b0fd10b96d192b92b8ccc7254ade4b3489331", + "repo": "hasktorch", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1608007629, - "narHash": "sha256-lipVFC/a2pzzA5X2ULj64je+fz1JIp2XRrB5qyoizpQ=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", - "type": "github" - } - }, - "nixpkgs-2003": { - "locked": { - "lastModified": 1607708579, - "narHash": "sha256-QyADEDydJJPa8n3xawnA82IJAcZHNNm6Pp5DU7exMr4=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "7f73e46625f508a793700f5110b86f1a53341d6e", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "7f73e46625f508a793700f5110b86f1a53341d6e", - "type": "github" - } - }, - "nixpkgs-2009": { - "locked": { - "lastModified": 1608007629, - "narHash": "sha256-lipVFC/a2pzzA5X2ULj64je+fz1JIp2XRrB5qyoizpQ=", - "owner": "NixOS", + "lastModified": 1716097317, + "narHash": "sha256-1UMrLtgzielG/Sop6gl6oTSM4pDt7rF9j9VuxhDWDlY=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", + "rev": "8535fb92661f37ff9f0da3007fbc942f7d134b41", "type": "github" }, "original": { - "owner": "NixOS", + "owner": "nixos", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", - "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", "type": "github" } }, - "nixpkgs-unstable": { + "nixpkgs-lib": { "locked": { - "lastModified": 1612284693, - "narHash": "sha256-efzJNF1jvjK3BMl0gZ0ZaUWcFMv0nLb9AHN/++5+u0U=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "410bbd828cdc6156aecd5bc91772ad3a6b1099c7", - "type": "github" + "lastModified": 1717284937, + "narHash": "sha256-lIbdfCsf8LMFloheeE6N31+BMIeixqyQWbSr2vk79EQ=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" }, "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "410bbd828cdc6156aecd5bc91772ad3a6b1099c7", - "type": "github" + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" } }, - "nixpkgs_2": { + "nixpkgs-lib_2": { "locked": { - "lastModified": 1621433235, - "narHash": "sha256-eSBLBQxJoEIFVuBgxi0vLvVVyv+BS5YAC47a2rePw9Y=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "6cf64704297f60ca6ab579a4135bb565bb514b06", - "type": "github" + "lastModified": 1714640452, + "narHash": "sha256-QBx10+k6JWz6u7VsohfSw8g8hjdBZEf8CFzXH1/1Z94=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz" } }, "root": { "inputs": { - "hackageSrc": "hackageSrc", - "haskell-nix": "haskell-nix", - "libtorch-nix": "libtorch-nix", - "nixpkgs": "nixpkgs_2", - "stackageSrc": "stackageSrc", - "utils": "utils" - } - }, - "stackageSrc": { - "flake": false, - "locked": { - "lastModified": 1621299779, - "narHash": "sha256-zAu9jI9QWZhYWc+6l2gAPWKkkcO6DpX3MnYn8ftYaAU=", - "owner": "input-output-hk", - "repo": "stackage.nix", - "rev": "d387a944749263e4685cb116893c5226cd9fc75b", - "type": "github" - }, - "original": { - "owner": "input-output-hk", - "repo": "stackage.nix", - "type": "github" - } - }, - "utils": { - "locked": { - "lastModified": 1620759905, - "narHash": "sha256-WiyWawrgmyN0EdmiHyG2V+fqReiVi8bM9cRdMaKQOFg=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" + "flake-parts": "flake-parts", + "hasktorch": "hasktorch", + "nixpkgs": [ + "hasktorch", + "nixpkgs" + ] } } }, diff --git a/flake.nix b/flake.nix index aa681b4..d89fb2c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,112 +1,55 @@ { - inputs = { - haskell-nix.url = "github:input-output-hk/haskell.nix"; - stackageSrc = { - url = "github:input-output-hk/stackage.nix"; - flake = false; - }; - hackageSrc = { - url = "github:input-output-hk/hackage.nix"; - flake = false; - }; - utils.url = "github:numtide/flake-utils"; - libtorch-nix = { - url = "github:hasktorch/libtorch-nix/d14b0fd10b96d192b92b8ccc7254ade4b3489331"; - flake = false; - }; + nixConfig = { + extra-substituters = [ + "https://hasktorch.cachix.org" + ]; + extra-trusted-public-keys = [ + "hasktorch.cachix.org-1:wLjNS6HuFVpmzbmv01lxwjdCOtWRD8pQVR3Zr/wVoQc=" + ]; }; - outputs = inputs@{ self, nixpkgs, haskell-nix, utils, ... }: - let - name = "hasktorchSkeleton"; - compiler = "ghc8104"; # Not used for `stack.yaml` based projects. - cudaSupport = false; - cudaMajorVersion = null; - project-name = "${name}HaskellPackages"; - - - # This overlay adds our project to pkgs - project-overlay = final: prev: { - ${project-name} = - #assert compiler == supported-compilers; - final.haskell-nix.project' { - # 'cleanGit' cleans a source directory based on the files known by git - src = prev.haskell-nix.haskellLib.cleanGit { - inherit name; - src = ./.; - }; - - compiler-nix-name = compiler; - projectFileName = "cabal.project"; # Not used for `stack.yaml` based projects. - modules = [ - # Fixes for libtorch-ffi - { - packages.libtorch-ffi = { - configureFlags = with final; [ - "--extra-lib-dirs=${torch}/lib" - "--extra-include-dirs=${torch}/include" - "--extra-include-dirs=${torch}/include/torch/csrc/api/include" - ]; - flags = { - cuda = cudaSupport; - gcc = !cudaSupport && final.stdenv.hostPlatform.isDarwin; - }; - }; - } - ]; - - }; + inputs = { + hasktorch.url = "github:hasktorch/hasktorch"; + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.follows = "hasktorch/nixpkgs"; + }; - }; - in - { overlay = final: prev: { - "${name}" = ("${project-name}-overlay" final prev)."${project-name}".flake {}; - }; - } // (utils.lib.eachSystem [ "x86_64-linux" ] (system: - let + outputs = inputs @ { + self, + hasktorch, + nixpkgs, + flake-parts, + ... + }: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux"]; + perSystem = { + config, + system, + pkgs, + ... + }: let + ghc = "ghc965"; + in { + _module.args = { pkgs = import nixpkgs { inherit system; + # Set to false to disable CUDA support + config.cudaSupport = true; overlays = [ - haskell-nix.overlay - (final: prev: { - haskell-nix = prev.haskell-nix // { - sources = prev.haskell-nix.sources // { - hackage = inputs.hackageSrc; - stackage = inputs.stackageSrc; - }; - modules = [ - # Fixes for libtorch-ffi - { - packages.libtorch-ffi = { - configureFlags = with final; [ - "--extra-lib-dirs=${torch}/lib" - "--extra-include-dirs=${torch}/include" - "--extra-include-dirs=${torch}/include/torch/csrc/api/include" - ]; - flags = { - cuda = cudaSupport; - gcc = !cudaSupport && final.stdenv.hostPlatform.isDarwin; - }; - }; - } - ]; - }; - }) - (import ./nix/overlays/libtorch.nix { inherit inputs cudaSupport cudaMajorVersion; }) - project-overlay + hasktorch.overlays.default ]; }; - flake = pkgs."${project-name}".flake {}; - in flake // rec { - - packages.example = flake.packages."${name}:exe:example"; - - defaultPackage = packages.example; - - devShell = (import ./shell.nix { - inherit cudaSupport cudaMajorVersion pkgs; - withHoogle = false; - }); - } - )); + }; + packages.default = + pkgs.haskell.packages.${ghc}.callCabal2nix "example" ./. {}; + devShells.default = pkgs.haskell.packages.${ghc}.shellFor { + packages = ps: [ + (ps.callCabal2nix "example" ./. {}) + ]; + nativeBuildInputs = with pkgs; [cabal-install stylish-haskell]; + withHoogle = true; + }; + }; + }; } diff --git a/hasktorch-skeleton.cabal b/hasktorch-skeleton.cabal index 34d2b58..d688a4f 100644 --- a/hasktorch-skeleton.cabal +++ b/hasktorch-skeleton.cabal @@ -1,4 +1,4 @@ -cabal-version: 2.2 +cabal-version: 3.0 name: hasktorch-skeleton version: 0.0.0.0 synopsis: See README for more info @@ -12,13 +12,13 @@ category: Tensors, Machine Learning, AI build-type: Simple extra-doc-files: README.md , CHANGELOG.md -tested-with: GHC == 8.8.3 +tested-with: GHC == 9.6.5 common base ghc-options: -Wall -Wextra -Wno-unrecognised-pragmas -Wno-orphans default-language: Haskell2010 build-depends: - base >= 4.12 && < 5 + base >= 4.18 && < 5 , hasktorch >= 0.2 && < 0.3 common binary-base diff --git a/nix/default.nix b/nix/default.nix deleted file mode 100644 index a64eb55..0000000 --- a/nix/default.nix +++ /dev/null @@ -1,71 +0,0 @@ -{ system ? builtins.currentSystem -, crossSystem ? null -# Lets you customise ghc and profiling (see ./haskell.nix): -, config ? {} -# Lets you override niv dependencies of the project without modifications to the source. -, sourcesOverride ? {} -# Version info, to be passed when not building from a git work tree -, gitrev ? null -# Enable CUDA support -, cudaSupport ? false -, cudaMajorVersion ? null -# Add packages on top of the package set derived from cabal resolution -, extras ? (_: {}) -}: - -# assert that the correct cuda versions are used -assert cudaSupport -> (cudaMajorVersion == "9" || cudaMajorVersion == "10" || cudaMajorVersion == "11"); - -let - sources = import ./sources.nix { inherit pkgs; } - // sourcesOverride; - iohkNix = import sources.iohk-nix {}; - haskellNix = import sources.haskell-nix { inherit system sourcesOverride; }; - - # Use haskell.nix default nixpkgs - nixpkgsSrc = haskellNix.sources.nixpkgs-unstable; - - # for inclusion in pkgs: - overlays = - # Haskell.nix (https://github.com/input-output-hk/haskell.nix) - haskellNix.nixpkgsArgs.overlays - # override Haskell.nix hackage and stackage sources - ++ [ - (pkgsNew: pkgsOld: let inherit (pkgsNew) lib; in { - haskell-nix = pkgsOld.haskell-nix // { - hackageSrc = sources.hackage-nix; - stackageSrc = sources.stackage-nix; - }; - }) - ] - # the haskell-nix.haskellLib.extra overlay contains some useful extra utility functions for haskell.nix - ++ iohkNix.overlays.haskell-nix-extra - # the iohkNix overlay contains nix utilities and niv - ++ iohkNix.overlays.iohkNix - ++ [ - (import ./overlays/libtorch.nix { - inherit cudaSupport cudaMajorVersion; - inputs = sources; - }) - ] - # our own overlays: - ++ [ - (pkgs: _: with pkgs; { - inherit gitrev cudaSupport extras; - - # commonLib: mix pkgs.lib with iohk-nix utils and sources: - commonLib = lib // iohkNix - // import ./util.nix { inherit haskell-nix; } - # also expose sources, nixpkgs and overlays - // { inherit overlays sources nixpkgsSrc; }; - }) - # haskell-nix-ified hasktorch cabal project: - (import ./pkgs.nix) - ]; - - pkgs = import nixpkgsSrc { - inherit system crossSystem overlays; - config = haskellNix.nixpkgsArgs.config // config; - }; - -in pkgs diff --git a/nix/haskell.nix b/nix/haskell.nix deleted file mode 100644 index 22c85b5..0000000 --- a/nix/haskell.nix +++ /dev/null @@ -1,54 +0,0 @@ -{ lib -, stdenv -, pkgs -, haskell-nix -, buildPackages -, config ? {} -# GHC attribute name -, compiler ? config.haskellNix.compiler or "ghc8104" -# Enable profiling -, profiling ? config.haskellNix.profiling or false -# Enable CUDA support -, cudaSupport ? false -}: - -let - - src = haskell-nix.haskellLib.cleanGit { - name = "hasktorch-skeleton"; - src = ../.; - }; - - # This creates the Haskell package set. - # https://input-output-hk.github.io/haskell.nix/user-guide/projects/ - pkgSet = haskell-nix.cabalProject { - inherit src; - - compiler-nix-name = compiler; - - # these extras will provide additional packages - # ontop of the package set derived from cabal resolution. - pkg-def-extras = [ ]; - - modules = [ - { compiler.nix-name = compiler; } - - # Fixes for libtorch-ffi - { - packages.libtorch-ffi = { - configureFlags = [ - "--extra-lib-dirs=${pkgs.torch}/lib" - "--extra-include-dirs=${pkgs.torch}/include" - "--extra-include-dirs=${pkgs.torch}/include/torch/csrc/api/include" - ]; - flags = { - cuda = cudaSupport; - gcc = !cudaSupport && pkgs.stdenv.hostPlatform.isDarwin; - }; - }; - } - ]; - }; - -in - pkgSet diff --git a/nix/overlays/libtorch.nix b/nix/overlays/libtorch.nix deleted file mode 100644 index 6f3c008..0000000 --- a/nix/overlays/libtorch.nix +++ /dev/null @@ -1,41 +0,0 @@ -{ inputs, cudaSupport, cudaMajorVersion ? null }: - -# libtorch overlays from pytorch-world -# TODO: pull in libGL_driver and cudatoolkit as done in https://github.com/NixOS/nixpkgs/blob/master/pkgs/games/katago/default.nix - -final: prev: -with prev; - -let libtorchSrc = callPackage "${inputs.libtorch-nix}/libtorch/release.nix" { }; in - -if cudaSupport && cudaMajorVersion == "9" then - let libtorch = libtorchSrc.libtorch_cudatoolkit_9_2; in - { - c10 = libtorch; - torch = libtorch; - torch_cpu = libtorch; - torch_cuda = libtorch; - } -else if cudaSupport && cudaMajorVersion == "10" then - let libtorch = libtorchSrc.libtorch_cudatoolkit_10_2; in - { - c10 = libtorch; - torch = libtorch; - torch_cpu = libtorch; - torch_cuda = libtorch; - } -else if cudaSupport && cudaMajorVersion == "11" then - let libtorch = libtorchSrc.libtorch_cudatoolkit_11_0; in - { - c10 = libtorch; - torch = libtorch; - torch_cpu = libtorch; - torch_cuda = libtorch; - } -else - let libtorch = libtorchSrc.libtorch_cpu; in - { - c10 = libtorch; - torch = libtorch; - torch_cpu = libtorch; - } diff --git a/nix/pkgs.nix b/nix/pkgs.nix deleted file mode 100644 index 2acceeb..0000000 --- a/nix/pkgs.nix +++ /dev/null @@ -1,12 +0,0 @@ -pkgs: _: with pkgs; { - hasktorchSkeletonHaskellPackages = import ./haskell.nix { - inherit - lib - stdenv - pkgs - haskell-nix - buildPackages - config - ; - }; -} \ No newline at end of file diff --git a/nix/sources.json b/nix/sources.json deleted file mode 100644 index 9df2c16..0000000 --- a/nix/sources.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "hackage-nix": { - "branch": "master", - "description": "Automatically generated Nix expressions for Hackage", - "homepage": "", - "owner": "input-output-hk", - "repo": "hackage.nix", - "rev": "0d068a159dd838f935a24befc83946cf6122b1a4", - "sha256": "1b7a31ikrwdd0mlb6byjn9fxggy7ns9xlnl40dv166rx98dhg8hr", - "type": "tarball", - "url": "https://github.com/input-output-hk/hackage.nix/archive/0d068a159dd838f935a24befc83946cf6122b1a4.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "haskell-nix": { - "branch": "master", - "description": "Alternative Haskell Infrastructure for Nixpkgs", - "homepage": "https://input-output-hk.github.io/haskell.nix", - "owner": "input-output-hk", - "repo": "haskell.nix", - "rev": "a88542003caddbfeff37ef2bd7fc51b4a9e43d1f", - "sha256": "088bafnl5d4a3sfskszdvkkd0vk3rpdzwgrghkqjcxxhm0yc523y", - "type": "tarball", - "url": "https://github.com/input-output-hk/haskell.nix/archive/a88542003caddbfeff37ef2bd7fc51b4a9e43d1f.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "iohk-nix": { - "branch": "master", - "description": "nix scripts shared across projects", - "homepage": null, - "owner": "input-output-hk", - "repo": "iohk-nix", - "rev": "666e57027dca46964c6a26efcc2042b247d354a5", - "sha256": "0v5sgs8wf47x4csr6f70z2hi47my5r981m71nqgkj04n0sr6lz4b", - "type": "tarball", - "url": "https://github.com/input-output-hk/iohk-nix/archive/666e57027dca46964c6a26efcc2042b247d354a5.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "jupyterWith": { - "branch": "master", - "description": "declarative and reproducible Jupyter environments - powered by Nix", - "homepage": "", - "owner": "tweag", - "repo": "jupyterWith", - "rev": "35eb565c6d00f3c61ef5e74e7e41870cfa3926f7", - "sha256": "15zpprs0blvlvbqapkyn92x6dpfa6va2xz25v24z67lqs96ii4jm", - "type": "tarball", - "url": "https://github.com/tweag/jupyterWith/archive/35eb565c6d00f3c61ef5e74e7e41870cfa3926f7.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "libtorch-nix": { - "branch": "main", - "description": null, - "homepage": null, - "owner": "hasktorch", - "repo": "libtorch-nix", - "rev": "d14b0fd10b96d192b92b8ccc7254ade4b3489331", - "sha256": "1k2xax64hfmaw5kzmx3w242z62xckjihraa75vvdz8v27in60zqi", - "type": "tarball", - "url": "https://github.com/hasktorch/libtorch-nix/archive/d14b0fd10b96d192b92b8ccc7254ade4b3489331.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "niv": { - "branch": "master", - "description": "Easy dependency management for Nix projects", - "homepage": "https://github.com/nmattia/niv", - "owner": "nmattia", - "repo": "niv", - "rev": "af958e8057f345ee1aca714c1247ef3ba1c15f5e", - "sha256": "1qjavxabbrsh73yck5dcq8jggvh3r2jkbr6b5nlz5d9yrqm9255n", - "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/af958e8057f345ee1aca714c1247ef3ba1c15f5e.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "stackage-nix": { - "branch": "master", - "description": "Automatically generated Nix expressions of Stackage snapshots", - "homepage": "", - "owner": "input-output-hk", - "repo": "stackage.nix", - "rev": "76ceb02f61b12cdeaac07c5f6738932b2f2aca30", - "sha256": "0wdaw6vjjglpx8adfj0fyaykzw7crg28nmlfxmkibp53jzlw8zg6", - "type": "tarball", - "url": "https://github.com/input-output-hk/stackage.nix/archive/76ceb02f61b12cdeaac07c5f6738932b2f2aca30.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index 1938409..0000000 --- a/nix/sources.nix +++ /dev/null @@ -1,174 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - if spec ? ref then spec.ref else - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; - in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/nix/stack-shell.nix b/nix/stack-shell.nix deleted file mode 100644 index ec3b7b5..0000000 --- a/nix/stack-shell.nix +++ /dev/null @@ -1,49 +0,0 @@ - -# This shell file is specifically to be used with Stack. -# -# This file allows using Stack's built-in Nix integration. This means that you -# can compile hasktorch with Stack by using a command like `stack --nix build`. -# Stack will use Nix to download and build required system libraries (like GHC -# and libtorch), and then build Haskell libraries like normal. -# -# This approach allows for more reproducibility than using Stack without Nix. -{ config ? {} -, sourcesOverride ? {} -, cudaSupport ? false -, cudaMajorVersion ? null -, withHoogle ? false -, pkgs ? import ./default.nix { - inherit config sourcesOverride cudaSupport cudaMajorVersion; - } -}: -with pkgs; -let - ghc = hasktorchSkeletonHaskellPackages.ghcWithPackages (_: []); - - buildInputs = [ - git # needed so that stack can get extra-deps from github - torch - zlib - ]; - - stack-shell = haskell.lib.buildStackProject rec { - inherit ghc; - - name = "hasktorch-skeleton-stack-dev-shell"; - - extraArgs = [ - "--extra-include-dirs=${torch}/include/torch/csrc/api/include" - ]; - - inherit buildInputs; - - phases = ["nobuildPhase"]; - nobuildPhase = "echo '${lib.concatStringsSep "\n" ([ghc] ++ buildInputs)}' > $out"; - meta.platforms = lib.platforms.unix; - - inherit withHoogle; - }; - -in - - stack-shell \ No newline at end of file diff --git a/nix/util.nix b/nix/util.nix deleted file mode 100644 index f24484d..0000000 --- a/nix/util.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ haskell-nix }: - -with haskell-nix.haskellLib; -{ - - inherit - selectProjectPackages - collectComponents'; - - inherit (extra) - collectChecks - recRecurseIntoAttrs; - -} \ No newline at end of file