Skip to content
Snippets Groups Projects
Commit d6adbc7c authored by Daniel Firth's avatar Daniel Firth
Browse files

apps.procex: init with simple commands

parent f7a7a95b
Branches
No related merge requests found
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
program = "${run-impure-tests}/bin/run-impure-tests"; program = "${run-impure-tests}/bin/run-impure-tests";
}; };
procex = import ./shell/default.nix { haskellPackages = horizon-platform-prev.legacyPackages.${system}; inherit (pkgs) runCommand writeShellScriptBin; };
in in
{ {
...@@ -90,6 +91,11 @@ ...@@ -90,6 +91,11 @@
program = "${horizon-gen-gitlab-ci}/bin/gen-gitlab-ci"; program = "${horizon-gen-gitlab-ci}/bin/gen-gitlab-ci";
}; };
procex = {
type = "app";
program = "${procex}/bin/procex-shell";
};
run-impure-tests = run-impure-tests-app; run-impure-tests = run-impure-tests-app;
}; };
......
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# OPTIONS_GHC -Wno-missing-signatures #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}
module ShellRC where
import qualified Control.Lens as L
import qualified Data.Aeson as A
import qualified Data.Aeson.Key as A
import qualified Data.Aeson.KeyMap as A
import qualified Data.Aeson.Lens as L
import qualified Data.ByteString.Lazy as B
import Data.ByteString.Lazy.UTF8 as BLU
import qualified Data.ByteString.Lazy.UTF8 as BU
import qualified Data.Map as Map
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Yaml as Y
import qualified Data.Yaml.Pretty as Y
import Network.HTTP.Simple
import Path
import Procex.Prelude
import Procex.Shell hiding (promptFunction)
import System.Directory
import System.Environment
promptFunction :: [String] -> Int -> IO String
promptFunction _modules _line = do
d <- getEnv "PWD"
setCurrentDirectory d
pure $ d <> ": "
_init :: IO ()
_init = do
initInteractive
getEnv "REALHOME" >>= setEnv "HOME" -- Set by the script that launches GHCi
hackagePkg :: Text -> IO A.Value
hackagePkg x = do
k <- parseRequest $ "http://hackage.haskell.org/package/" <> T.unpack x
getResponseBody <$> httpJSON k
hackagePkgLatest :: Text -> IO Text
hackagePkgLatest x = Prelude.last . Map.keys . A.toMapText . L.view L._Object <$> hackagePkg x
runAllFeedback :: IO ()
runAllFeedback = do
(x :: Either Y.ParseException A.Value) <- Y.decodeFileEither "feedback.yaml"
t <- getEnv "TERM"
let y = Map.keys . A.toMapText . L.view (L._Right . L._Object . L.ix "loops" . L._Object) $ x
mapM_ (captureLazyNoThrow . mq t "--command" "nix" "run" "github:NorfairKing/feedback" "--" . T.unpack) y
{ haskellPackages, writeShellScriptBin, runCommand }:
let
shellrcSrcPath = ./.;
shellrcModule = "ShellRC";
shellrcSrc = shellrcSrcPath;
shellrcModulePath = builtins.replaceStrings [ "." ] [ "/" ] shellrcModule + ".hs";
ghc = haskellPackages.ghcWithPackages (p: with p; [
bytestring
containers
dhall
http-conduit
lens
lens-aeson
path
procex
text
yaml
]);
args = builtins.concatStringsSep " " [
"-XDataKinds"
"-XExtendedDefaultRules"
"-XGHC2021"
"-XOverloadedStrings"
"-XOverloadedLabels"
"-Wall"
"-Wno-type-defaults"
];
shellrc = runCommand "shellrc" { } ''
cp ${shellrcSrc} --no-preserve=all -rT $out
${ghc}/bin/ghc -c -dynamic --make -i"$out" ${args} $out/${shellrcModulePath}
'';
init = runCommand "ghci-init" { } ''
cat > $out <<END
:set +m -interactive-print Text.Pretty.Simple.pPrint
:l ${shellrcModule}
import Procex.Shell.Labels
:set prompt-function promptFunction
_init
END
grep -E '^import .*$' < ${shellrcSrc}/${shellrcModulePath} >> $out
'';
in
(writeShellScriptBin "procex-shell" ''
home="$HOME/.local/share/ghci-shell"
mkdir -p "$home"
exec env GHCRTS="-c" HOME="$home" REALHOME="$HOME" ${ghc}/bin/ghci ${args} -ignore-dot-ghci -i -i${shellrc} -ghci-script ${init} "$@"
'').overrideAttrs (old: old // { passthru = { shellPath = "/bin/procex-shell"; }; })
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment