mirror of
https://github.com/nmattia/snack.git
synced 2024-09-11 11:55:36 +03:00
Merge pull request #111 from nmattia/nm-simple-ghci
Simplify GHCi and HPack code
This commit is contained in:
commit
e8cef886cf
@ -53,30 +53,6 @@ let
|
||||
ghcWith = deps: ghcWithPackages
|
||||
(ps: map (p: ps.${p}) deps);
|
||||
|
||||
specsFromPackageFile = packageFile:
|
||||
let
|
||||
basename = builtins.baseNameOf packageFile;
|
||||
components = pkgs.lib.strings.splitString "." basename;
|
||||
ext =
|
||||
if pkgs.lib.length components <= 1
|
||||
then abort ("File " ++ packageFile ++ " does not have an extension")
|
||||
else pkgs.lib.last components;
|
||||
fromNix = [(mkPackageSpec (import packageFile))];
|
||||
fromHPack =
|
||||
let
|
||||
descrs = pkgDescrsFromHPack packageFile;
|
||||
executables =
|
||||
builtins.map mkPackageSpec descrs.executables;
|
||||
library = withAttr descrs "library" null
|
||||
(comp: if builtins.isNull comp then null else mkPackageSpec comp);
|
||||
in executables ++ (if builtins.isNull library then [] else [ library ]);
|
||||
specs =
|
||||
if ext == "nix" then fromNix
|
||||
else if ext == "yaml" then fromHPack
|
||||
else if ext == "yml" then fromHPack
|
||||
else abort ("Unknown extension " ++ ext ++ " of file " ++ packageFile);
|
||||
in specs;
|
||||
|
||||
# Normal build (libs, exes)
|
||||
|
||||
inferBuild = packageFile:
|
||||
@ -143,6 +119,24 @@ let
|
||||
in modSpecs.${mainModName};
|
||||
in mainModSpec;
|
||||
|
||||
# Get a list of package specs from a file (.nix or .yaml)
|
||||
specsFromPackageFile = packageFile:
|
||||
let
|
||||
basename = builtins.baseNameOf packageFile;
|
||||
components = pkgs.lib.strings.splitString "." basename;
|
||||
ext =
|
||||
if pkgs.lib.length components <= 1
|
||||
then abort ("File " ++ packageFile ++ " does not have an extension")
|
||||
else pkgs.lib.last components;
|
||||
fromNix = [(mkPackageSpec (import packageFile))];
|
||||
fromHPack = builtins.map mkPackageSpec (pkgSpecsFromHPack packageFile);
|
||||
specs =
|
||||
if ext == "nix" then fromNix
|
||||
else if ext == "yaml" then fromHPack
|
||||
else if ext == "yml" then fromHPack
|
||||
else abort ("Unknown extension " ++ ext ++ " of file " ++ packageFile);
|
||||
in specs;
|
||||
|
||||
in
|
||||
{
|
||||
inherit
|
||||
|
@ -18,8 +18,7 @@ rec {
|
||||
ghcOpts = allTransitiveGhcOpts modSpecs
|
||||
++ (map (x: "-X${x}") (allTransitiveExtensions modSpecs));
|
||||
ghc = ghcWith (allTransitiveDeps modSpecs);
|
||||
ghciArgs = lib.strings.escapeShellArgs
|
||||
(ghcOpts ++ absoluteModuleFiles);
|
||||
ghciArgs = ghcOpts ++ absoluteModuleFiles;
|
||||
absoluteModuleFiles =
|
||||
map
|
||||
(mod:
|
||||
@ -29,17 +28,6 @@ rec {
|
||||
modSpecs;
|
||||
|
||||
dirs = allTransitiveDirectories modSpecs;
|
||||
newGhc =
|
||||
symlinkJoin
|
||||
{ name = "ghci";
|
||||
paths = [ ghc ];
|
||||
postBuild =
|
||||
''
|
||||
wrapProgram "$out/bin/ghci" \
|
||||
--add-flags "${ghciArgs}"
|
||||
'';
|
||||
buildInputs = [makeWrapper];
|
||||
};
|
||||
in
|
||||
# This symlinks the extra dirs to $PWD for GHCi to work
|
||||
writeScriptBin "ghci-with-files"
|
||||
@ -60,6 +48,6 @@ rec {
|
||||
done
|
||||
fi
|
||||
done
|
||||
${newGhc}/bin/ghci
|
||||
${ghc}/bin/ghci ${lib.strings.escapeShellArgs ghciArgs}
|
||||
'';
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
with (callPackage ./lib.nix {});
|
||||
with (callPackage ./modules.nix {});
|
||||
with (callPackage ./package-spec.nix {});
|
||||
|
||||
let
|
||||
y2j = runCommand "yaml2json"
|
||||
@ -24,7 +25,7 @@ in
|
||||
# Returns an attribute set with two fields:
|
||||
# - library: a package spec
|
||||
# - executable: an attr set of executable name to package spec
|
||||
pkgDescrsFromHPack = packageYaml:
|
||||
pkgSpecsFromHPack = packageYaml:
|
||||
let
|
||||
package = fromYAML (builtins.readFile packageYaml);
|
||||
|
||||
@ -35,8 +36,9 @@ in
|
||||
topDeps = mkDeps package;
|
||||
topExtensions = optAttr package "default-extensions" [];
|
||||
topGhcOpts = optAttr package "ghc-options" [];
|
||||
packageLib = withAttr package "library" null (component:
|
||||
{ src =
|
||||
libs = withAttr package "library" [] (component:
|
||||
[{
|
||||
src =
|
||||
let
|
||||
base = builtins.dirOf packageYaml;
|
||||
source-dirs = optAttr component "source-dirs" ".";
|
||||
@ -50,7 +52,7 @@ in
|
||||
dependencies = topDeps ++ mkDeps component;
|
||||
extensions = topExtensions ++ (optAttr component "extensions" []);
|
||||
ghcOpts = topGhcOpts ++ (optAttr component "ghc-options" []);
|
||||
}
|
||||
}]
|
||||
);
|
||||
|
||||
exes =
|
||||
@ -79,10 +81,7 @@ in
|
||||
dependencies = topDeps ++ dropVersionBounds depOrPack.wrong;
|
||||
extensions = topExtensions ++ (optAttr component "extensions" []);
|
||||
ghcOpts = topGhcOpts ++ (optAttr component "ghc-options" []);
|
||||
packages = map (_: packageLib) depOrPack.right;
|
||||
packages = if lib.length depOrPack.right > 0 then libs else [];
|
||||
};
|
||||
in
|
||||
{ library = packageLib;
|
||||
executables = exes;
|
||||
};
|
||||
in exes ++ libs;
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ rec {
|
||||
# TODO: merge extra files and extra dirs together
|
||||
packageExtraFiles = mkPerModuleAttr extra-files;
|
||||
packageExtraDirectories = mkPerModuleAttr extra-directories;
|
||||
|
||||
packagePackages = map mkPackageSpec packages;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user