diff options
Diffstat (limited to 'Com/Simatime/buildGhc.nix')
-rw-r--r-- | Com/Simatime/buildGhc.nix | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/Com/Simatime/buildGhc.nix b/Com/Simatime/buildGhc.nix index 489651e..2b578b8 100644 --- a/Com/Simatime/buildGhc.nix +++ b/Com/Simatime/buildGhc.nix @@ -1,17 +1,30 @@ - -nixpkgs: - -{ name # the main module namespace -, nick # a short name, for the executable -, deps # deps get passed to ghc -}: +nixpkgs: main: with nixpkgs; +with nixpkgs.lib; let - nsToPath = ns: builtins.toString (builtins.replaceStrings ["."] ["/"] ns); + # provided by .envrc + root = builtins.getEnv "BIZ_ROOT"; + + # general functions to put in a lib + lines = s: strings.splitString "\n" s; + seq = ls: builtins.filter (x: x!= null) ls; + + # turn the file path into a Haskell module name + relpath = builtins.replaceStrings ["${root}/"] [""] (builtins.toString main); + module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath; + + # extract info from special comments + content = builtins.readFile main; + exe = builtins.head (lists.flatten (seq + (map (builtins.match "^-- : exe ([[:alnum:]._-]*)$") + (lines content)))); + deps = lists.flatten (seq + (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$") + (lines content))); - path = nsToPath name; + # do the build... depsToPackageSet = packageSet: deps: map (s: builtins.getAttr s packageSet) deps; @@ -33,21 +46,21 @@ let ghc = ghc865_.ghcWithPackages (hp: depsToPackageSet hp deps); in stdenv.mkDerivation { - name = name; + name = module; version = "0"; src = ../../.; # this is the git root nativeBuildInputs = [ ghc ]; strictDeps = true; buildPhase = '' # - mkdir -p $out/{bin,static} ${path} + mkdir -p $out/{bin,static} ${baseNameOf relpath} # # compile with ghc # ${ghc}/bin/ghc -Werror -i. \ - --make ${path}.hs \ - -main-is ${name} \ - -o $out/bin/${nick} + --make ${main} \ + -main-is ${module} \ + -o $out/bin/${exe} ''; # the install process was handled above installPhase = "exit 0"; |