From 81ca2f40518052b7d8461d7efb489152c094a026 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:01:02 -0400 Subject: [PATCH] Remove automatic hpack conversion (#148) --- CHANGELOG.md | 1 + doc/start.md | 1 - nix/build-haskell-package.nix | 29 ++-------------------------- nix/haskell-parsers/README.md | 3 +-- nix/haskell-parsers/default.nix | 16 +-------------- nix/haskell-parsers/parser.nix | 12 ------------ nix/haskell-parsers/parser_tests.nix | 15 -------------- runtest.sh | 1 - test/README.md | 1 - test/hpack/flake.nix | 22 --------------------- test/hpack/package.yaml | 17 ---------------- test/hpack/src/Main.hs | 5 ----- test/hpack/test.sh | 9 --------- 13 files changed, 5 insertions(+), 127 deletions(-) delete mode 100644 test/hpack/flake.nix delete mode 100644 test/hpack/package.yaml delete mode 100644 test/hpack/src/Main.hs delete mode 100755 test/hpack/test.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index f7348a9..12ae355 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - #138: Add `checks` to `outputs` submodule - #143: Changed `autoWire` to be an enum type, for granular controlling of which outputs to autowire. - #137: Expose cabal executables as flake apps. Add a corresponding `outputs.apps` option, while the `outputs.localPackages` option is renamed to `outputs.packages` (it now contains package metadata, including packages and its executables). +- #148: Remove automatic hpack->cabal generation. Use `pre-commit-hooks.nix` instead. ## 0.2.0 (Mar 13, 2023) diff --git a/doc/start.md b/doc/start.md index c10369a..1e335fb 100644 --- a/doc/start.md +++ b/doc/start.md @@ -36,7 +36,6 @@ When nixifying a Haskell project without flake-parts (thus without haskell-flake In addition, compared to using plain nixpkgs, haskell-flake supports: - Auto-detection of local packages based on `cabal.project` file (via [haskell-parsers](https://github.com/srid/haskell-flake/tree/master/nix/haskell-parsers)) -- Support for hpack's `package.yaml` - Parse executables from `.cabal` file - Composition of dependency overrides, and other project settings, via [[modules]] diff --git a/nix/build-haskell-package.nix b/nix/build-haskell-package.nix index 18594a7..0fd208a 100644 --- a/nix/build-haskell-package.nix +++ b/nix/build-haskell-package.nix @@ -8,27 +8,6 @@ let fromSdist = self.buildFromCabalSdist or (builtins.trace "Your version of Nixpkgs does not support hs.buildFromCabalSdist yet." (pkg: pkg)); - # If `root` has package.yaml, but no cabal file, generate the cabal - # file and return the new source tree. - realiseHpack = name: root: - let - contents = lib.attrNames (builtins.readDir root); - hasCabal = lib.any (lib.strings.hasSuffix ".cabal") contents; - hasHpack = builtins.elem "package.yaml" contents; - in - if (!hasCabal && hasHpack) - then - pkgs.runCommand - "${name}-hpack" - { nativeBuildInputs = [ pkgs.hpack ]; } - '' - cp -r ${root} $out - chmod u+w $out - cd $out - hpack - '' - else root; - makeSrcAutonomous = name: root: pkg: hlib.overrideSrc { src = @@ -47,16 +26,12 @@ in name: pkgCfg: let - # NOTE: Even though cabal2nix does run hpack automatically, - # buildFromCabalSdist does not. So we must run hpack ourselves at - # the original source level. - root = realiseHpack name pkgCfg.root; - pkg = self.callCabal2nix name root { }; + pkg = self.callCabal2nix name pkgCfg.root { }; in lib.pipe pkg [ # Avoid rebuilding because of changes in parent directories - (makeSrcAutonomous name root) + (makeSrcAutonomous name pkgCfg.root) # Make sure all files we use are included in the sdist, as a check # for release-worthiness. diff --git a/nix/haskell-parsers/README.md b/nix/haskell-parsers/README.md index 95367ff..c11f189 100644 --- a/nix/haskell-parsers/README.md +++ b/nix/haskell-parsers/README.md @@ -1,10 +1,9 @@ # `haskell-parsers` -`haskell-parsers` provides parsers for Haskell associated files: hpack, cabal and cabal.project. It provides: +`haskell-parsers` provides parsers for Haskell associated files: cabal and cabal.project. It provides: - **`findPackagesInCabalProject`**: a superior alternative to nixpkgs' [`haskellPathsInDir`](https://github.com/NixOS/nixpkgs/blob/f991762ea1345d850c06cd9947700f3b08a12616/lib/filesystem.nix#L18). - It locates packages based on the "packages" field of `cabal.project` file if it exists (otherwise it returns the top-level package). - - It supports `hpack`, thus works with `package.yaml` even if no `.cabal` file exists. - **`getCabalExecutables`**: a function to extract executables from a `.cabal` file. ## Limitations diff --git a/nix/haskell-parsers/default.nix b/nix/haskell-parsers/default.nix index 5d13127..db8c12e 100644 --- a/nix/haskell-parsers/default.nix +++ b/nix/haskell-parsers/default.nix @@ -17,31 +17,17 @@ let else if num == 1 then builtins.head cabalFiles else throwError "Expected a single .cabal file, but found multiple: ${builtins.toJSON cabalFiles}"; - findSinglePackageYamlFile = path: - let f = path + "/package.yaml"; - in if builtins.pathExists f then f else null; getCabalName = lib.strings.removeSuffix ".cabal"; - getPackageYamlName = fp: - let - name = parser.parsePackageYamlName (builtins.readFile fp); - in - if name.type == "success" - then name.value - else throwError "Failed to parse ${fp}: ${builtins.toJSON name}"; findHaskellPackageNameOfDirectory = path: let cabalFile = findSingleCabalFile path; - packageYamlFile = findSinglePackageYamlFile path; in if cabalFile != null then getCabalName cabalFile - else if packageYamlFile != null - then - getPackageYamlName packageYamlFile else - throwError "Neither a .cabal file nor a package.yaml found under ${path}"; + throwError "No .cabal file found under ${path}"; }; in { diff --git a/nix/haskell-parsers/parser.nix b/nix/haskell-parsers/parser.nix index f492ae3..7866299 100644 --- a/nix/haskell-parsers/parser.nix +++ b/nix/haskell-parsers/parser.nix @@ -32,18 +32,6 @@ in in parsec.runParser parser cabalProjectFile; - # Extract the "name" field from a package.yaml file. - parsePackageYamlName = packageYamlFile: - let - spaces1 = parsec.skipWhile1 (c: c == " " || c == "\t"); - key = parsec.string "name:"; - val = parsec.fmap lib.concatStrings (parsec.many1 (parsec.anyCharBut "\n")); - parser = parsec.skipThen - (parsec.skipThen key spaces1) - val; - in - parsec.runParser parser packageYamlFile; - # Extract all the executables from a .cabal file parseCabalExecutableNames = cabalFile: with parsec; diff --git a/nix/haskell-parsers/parser_tests.nix b/nix/haskell-parsers/parser_tests.nix index 06c2bd7..0a4121b 100644 --- a/nix/haskell-parsers/parser_tests.nix +++ b/nix/haskell-parsers/parser_tests.nix @@ -18,20 +18,6 @@ let expected = [ "foo" "bar" ]; }; }; - packageYamlTests = - let - eval = s: - let res = parser.parsePackageYamlName s; in - if res.type == "success" then res.value else res; - in - { - testSimple = { - expr = eval '' - name: foo - ''; - expected = "foo"; - }; - }; cabalExecutableTests = let eval = s: @@ -68,6 +54,5 @@ let in { "cabal.project" = runTestsFailing cabalProjectTests; - "package.yaml" = runTestsFailing packageYamlTests; "foo-bar.cabal" = runTestsFailing cabalExecutableTests; } diff --git a/runtest.sh b/runtest.sh index 47a33d7..fbeecae 100755 --- a/runtest.sh +++ b/runtest.sh @@ -11,7 +11,6 @@ TESTS=( ./nix/haskell-parsers ./example ./test/simple - ./test/hpack ./test/with-subdir ./test/project-module ./doc diff --git a/test/README.md b/test/README.md index dcbe4c9..5a9621b 100644 --- a/test/README.md +++ b/test/README.md @@ -5,7 +5,6 @@ The following tests are available: | Directory | Description | | --- | --- | | `simple/` | Basic functionalities | -| `hpack` | `hpack` support | | `with-subdir` | Prevent redundant rebuilds when parent contents change | | `project-module`| Default project modules are generated correctly | diff --git a/test/hpack/flake.nix b/test/hpack/flake.nix deleted file mode 100644 index 135aa65..0000000 --- a/test/hpack/flake.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ - # Since there is no flake.lock file (to avoid incongruent haskell-flake - # pinning), we must specify revisions for *all* inputs to ensure - # reproducibility. - inputs = { - nixpkgs = { }; - flake-parts = { }; - haskell-flake = { }; - }; - outputs = inputs@{ self, nixpkgs, flake-parts, ... }: - flake-parts.lib.mkFlake { inherit inputs; } { - systems = nixpkgs.lib.systems.flakeExposed; - imports = [ - inputs.haskell-flake.flakeModule - ]; - perSystem = { self', pkgs, ... }: { - haskellProjects.default = { }; - # haskell-flake doesn't set the default package, but you can do it here. - packages.default = self'.packages.haskell-flake-test; - }; - }; -} diff --git a/test/hpack/package.yaml b/test/hpack/package.yaml deleted file mode 100644 index c1aa9a1..0000000 --- a/test/hpack/package.yaml +++ /dev/null @@ -1,17 +0,0 @@ -name: haskell-flake-test -version: 0.1.0.0 -license: NONE -author: Joe -maintainer: joe@example.com - -ghc-options: - - -Wall - -default-language: Haskell2010 - -executables: - haskell-flake-test: - main: Main.hs - dependencies: - - base - source-dirs: src diff --git a/test/hpack/src/Main.hs b/test/hpack/src/Main.hs deleted file mode 100644 index 96d9c0b..0000000 --- a/test/hpack/src/Main.hs +++ /dev/null @@ -1,5 +0,0 @@ -module Main where - -main :: IO () -main = do - putStrLn "Hello world, from hpack test" diff --git a/test/hpack/test.sh b/test/hpack/test.sh deleted file mode 100755 index 1470fab..0000000 --- a/test/hpack/test.sh +++ /dev/null @@ -1,9 +0,0 @@ -source ../common.sh -set -euxo pipefail - -# First, build the flake -logHeader "Testing nix build" -nix build ${OVERRIDE_ALL} -# Run the devshell test script in a nix develop shell. -logHeader "Testing nix devshell" -nix develop ${OVERRIDE_ALL} -c echo