@@ -25,6 +25,9 @@ module Obelisk.Command.Nix
2525 , boolArg
2626 , rawArg
2727 , strArg
28+ , NValue (..)
29+ , renderNValue
30+ , renderAttrset
2831 ) where
2932
3033import Control.Monad (guard)
@@ -33,8 +36,11 @@ import Control.Lens
3336import Data.Bool (bool)
3437import Data.Default
3538import Data.List (intercalate)
39+import Data.Map (Map)
40+import qualified Data.Map as M
3641import Data.Maybe
3742import Data.Monoid ((<>))
43+import Data.Text (Text)
3844import qualified Data.Text as T
3945import System.Process (proc)
4046
@@ -180,3 +186,16 @@ nixCmd cmdCfg = withSpinner' ("Running " <> cmd <> desc) (Just $ const $ "Built
180186 [ (" on " <>) <$> path
181187 , (\a -> " [" <> a <> "]") <$> (commonCfg ^. nixCmdConfig_target . target_attr)
182188 ]
189+
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+