diff --git a/.gitignore b/.gitignore index ff5cef7..6607c7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ TAGS dist-newstyle +result +result-* +tags diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..5b7cf58 --- /dev/null +++ b/default.nix @@ -0,0 +1,22 @@ +{ mkDerivation, base, bytestring, containers, exceptions, inline-c +, lib, primitive, process, python3-embed, quickcheck-instances, stm +, tasty, tasty-bench, tasty-hunit, tasty-quickcheck +, template-haskell, text, transformers, vector +}: +mkDerivation { + pname = "inline-python"; + version = "0.1.1.1"; + sha256 = "169f3xa2v53h5pqkc6h34wswyl0y3311xq66jwshxh80ynp37nj3"; + libraryHaskellDepends = [ + base bytestring containers exceptions inline-c primitive process + quickcheck-instances stm tasty tasty-hunit tasty-quickcheck + template-haskell text transformers vector + ]; + libraryPkgconfigDepends = [ python3-embed ]; + testHaskellDepends = [ base tasty ]; + benchmarkHaskellDepends = [ base tasty tasty-bench ]; + doHaddock = false; + homepage = "https://github.com/Shimuuar/inline-python"; + description = "Python interpreter embedded into haskell"; + license = lib.licenses.bsd3; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..830d181 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1743550720, + "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c621e8422220273271f52058f618c94e405bb0f5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1744868846, + "narHash": "sha256-5RJTdUHDmj12Qsv7XOhuospjAjATNiTMElplWnJE9Hs=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ebe4301cbd8f81c4f8d3244b3632338bbeb6d49c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1743296961, + "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..57a7486 --- /dev/null +++ b/flake.nix @@ -0,0 +1,113 @@ +{ + description = "Embedding of python interpreter into haskell programs"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = inputs @ { + self, + nixpkgs, + flake-parts, + ... + }: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = builtins.attrNames nixpkgs.legacyPackages; + perSystem = attrs @ { + system, + pkgs, + ... + }: let + pkgs = attrs.pkgs.extend self.overlays.default; + + py = pkgs.python3.withPackages (py_pkg: with py_pkg; + [ numpy + matplotlib + ]); + in { + devShells.default = pkgs.haskellPackages.shellFor { + name = "inline-python-devShell"; + packages = p: [p.inline-python]; + nativeBuildInputs = with pkgs.haskellPackages; [ + pkgs.cabal-install + cabal2nix + haskell-language-server + ]; + buildInputs = with pkgs; [ + py + pkg-config + ]; + + shellHook = '' + export PYTHONHOME=${py} + ''; + }; + + packages = rec { + default = inline-python; + inherit + (pkgs.haskellPackages) + inline-python + ; + }; + + }; + flake = { + overlays = { + default = final: prev: + with final.haskell.lib; + with final.lib; let + # NOTE: haskellPackages' so that we don't rebuild the world in the devShell + # due to the overrides + haskellPackages' = prev.haskellPackages.override (old: { + overrides = prev.lib.composeExtensions (old.overrides or (_: _: {})) ( + hself: hsuper: { + vector = dontCheck hsuper.vector_0_13_2_0; + primitive = hsuper.primitive_0_9_0_0; + scientific = hsuper.scientific_0_3_8_0; + uuid-types = hsuper.uuid-types_1_0_6; + quickcheck-instances = hsuper.quickcheck-instances_0_3_32; + + inline-python = (buildFromSdist ( + overrideCabal (hsuper.callPackage ./default.nix { + python3-embed = final.python3; + }) + (old: { + configureFlags = + (old.configureFlags or []) + ++ [ + "--ghc-options=-O2" + "--ghc-options=-j" + "--ghc-options=+RTS" + "--ghc-options=-A256m" + "--ghc-options=-n4m" + "--ghc-options=-RTS" + "--ghc-options=-Wall" + # "--ghc-options=-Werror" # the current version has a bunch of warnings + "--ghc-options=-Wincomplete-uni-patterns" + "--ghc-options=-Wincomplete-record-updates" + "--ghc-options=-Wpartial-fields" + "--ghc-options=-Widentities" + "--ghc-options=-Wredundant-constraints" + "--ghc-options=-Wcpp-undef" + "--ghc-options=-Wunused-packages" + "--ghc-options=-Wno-deprecations" + ]; + }) + )); + } + ); + }); + in { + haskellPackages = prev.haskellPackages.override (old: { + overrides = prev.lib.composeExtensions (old.overrides or (_: _: {})) ( + hself: hsuper: { + inline-python = haskellPackages'.inline-python; + }); + }); + }; + }; + }; + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..5b7cf58 --- /dev/null +++ b/package.nix @@ -0,0 +1,22 @@ +{ mkDerivation, base, bytestring, containers, exceptions, inline-c +, lib, primitive, process, python3-embed, quickcheck-instances, stm +, tasty, tasty-bench, tasty-hunit, tasty-quickcheck +, template-haskell, text, transformers, vector +}: +mkDerivation { + pname = "inline-python"; + version = "0.1.1.1"; + sha256 = "169f3xa2v53h5pqkc6h34wswyl0y3311xq66jwshxh80ynp37nj3"; + libraryHaskellDepends = [ + base bytestring containers exceptions inline-c primitive process + quickcheck-instances stm tasty tasty-hunit tasty-quickcheck + template-haskell text transformers vector + ]; + libraryPkgconfigDepends = [ python3-embed ]; + testHaskellDepends = [ base tasty ]; + benchmarkHaskellDepends = [ base tasty tasty-bench ]; + doHaddock = false; + homepage = "https://github.com/Shimuuar/inline-python"; + description = "Python interpreter embedded into haskell"; + license = lib.licenses.bsd3; +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 5b5a5cf..0000000 --- a/shell.nix +++ /dev/null @@ -1,17 +0,0 @@ -let - pkgs = import {}; - py = pkgs.python3.withPackages (py_pkg: with py_pkg; - [ numpy - matplotlib - ]); -in -pkgs.mkShell { - packages = with pkgs; [ - gcc - pkg-config - py - ]; - shellHook = '' - export PYTHONHOME=${py} - ''; -}