From ebefbd5ef277ac090021fd56f1eb6e75ed6e1f7c Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 8 Jan 2021 23:05:24 -0500 Subject: Refactor nix a bit Using lib.pipe for readability. Moved analyze into the public functions so I can debug things easier by calling bild.analyze from the nix repl. --- Biz/Bild/Rules.nix | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'Biz/Bild/Rules.nix') diff --git a/Biz/Bild/Rules.nix b/Biz/Bild/Rules.nix index 51fcb14..17461ef 100644 --- a/Biz/Bild/Rules.nix +++ b/Biz/Bild/Rules.nix @@ -25,6 +25,10 @@ let haskellDeps = hpkgs: import ./Deps/Haskell.nix hpkgs; + mkGhcPackageSet = pkgs.haskell.packages.${ghcCompiler}.ghcWithHoogle; + mkGhcjsPackageSet = pkgs.haskell.packages.${ghcjsCompiler}.ghcWithPackages; + +in rec { # gather data needed for compiling by analyzing the main module analyze = main: rec { # path to the module relative to the git root @@ -35,23 +39,29 @@ let # file contents content = builtins.readFile main; # search for the ': out' declaration - out = builtins.head (lib.lists.flatten (removeNull - (map (builtins.match "^-- : out ([[:alnum:]._-]*)$") - (lines content)))); + out = lib.pipe content [ + lines + (map (builtins.match "^-- : out ([[:alnum:]._-]*)$")) + removeNull + lib.lists.flatten + builtins.head + ]; # collect all of the ': dep' declarations - deps = lib.lists.flatten (removeNull - (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$") - (lines content))); - - sysdeps = lib.lists.flatten (removeNull - (map (builtins.match "^-- : sys ([[:alnum:]._-]*)$") - (lines content))); + deps = lib.pipe content [ + lines + (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$")) + removeNull + lib.lists.flatten + ]; + # collect ': sys' declarations + sysdeps = lib.pipe content [ + lines + (map (builtins.match "^-- : sys ([[:alnum:]._-]*)$")) + removeNull + lib.lists.flatten + ]; }; - mkGhcPackageSet = pkgs.haskell.packages.${ghcCompiler}.ghcWithHoogle; - mkGhcjsPackageSet = pkgs.haskell.packages.${ghcjsCompiler}.ghcWithPackages; - -in rec { ghcPackageSetFull = mkGhcPackageSet haskellDeps; ghc = main: -- cgit v1.2.3