on master help sign in
Begin using hnix for rendering attset
commitd9c11c50b760043ed3143697124a786c7661f833 authorLuigy Leon <luichi.19@gmail.com> dateMon 19 Nov 2018, 17:07 (8 years ago) parentdc992e3
4 files changed+30−32
default.nix+6 lib/command/obelisk-command.cabal+2 lib/command/src/Obelisk/Command/Deploy.hs+22−14 lib/command/src/Obelisk/Command/Nix.hs−18
default.nix+6
@@ -35,6 +35,12 @@ let
3535 (self: super: let
3636 pkgs = self.callPackage ({ pkgs }: pkgs) {};
3737 in {
38+ hnix = pkgs.haskell.lib.dontCheck (self.callCabal2nix "hnix" (pkgs.fetchFromGitHub {
39+ owner = "haskell-nix";
40+ repo = "hnix";
41+ rev = "42afdc21da5d9e076eab57eaa42bfdde938192b8";
42+ sha256 = "0psw384dx9bw2dp93xrzw8rd9amvcwgzn64jzzwby7sfspj6k349";
43+ }) {});
3844 # Need 8.0.2 build support
3945 # PR: https://github.com/dmwit/universe/pull/33
4046 universe-template = self.callCabal2nix "universe-template" (pkgs.fetchFromGitHub {
lib/command/obelisk-command.cabal+2
@@ -23,6 +23,7 @@ library
2323 , github
2424 , here
2525 , hit
26+ , hnix
2627 , hpack
2728 , io-streams
2829 , exceptions
@@ -43,6 +44,7 @@ library
4344 , time
4445 , transformers
4546 , unix
47+ , unordered-containers
4648 , yaml
4749 exposed-modules:
4850 Obelisk.App
lib/command/src/Obelisk/Command/Deploy.hs+22−14
@@ -4,6 +4,7 @@
44{-# LANGUAGE ScopedTypeVariables #-}
55{-# LANGUAGE ViewPatterns #-}
66{-# LANGUAGE DeriveGeneric #-}
7+{-# LANGUAGE TypeApplications #-}
78module Obelisk.Command.Deploy where
89
910import Control.Lens
@@ -14,21 +15,22 @@ import Data.Aeson (FromJSON, ToJSON, encode, eitherDecode)
1415import Data.Bits
1516import qualified Data.ByteString.Lazy as BSL
1617import Data.Default
17−import Data.List (isSuffixOf)
18−import Data.Map (Map)
18+import qualified Data.HashMap.Strict as HM
1919import qualified Data.Map as Map
20−import Data.Maybe
2120import Data.Text (Text)
2221import qualified Data.Set as Set
2322import qualified Data.Text as T
2423import qualified Data.Text.IO as T
2524import GHC.Generics
25+import Nix.Convert
26+import Nix.Pretty
27+import Nix.Value
2628import System.Directory
2729import System.Environment (getEnvironment)
2830import System.FilePath
2931import System.IO
3032import System.Posix.Files
31−import System.Process (delegate_ctlc, env, proc, readCreateProcess, cwd)
33+import System.Process (delegate_ctlc, env, proc, cwd)
3234import Text.URI (URI)
3335import qualified Text.URI as URI
3436import Text.URI.Lens
@@ -159,14 +161,18 @@ deployPush deployPath getNixBuilders = do
159161deployUpdate :: MonadObelisk m => FilePath -> m ()
160162deployUpdate deployPath = updateThunkToLatest $ deployPath </> "src"
161163
162−keytoolToAndroidConfig :: KeytoolConfig -> Map Text NValue
163−keytoolToAndroidConfig conf = Map.fromList
164− [ ("storeFile", NValue_Path $ _keytoolConfig_keystore conf)
165− , ("storePassword", NValue_Text $ T.pack $ _keytoolConfig_storepass conf)
166− , ("keyAlias", NValue_Text $ T.pack $ _keytoolConfig_alias conf)
167− , ("keyPassword", NValue_Text $ T.pack $ _keytoolConfig_keypass conf)
168− ]
169−
164+keytoolToAndroidConfig :: KeytoolConfig -> HM.HashMap Text (NValueNF Identity)
165+keytoolToAndroidConfig conf = runIdentity $ do
166+ path <- toValue $ Path $ _keytoolConfig_keystore conf
167+ storepass <- toValue $ T.pack $ _keytoolConfig_storepass conf
168+ alias <- toValue $ T.pack $ _keytoolConfig_alias conf
169+ keypass <- toValue $ T.pack $ _keytoolConfig_keypass conf
170+ return $ HM.fromList
171+ [ ("storeFile", path)
172+ , ("storePassword", storepass)
173+ , ("keyAlias", alias)
174+ , ("keyPassword", keypass)
175+ ]
170176
171177deployMobile :: MonadObelisk m => String -> [String] -> m ()
172178deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
@@ -200,13 +206,15 @@ deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
200206 liftIO $ putStrLn $ show keytoolConfContents
201207 releaseKey <- case eitherDecode keytoolConfContents of
202208 Left err -> failWith $ T.pack err
203− Right conf -> return $ renderAttrset $ keytoolToAndroidConfig conf
209+ Right conf -> do
210+ let nvset = toValue @(HM.HashMap Text (NValueNF Identity)) @Identity @(NValueNF Identity) $ keytoolToAndroidConfig conf
211+ return $ printNix $ runIdentity nvset
204212 result <- nixCmd $ NixCmd_Build $ def
205213 & nixBuildConfig_outLink .~ OutLink_None
206214 & nixCmdConfig_target .~ Target
207215 { _target_path = Nothing
208216 , _target_attr = Nothing
209− , _target_expr = Just $ "with (import " <> srcDir <> " {}); " <> platform <> ".frontend.override (drv: { releaseKey = (if builtins.isNull drv.releaseKey then {} else drv.releaseKey) // " <> T.unpack releaseKey <> "; })"
217+ , _target_expr = Just $ "with (import " <> srcDir <> " {}); " <> platform <> ".frontend.override (drv: { releaseKey = (if builtins.isNull drv.releaseKey then {} else drv.releaseKey) // " <> releaseKey <> "; })"
210218 }
211219 putLog Notice $ T.pack $ "Your recently built android apk can be found at the following path: " <> (show result)
212220 callProcessAndLogOutput (Notice, Error) $ proc (result </> "bin" </> "deploy") mobileArgs
lib/command/src/Obelisk/Command/Nix.hs−18
@@ -25,9 +25,6 @@ module Obelisk.Command.Nix
2525 , boolArg
2626 , rawArg
2727 , strArg
28− , NValue (..)
29− , renderNValue
30− , renderAttrset
3128 ) where
3229
3330import Control.Monad (guard)
@@ -36,11 +33,8 @@ import Control.Lens
3633import Data.Bool (bool)
3734import Data.Default
3835import Data.List (intercalate)
39−import Data.Map (Map)
40−import qualified Data.Map as M
4136import Data.Maybe
4237import Data.Monoid ((<>))
43−import Data.Text (Text)
4438import qualified Data.Text as T
4539import System.Process (proc)
4640
@@ -187,15 +181,3 @@ nixCmd cmdCfg = withSpinner' ("Running " <> cmd <> desc) (Just $ const $ "Built
187181 , (\a -> " [" <> a <> "]") <$> (commonCfg ^. nixCmdConfig_target . target_attr)
188182 ]
189183
190−data NValue
191− = NValue_Text Text
192− | NValue_Path FilePath
193−
194−renderNValue :: NValue -> Text
195−renderNValue = \case
196− NValue_Text x -> "\"" <> x <> "\""
197− NValue_Path p -> T.pack p
198−
199−renderAttrset :: Map Text NValue -> Text
200−renderAttrset m = "{ " <> T.unwords (map (\(k,v) -> k <> " = " <> renderNValue v <> ";") $ M.toList m) <> " }"
201−