From 2d78731477ae43a4fc2dd7331880f943db9505c2 Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Sat, 22 Oct 2022 02:24:10 -0700 Subject: [PATCH] translators/cabal-freeze: Read name and version from cabal file Also remove those fields from extraArgs. --- examples/haskell_cabal-freeze/flake.nix | 1 - .../translators/cabal-freeze/default.nix | 39 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/examples/haskell_cabal-freeze/flake.nix b/examples/haskell_cabal-freeze/flake.nix index 344ba178..902ee602 100644 --- a/examples/haskell_cabal-freeze/flake.nix +++ b/examples/haskell_cabal-freeze/flake.nix @@ -17,7 +17,6 @@ { translator = "cabal-freeze"; } - {subsystemInfo = {defaultPackageName = "unordered-containers";};} ]; }); } diff --git a/src/subsystems/haskell/translators/cabal-freeze/default.nix b/src/subsystems/haskell/translators/cabal-freeze/default.nix index 3b62dfeb..c8dd809c 100644 --- a/src/subsystems/haskell/translators/cabal-freeze/default.nix +++ b/src/subsystems/haskell/translators/cabal-freeze/default.nix @@ -112,8 +112,6 @@ in { tree, # arguments defined in `extraArgs` (see below) specified by user ghcVersion, - defaultPackageName, - defaultPackageVersion, ... } @ args: let # get the root source and project source @@ -121,6 +119,29 @@ in { projectSource = "${tree.fullPath}/${project.relPath}"; projectTree = tree.getNodeFromPath project.relPath; + # FIXME: This is the first of many snippets that will need to be modified to support multiple packages + cabalFileText = l.pipe projectTree.files [ + l.attrNames + ( + l.findFirst (l.hasSuffix ".cabal") + (throw "No cabal file in the tree") + ) + projectTree.getNodeFromPath + (l.attrByPath ["fullPath"] "") + dlib.readTextFile + (s: "\n" + s) + ]; + + defaultPackageName = l.pipe cabalFileText [ + (l.match ".*\nname:[[:space:]]+([^[:space:]]+).*") + l.head + ]; + + defaultPackageVersion = l.pipe cabalFileText [ + (l.match ".*\nversion:[[:space:]]+([^[:space:]]+).*") + l.head + ]; + parsedCabalFreeze = l.pipe projectTree.files [ l.attrNames ( @@ -277,19 +298,5 @@ in { examples = ["9.0.2" "9.4.1"]; type = "argument"; }; - - defaultPackageName = { - description = "Name of default package"; - default = "main"; - examples = ["main" "default"]; - type = "argument"; - }; - - defaultPackageVersion = { - description = "Version of default package"; - default = "unknown"; - examples = ["unknown" "1.2.0"]; - type = "argument"; - }; }; }