From f041222ef9840da5b9380931f9f56e6db06117bf Mon Sep 17 00:00:00 2001 From: Junji Hashimoto Date: Mon, 6 Jan 2025 21:38:03 +0900 Subject: [PATCH] Use hasktorch in nixpkgs --- README.md | 4 +- cabal.project | 21 ----- default.nix | 69 --------------- flake.lock | 160 +++++------------------------------ flake.nix | 133 ++++++----------------------- nix/default.nix | 71 ---------------- nix/haskell.nix | 54 ------------ nix/overlays/libtorch.nix | 41 --------- nix/pkgs.nix | 12 --- nix/sources.json | 86 ------------------- nix/sources.nix | 174 -------------------------------------- nix/stack-shell.nix | 49 ----------- nix/util.nix | 14 --- shell.nix | 41 --------- stack.yaml | 19 ++--- 15 files changed, 58 insertions(+), 890 deletions(-) delete mode 100644 default.nix delete mode 100644 nix/default.nix delete mode 100644 nix/haskell.nix delete mode 100644 nix/overlays/libtorch.nix delete mode 100644 nix/pkgs.nix delete mode 100644 nix/sources.json delete mode 100644 nix/sources.nix delete mode 100644 nix/stack-shell.nix delete mode 100644 nix/util.nix delete mode 100644 shell.nix diff --git a/README.md b/README.md index 794fa0b..d9297cc 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,12 @@ Similar to the [Cardano Skeleton](https://github.com/input-output-hk/cardano-ske this repository serves as an example of how a downstream user of both Nix and Hasktorch can set up a development environment. +The Nix shell installs ghc with hasktorch. When there is a hasktorch cache in nixpkgs, building hasktorch will be skipped. + # 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 ."` +2. Launch a Nix shell with (optionally) CUDA, `hls`, and VS Code, `nix develop"` 3. Install the [Haskell Language Server plugin](https://marketplace.visualstudio.com/items?itemName=alanz.vscode-hie-server) and set the `HIE Variant` to `ghcide`. 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/default.nix b/default.nix deleted file mode 100644 index 9ee2659..0000000 --- a/default.nix +++ /dev/null @@ -1,69 +0,0 @@ -############################################################################ -# hasktorch-skeleton Nix build -############################################################################ - -{ system ? builtins.currentSystem -, crossSystem ? null -# allows to customize ghc and profiling (see ./nix/haskell.nix): -, config ? {} -# allows to override dependencies of the hasktorch-skeleton project without modifications -, sourcesOverride ? {} -# If true, activates CUDA support -, cudaSupport ? false -# If cudaSupport is true, this needs to be set to a valid CUDA major version number, e.g. 10: -# nix-build --arg cudaSupport true --argstr cudaMajorVersion 10 -, cudaMajorVersion ? null -# pinned version of nixpkgs augmented with various overlays including hasktorch -, pkgs ? import ./nix/default.nix { - inherit system crossSystem config sourcesOverride cudaSupport cudaMajorVersion; - } -}: - -# commonLib include iohk-nix utilities, our util.nix and nixpkgs lib. -with pkgs; with commonLib; - -let - - haskellPackages = recRecurseIntoAttrs - # the Haskell.nix package set, reduced to local packages. - (selectProjectPackages hasktorchSkeletonHaskellPackages); - - libs = collectComponents' "library" haskellPackages; - exes = collectComponents' "exes" haskellPackages; - - self = { - inherit haskellPackages; - - inherit (haskellPackages.hasktorch-skeleton.identifier) version; - - # Grab library components of this package. - inherit (libs) - hasktorch-skeleton - ; - - # Grab executable components of this package. - inherit (exes); - - # `tests` are the test suites which have been built. - tests = collectComponents' "tests" haskellPackages; - # `benchmarks` (only built, not run). - benchmarks = collectComponents' "benchmarks" haskellPackages; - - checks = recurseIntoAttrs { - # `checks.tests` collect results of executing the tests: - tests = collectChecks haskellPackages; - }; - - shell = import ./shell.nix { - inherit pkgs; - withHoogle = true; - }; - - # Building the stack shell doesn't work in the sandbox. Pass `--option sandbox relaxed` or - # `--option sandbox false` to be able to build this. You have to be root in order to that. - # stackShell = import ./nix/stack-shell.nix { - # inherit pkgs; - # }; - }; -in - self \ No newline at end of file diff --git a/flake.lock b/flake.lock index f93f4fc..f8f0d88 100644 --- a/flake.lock +++ b/flake.lock @@ -1,170 +1,52 @@ { "nodes": { - "hackageSrc": { - "flake": false, - "locked": { - "lastModified": 1621386693, - "narHash": "sha256-iDI16Wc28HOuvnab2vsuCku7XqVBeVWABRZEyhSQ2RM=", - "owner": "input-output-hk", - "repo": "hackage.nix", - "rev": "1ca8be1a4695af150ae81e6c9a2fad068c03c008", - "type": "github" - }, - "original": { - "owner": "input-output-hk", - "repo": "hackage.nix", - "type": "github" - } - }, - "haskell-nix": { - "inputs": { - "nixpkgs": "nixpkgs", - "nixpkgs-2003": "nixpkgs-2003", - "nixpkgs-2009": "nixpkgs-2009", - "nixpkgs-unstable": "nixpkgs-unstable" - }, - "locked": { - "lastModified": 1621386783, - "narHash": "sha256-s25SqEJfUuIvW3vGclNU/cLwRjLbctOGPhS1ceDOwoY=", - "owner": "input-output-hk", - "repo": "haskell.nix", - "rev": "125fb28555bf7da35b19d75766da1933861c280f", - "type": "github" - }, - "original": { - "owner": "input-output-hk", - "repo": "haskell.nix", - "type": "github" - } - }, - "libtorch-nix": { - "flake": false, - "locked": { - "lastModified": 1621467457, - "narHash": "sha256-EX9gbDxio9/2LkepDKOcrAvzBRF89Ppn4ao6SExXXcw=", - "owner": "hasktorch", - "repo": "libtorch-nix", - "rev": "d14b0fd10b96d192b92b8ccc7254ade4b3489331", - "type": "github" - }, - "original": { - "owner": "hasktorch", - "repo": "libtorch-nix", - "rev": "d14b0fd10b96d192b92b8ccc7254ade4b3489331", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1608007629, - "narHash": "sha256-lipVFC/a2pzzA5X2ULj64je+fz1JIp2XRrB5qyoizpQ=", - "owner": "NixOS", + "lastModified": 1736161650, + "narHash": "sha256-ShQLSxRTmuzbuXr9uqiDIsISjl+S7+oG/W4av8f9v9o=", + "owner": "junjihashimoto", "repo": "nixpkgs", - "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", + "rev": "5c77923028d8ec6c54dc9820e44bced372c68f3d", "type": "github" }, "original": { - "owner": "NixOS", + "owner": "junjihashimoto", "repo": "nixpkgs", - "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", + "rev": "5c77923028d8ec6c54dc9820e44bced372c68f3d", "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", - "repo": "nixpkgs", - "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", - "type": "github" - } - }, - "nixpkgs-unstable": { - "locked": { - "lastModified": 1612284693, - "narHash": "sha256-efzJNF1jvjK3BMl0gZ0ZaUWcFMv0nLb9AHN/++5+u0U=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "410bbd828cdc6156aecd5bc91772ad3a6b1099c7", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "410bbd828cdc6156aecd5bc91772ad3a6b1099c7", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1621433235, - "narHash": "sha256-eSBLBQxJoEIFVuBgxi0vLvVVyv+BS5YAC47a2rePw9Y=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "6cf64704297f60ca6ab579a4135bb565bb514b06", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, "root": { "inputs": { - "hackageSrc": "hackageSrc", - "haskell-nix": "haskell-nix", - "libtorch-nix": "libtorch-nix", - "nixpkgs": "nixpkgs_2", - "stackageSrc": "stackageSrc", + "nixpkgs": "nixpkgs", "utils": "utils" } }, - "stackageSrc": { - "flake": false, + "systems": { "locked": { - "lastModified": 1621299779, - "narHash": "sha256-zAu9jI9QWZhYWc+6l2gAPWKkkcO6DpX3MnYn8ftYaAU=", - "owner": "input-output-hk", - "repo": "stackage.nix", - "rev": "d387a944749263e4685cb116893c5226cd9fc75b", + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { - "owner": "input-output-hk", - "repo": "stackage.nix", + "owner": "nix-systems", + "repo": "default", "type": "github" } }, "utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1620759905, - "narHash": "sha256-WiyWawrgmyN0EdmiHyG2V+fqReiVi8bM9cRdMaKQOFg=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index aa681b4..cb2e9c3 100644 --- a/flake.nix +++ b/flake.nix @@ -1,112 +1,35 @@ { + nixConfig = { + bash-prompt = "\[hasktorch-skeleton$(__git_ps1 \" (%s)\")\]$ "; + }; 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; - }; + nixpkgs.url = "github:junjihashimoto/nixpkgs?rev=5c77923028d8ec6c54dc9820e44bced372c68f3d"; }; - 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; - }; - }; - } - ]; - - }; - - }; - in - { overlay = final: prev: { - "${name}" = ("${project-name}-overlay" final prev)."${project-name}".flake {}; + outputs = { self, nixpkgs, utils }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + config.cudaSupport = system == "x86_64-linux"; }; - } // (utils.lib.eachSystem [ "x86_64-linux" ] (system: - let - pkgs = import nixpkgs { - inherit system; - 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 - ]; - }; - 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; - }); - } - )); + ghcWithHasktorch = pkgs.haskellPackages.ghcWithPackages (pkgs: with pkgs; [ + hasktorch + haskell-language-server + ]); + in { + defaultPackage = pkgs.haskellPackages.callCabal2nix "hasktorch-skeleton" ./. {}; + devShell = with pkgs; mkShell { + buildInputs = [ + ghcWithHasktorch + cabal-install + stack + ]; + shellHook = '' + source ${git}/share/bash-completion/completions/git-prompt.sh + ''; + }; + }); } 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 diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 1f374c0..0000000 --- a/shell.nix +++ /dev/null @@ -1,41 +0,0 @@ -# This file is used by nix-shell. -# It just takes the shell attribute from default.nix. -{ config ? {} -, sourcesOverride ? {} -# If true, activates CUDA support -, cudaSupport ? false -# If cudaSupport is true, this needs to be set to a valid CUDA major version number, e.g. 10: -# nix-shell --arg cudaSupport true --argstr cudaMajorVersion 10 -, cudaMajorVersion ? null -, withHoogle ? false -, pkgs ? import ./nix/default.nix { - inherit config sourcesOverride cudaSupport cudaMajorVersion; - } -}: -with pkgs; -let - # This provides a development environment that can be used with nix-shell or - # lorri. See https://input-output-hk.github.io/haskell.nix/user-guide/development/ - shell = hasktorchSkeletonHaskellPackages.shellFor { - name = "hasktorch-skeleton-dev-shell"; - - tools = { - cabal = "3.2.0.0"; - haskell-language-server = "latest"; - }; - - # Prevents cabal from choosing alternate plans, so that - # *all* dependencies are provided by Nix. - # TODO: Set to true as soon as haskell.nix issue #231 is resolved. - exactDeps = false; - - shellHook = '' - export CPATH=${torch}/include/torch/csrc/api/include - ''; - - inherit withHoogle; - }; - -in - - shell diff --git a/stack.yaml b/stack.yaml index a88486a..32982fe 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,20 +1,13 @@ -resolver: nightly-2020-12-14 +resolver: lts-22.43 -compiler: ghc-8.10.4 +# compiler: ghc-9.6.6 packages: - . -extra-deps: -- git: git://github.com/hasktorch/hasktorch.git - commit: d7dd1f0a83971621526caf80c0dfafc5eb0bc8be - subdirs: - - libtorch-ffi-helper - - libtorch-ffi - - hasktorch -- stm-2.5.0.0@sha256:c238075f9f0711cd6a78eab6001b3e218cdaa745d6377bf83cc21e58ceec2ea1,2100 +allow-newer: true -nix: - shell-file: nix/stack-shell.nix +system-ghc: true -allow-newer: true +nix: + enable: false