mirror of
https://github.com/srid/haskell-flake.git
synced 2024-10-26 06:58:36 +03:00
Have packages
option auto-detect single-package projects (#75)
Co-authored-by: Ag <aravindmallapureddy@juspay.in> Co-authored-by: Sridhar Ratnakumar <srid@srid.ca>
This commit is contained in:
parent
026acf572f
commit
7019678d8c
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
- New features
|
- New features
|
||||||
- #63: Add `config.haskellProjects.${name}.outputs` containing all flake outputs for that project.
|
- #63: Add `config.haskellProjects.${name}.outputs` containing all flake outputs for that project.
|
||||||
|
- #49: The `packages` option now autodiscovers the top-level `.cabal` file as its default value.
|
||||||
- API changes
|
- API changes
|
||||||
- #37: Group `buildTools` (renamed to `tools`), `hlsCheck` and `hlintCheck` under the `devShell` submodule option; and allow disabling them all using `devShell.enable = false;` (useful if you want haskell-flake to produce just the package outputs).
|
- #37: Group `buildTools` (renamed to `tools`), `hlsCheck` and `hlintCheck` under the `devShell` submodule option; and allow disabling them all using `devShell.enable = false;` (useful if you want haskell-flake to produce just the package outputs).
|
||||||
- #64: Remove hlintCheck (use [treefmt-nix](https://github.com/numtide/treefmt-nix#flake-parts) instead)
|
- #64: Remove hlintCheck (use [treefmt-nix](https://github.com/numtide/treefmt-nix#flake-parts) instead)
|
||||||
|
@ -10,10 +10,7 @@
|
|||||||
imports = [ inputs.haskell-flake.flakeModule ];
|
imports = [ inputs.haskell-flake.flakeModule ];
|
||||||
perSystem = { self', pkgs, ... }: {
|
perSystem = { self', pkgs, ... }: {
|
||||||
haskellProjects.default = {
|
haskellProjects.default = {
|
||||||
packages = {
|
# packages.example.root = ./.; # This value is detected based on .cabal files
|
||||||
# You can add more than one local package here.
|
|
||||||
example.root = ./.; # Assumes ./example.cabal
|
|
||||||
};
|
|
||||||
# overrides = self: super: { };
|
# overrides = self: super: { };
|
||||||
# devShell = {
|
# devShell = {
|
||||||
# enable = true; # Enabled by default
|
# enable = true; # Enabled by default
|
||||||
|
@ -114,12 +114,53 @@ in
|
|||||||
description = ''
|
description = ''
|
||||||
Attrset of local packages in the project repository.
|
Attrset of local packages in the project repository.
|
||||||
|
|
||||||
Autodetected by default by looking for `.cabal` files in sub-directories.
|
Autodiscovered by default by looking for `.cabal` files in
|
||||||
|
top-level or sub-directories.
|
||||||
'';
|
'';
|
||||||
default =
|
default =
|
||||||
|
# We look for a single *.cabal in project root. Otherwise,
|
||||||
|
# look for multiple */*.cabal. Otherwise, error out.
|
||||||
|
#
|
||||||
|
# In future, we could just read `cabal.project`. See #76.
|
||||||
|
let
|
||||||
|
toplevel-cabal-paths =
|
||||||
|
lib.concatMapAttrs
|
||||||
|
(f: _:
|
||||||
|
if lib.strings.hasSuffix ".cabal" f
|
||||||
|
then { "${lib.strings.removeSuffix ''.cabal'' f}" = self; }
|
||||||
|
else { }
|
||||||
|
)
|
||||||
|
(builtins.readDir self);
|
||||||
|
subdir-cabal-paths = lib.filesystem.haskellPathsInDir self;
|
||||||
|
errorNoDefault = msg:
|
||||||
|
lib.asserts.assertMsg false ''
|
||||||
|
A default value for `packages` cannot be auto-detected:
|
||||||
|
|
||||||
|
${msg}
|
||||||
|
You must manually specify the `packages` option.
|
||||||
|
'';
|
||||||
|
cabal-paths =
|
||||||
|
if toplevel-cabal-paths != { }
|
||||||
|
then
|
||||||
|
let cabalNames = lib.attrNames toplevel-cabal-paths;
|
||||||
|
in if builtins.length cabalNames > 1
|
||||||
|
then
|
||||||
|
errorNoDefault ''
|
||||||
|
More than one .cabal file found in project root:
|
||||||
|
|
||||||
|
- ${lib.concatStringsSep ".cabal\n - " cabalNames}.cabal
|
||||||
|
''
|
||||||
|
else
|
||||||
|
toplevel-cabal-paths
|
||||||
|
else if subdir-cabal-paths != { }
|
||||||
|
then
|
||||||
|
subdir-cabal-paths
|
||||||
|
else
|
||||||
|
errorNoDefault "No .cabal file found.";
|
||||||
|
in
|
||||||
lib.mapAttrs
|
lib.mapAttrs
|
||||||
(_: value: { root = value; })
|
(_: value: { root = value; })
|
||||||
(lib.filesystem.haskellPathsInDir self);
|
cabal-paths;
|
||||||
defaultText = lib.literalMD "autodiscovered by reading `self` files.";
|
defaultText = lib.literalMD "autodiscovered by reading `self` files.";
|
||||||
};
|
};
|
||||||
devShell = mkOption {
|
devShell = mkOption {
|
||||||
|
12
runtest.sh
12
runtest.sh
@ -13,9 +13,17 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
FLAKE=$(pwd)
|
FLAKE=$(pwd)
|
||||||
cd ./test
|
|
||||||
|
|
||||||
# First, build the flake.
|
# A Nix bug causes incorrect self when in a sub-flake.
|
||||||
|
# https://github.com/NixOS/nix/issues/7263
|
||||||
|
# Workaround: copy ./test somewhere outside of this Git repo.
|
||||||
|
TESTDIR=$(mktemp -d)
|
||||||
|
trap 'rm -fr "$TESTDIR"' EXIT
|
||||||
|
cp -r ./test/* "$TESTDIR"
|
||||||
|
cd "$TESTDIR"
|
||||||
|
pwd
|
||||||
|
|
||||||
|
# First, build the flake
|
||||||
logHeader "Testing nix build"
|
logHeader "Testing nix build"
|
||||||
nix build --override-input haskell-flake path:${FLAKE}
|
nix build --override-input haskell-flake path:${FLAKE}
|
||||||
# Run the devshell test script in a nix develop shell.
|
# Run the devshell test script in a nix develop shell.
|
||||||
|
@ -24,10 +24,6 @@
|
|||||||
];
|
];
|
||||||
perSystem = { self', pkgs, ... }: {
|
perSystem = { self', pkgs, ... }: {
|
||||||
haskellProjects.default = {
|
haskellProjects.default = {
|
||||||
packages = {
|
|
||||||
# You can add more than one local package here.
|
|
||||||
haskell-flake-test.root = ./.; # Assumes ./haskell-flake-test.cabal
|
|
||||||
};
|
|
||||||
overrides = self: super: {
|
overrides = self: super: {
|
||||||
# Custom library overrides (here, "foo" comes from a flake input)
|
# Custom library overrides (here, "foo" comes from a flake input)
|
||||||
foo = self.callCabal2nix "foo" (inputs.haskell-multi-nix + /foo) { };
|
foo = self.callCabal2nix "foo" (inputs.haskell-multi-nix + /foo) { };
|
||||||
|
Loading…
Reference in New Issue
Block a user