diff --git a/flake.lock b/flake.lock index 635df7ae4..323aca223 100644 --- a/flake.lock +++ b/flake.lock @@ -1,9 +1,47 @@ { "nodes": { + "butler": { + "inputs": { + "hspkgs": "hspkgs" + }, + "locked": { + "lastModified": 1692392907, + "narHash": "sha256-fbaMwZsvc2Pd5f7IqLezPzfQUS5DmPlCSdKYgUGrHAY=", + "owner": "TristanCacqueray", + "repo": "haskell-butler", + "rev": "235aa40e2d6ef2c33ca9f82a62dfd901cdbd4ae5", + "type": "github" + }, + "original": { + "owner": "TristanCacqueray", + "repo": "haskell-butler", + "rev": "235aa40e2d6ef2c33ca9f82a62dfd901cdbd4ae5", + "type": "github" + } + }, "hspkgs": { "inputs": { "nixpkgs": "nixpkgs" }, + "locked": { + "lastModified": 1691345406, + "narHash": "sha256-8dXDNPe2kwBVXWvcpdxmkPL4PiPv4099qmOgMNtGOb8=", + "owner": "podenv", + "repo": "hspkgs", + "rev": "f6893161b29a8086c7e1232c886a99a5d815ffae", + "type": "github" + }, + "original": { + "owner": "podenv", + "repo": "hspkgs", + "rev": "f6893161b29a8086c7e1232c886a99a5d815ffae", + "type": "github" + } + }, + "hspkgs_2": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, "locked": { "lastModified": 1691350685, "narHash": "sha256-Fdv6Xpc3SjheKcBCA+NEe3E6pX9wQ1ADhNv0UiM+VvA=", @@ -36,6 +74,22 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1691280800, + "narHash": "sha256-/0CqbbXO5qfyZ2DgyLIYGP7wT3ONNE3gtiE5gYG9zXE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e365e1db48d060b3e31b02ec8177f66f386f39b8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e365e1db48d060b3e31b02ec8177f66f386f39b8", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1652483617, "narHash": "sha256-Jxyn3uXFr5LdZNNiippI/obtLXAVBM18uVfiKVP4j9Q=", @@ -53,8 +107,9 @@ }, "root": { "inputs": { - "hspkgs": "hspkgs", - "nixpkgs": "nixpkgs_2" + "butler": "butler", + "hspkgs": "hspkgs_2", + "nixpkgs": "nixpkgs_3" } } }, diff --git a/flake.nix b/flake.nix index ea36dbbe3..0c007ad3e 100644 --- a/flake.nix +++ b/flake.nix @@ -26,14 +26,17 @@ "github:NixOS/nixpkgs/ed014c27f4d0ca772fb57d3b8985b772b0503bbd"; hspkgs.url = "github:podenv/hspkgs/e25ca08431a6bab2b9eccda1764269824fe786ea"; + butler.url = + "github:TristanCacqueray/haskell-butler/235aa40e2d6ef2c33ca9f82a62dfd901cdbd4ae5"; }; - outputs = { self, nixpkgs, hspkgs }: + outputs = { self, nixpkgs, hspkgs, butler }: let legacy = import ./nix/default.nix { nixpkgsPath = nixpkgs; hspkgs = hspkgs.pkgs; self = self; + butler = butler; }; in { haskellExtend = legacy.hExtend; diff --git a/monocle.cabal b/monocle.cabal index e10559bef..dde24d693 100644 --- a/monocle.cabal +++ b/monocle.cabal @@ -128,6 +128,7 @@ library , binary >= 0.8 , bloodhound ^>= 0.19 , bugzilla-redhat ^>= 1.0 + , butler , byteslice >= 0.2 , bytestring >= 0.10 , containers >= 0.6 @@ -213,6 +214,9 @@ library , CLI , Tests + -- butler + , Monocle.Butler + -- monocle api , Monocle.Entity , Monocle.Main diff --git a/nix/default.nix b/nix/default.nix index 2c0ed3d91..aefadf959 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,4 +1,4 @@ -{ elasticsearch-port ? 19200, nixpkgsPath, hspkgs, self }: +{ elasticsearch-port ? 19200, nixpkgsPath, hspkgs, butler, self }: let nixpkgsSrc = import nixpkgsPath; @@ -44,7 +44,7 @@ let config.allowUnfree = true; }; # final haskell set, see: https://github.com/NixOS/nixpkgs/issues/25887 - hsPkgs = hspkgs.hspkgs.extend haskellExtend; + hsPkgs = (hspkgs.hspkgs.extend butler.haskellExtend).extend haskellExtend; # manually adds build dependencies for benchmark and codegen that are not managed by cabal2nix addExtraDeps = drv: diff --git a/src/Monocle/Butler.hs b/src/Monocle/Butler.hs new file mode 100644 index 000000000..ee2476b05 --- /dev/null +++ b/src/Monocle/Butler.hs @@ -0,0 +1,46 @@ +-- | This module contains the new monocle app +module Monocle.Butler where + +import Butler +import Prelude + +import Monocle.Backend.Queries qualified as Q +import Monocle.Effects qualified as E +import Monocle.Env qualified as M +import Monocle.Logging qualified as E (runLoggerEffect) +import Monocle.Prelude (runEff) + +-- Here is a demo app that only display the current change count. +-- Given a elasticEnv, we can unwrap the effectful Eff context into butler's ProcessIO +dashboardApp :: E.ElasticEnv -> App +dashboardApp elasticEnv = defaultApp "dashboard" startDashboard + where + runEffects = liftIO . runEff . E.runLoggerEffect . E.runElasticEffect elasticEnv . E.runMonoQuery queryEnv + + startDashboard ctx = do + state <- newTVarIO 0 + let getChanges = runEffects do + -- Here is the demo of using the monocle backend: + count <- Q.countDocs + atomically do writeTVar state count + + -- make a query + getChanges + + let mountUI = with div_ [wid_ ctx.wid "w"] do + "Change count: " + count <- lift do readTVar state + toHtml (showT count) + + forever do + atomically (readPipe ctx.pipe) >>= \case + ae@AppDisplay {} -> sendHtmlOnConnect mountUI ae + _ -> pure () + + -- TODO: make this configurable by the user. + queryEnv :: E.MonoQueryEnv + queryEnv = + E.MonoQueryEnv + { queryTarget = M.QueryWorkspace (M.mkConfig "openstack") + , searchQuery = undefined + }