Remove automatic hpack conversion (#148)

This commit is contained in:
Sridhar Ratnakumar 2023-04-26 15:01:02 -04:00 committed by GitHub
parent 1f801ee0bf
commit 81ca2f4051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 5 additions and 127 deletions

View File

@ -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)

View File

@ -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]]

View File

@ -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.

View File

@ -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

View File

@ -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
{

View File

@ -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;

View File

@ -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;
}

View File

@ -11,7 +11,6 @@ TESTS=(
./nix/haskell-parsers
./example
./test/simple
./test/hpack
./test/with-subdir
./test/project-module
./doc

View File

@ -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 |

View File

@ -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;
};
};
}

View File

@ -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

View File

@ -1,5 +0,0 @@
module Main where
main :: IO ()
main = do
putStrLn "Hello world, from hpack test"

View File

@ -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