From 68c292f966eaf72f2a33b1263b21b732829499ee Mon Sep 17 00:00:00 2001 From: Dixon Sean Low Yan Feng Date: Thu, 15 Jun 2023 22:10:31 +0800 Subject: [PATCH] fix: don't rely on string context for package source 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 (https://github.com/NixOS/nix/issues/8428) related to string contexts triggers an issue where setting the project root causes a type error with haskell-source-type (https://github.com/srid/haskell-flake/issues/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. --- nix/modules/project/packages/default.nix | 3 +-- nix/modules/project/packages/package.nix | 8 +++----- nix/types/haskell-source-type.nix | 15 --------------- 3 files changed, 4 insertions(+), 22 deletions(-) delete mode 100644 nix/types/haskell-source-type.nix diff --git a/nix/modules/project/packages/default.nix b/nix/modules/project/packages/default.nix index 219519be..5a39934c 100644 --- a/nix/modules/project/packages/default.nix +++ b/nix/modules/project/packages/default.nix @@ -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) diff --git a/nix/modules/project/packages/package.nix b/nix/modules/project/packages/package.nix index e7ea9fd5..bf5d9f39 100644 --- a/nix/modules/project/packages/package.nix +++ b/nix/modules/project/packages/package.nix @@ -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: @@ -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. }; diff --git a/nix/types/haskell-source-type.nix b/nix/types/haskell-source-type.nix deleted file mode 100644 index 8edec66b..00000000 --- a/nix/types/haskell-source-type.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ lib, ... }: - -let - isPathUnderNixStore = path: builtins.hasContext (builtins.toString path); -in -lib.mkOptionType { - name = "haskell-source"; - description = '' - Path to Haskell package source, or version from Hackage. - ''; - descriptionClass = "noun"; - check = path: - isPathUnderNixStore path || builtins.isString path; - merge = lib.mergeOneOption; -}