Skip to content

Commit

Permalink
fix: don't rely on string context for package source
Browse files Browse the repository at this point in the history
Before this commit, the type of a package source (haskell-source-type)
depended on string contexts in its `check` function. However, string
contexts do not work well to represent a path to a package source. For
instance, "hello ./subdirectory" would have a string context, but is
obviously not a valid path.

Furthermore, a `nix` bug (NixOS/nix#8428)
related to string contexts triggers an issue where setting the project
root causes a type error with haskell-source-type (srid#169).

This commit replaces haskell-source-type with `with type; either path str`
and instances of `isPathUnderNixStore` with `lib.types.path.check` to
avoid using string contexts.
  • Loading branch information
dixslyf committed Jun 15, 2023
1 parent 908a591 commit 68c292f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
3 changes: 1 addition & 2 deletions nix/modules/project/packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ in
default = self: _super:
let
inherit (project.config) log;
isPathUnderNixStore = path: builtins.hasContext (builtins.toString path);
build-haskell-package = import ../../../build-haskell-package.nix {
inherit pkgs lib self log;
};
getOrMkPackage = name: cfg:
if isPathUnderNixStore cfg.source
if lib.types.path.check cfg.source
then
log.traceDebug "${name}.callCabal2nix ${cfg.source}"
(build-haskell-package name cfg.source)
Expand Down
8 changes: 3 additions & 5 deletions nix/modules/project/packages/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ let
inherit (lib)
mkOption
types;
# TODO: DRY
isPathUnderNixStore = path: builtins.hasContext (builtins.toString path);

# Whether the 'path' is local to `project.config.projectRoot`
localToProject = path:
path != null &&
isPathUnderNixStore path &&
lib.types.path.check path &&
lib.strings.hasPrefix "${project.config.projectRoot}" "${path}";
in
{ name, config, ... }: {
options = {
source = mkOption {
type = import ../../../types/haskell-source-type.nix { inherit lib; };
type = with types; either path str;
description = ''
Source refers to a Haskell package defined by one of the following:
Expand All @@ -43,7 +41,7 @@ in
'';
};
in
if isPathUnderNixStore config.source
if lib.types.path.check config.source
then haskell-parsers.getCabalExecutables config.source
else null; # cfg.source is Hackage version; nothing to do.
};
Expand Down
15 changes: 0 additions & 15 deletions nix/types/haskell-source-type.nix

This file was deleted.

0 comments on commit 68c292f

Please sign in to comment.