aboutsummaryrefslogtreecommitdiff
path: root/pkgs/manager
diff options
context:
space:
mode:
authorChris Wells <chris@mathematicaster.org>2024-09-11 12:51:28 -0500
committerChris Wells <chris@mathematicaster.org>2024-09-11 12:51:28 -0500
commita99ef161f3d04c04d1d55369d1250634d84a90c3 (patch)
treebbf702ae9ac9bc7cb0efa8f02ba5c40dfe436417 /pkgs/manager
parentc3052ddc4e54092bfc9220d550ab4d8fcba166de (diff)
downloadkobo-manager-a99ef161f3d04c04d1d55369d1250634d84a90c3.tar
kobo-manager-a99ef161f3d04c04d1d55369d1250634d84a90c3.tar.gz
kobo-manager-a99ef161f3d04c04d1d55369d1250634d84a90c3.tar.bz2
kobo-manager-a99ef161f3d04c04d1d55369d1250634d84a90c3.tar.lz
kobo-manager-a99ef161f3d04c04d1d55369d1250634d84a90c3.tar.xz
kobo-manager-a99ef161f3d04c04d1d55369d1250634d84a90c3.tar.zst
kobo-manager-a99ef161f3d04c04d1d55369d1250634d84a90c3.zip
Starting to write the actual cli managerHEADmaster
Diffstat (limited to 'pkgs/manager')
-rw-r--r--pkgs/manager/main.hs79
1 files changed, 58 insertions, 21 deletions
diff --git a/pkgs/manager/main.hs b/pkgs/manager/main.hs
index 6eac0a7..9909419 100644
--- a/pkgs/manager/main.hs
+++ b/pkgs/manager/main.hs
@@ -3,8 +3,10 @@ module Main where
import Control.Applicative
import Control.Monad
import Data.Bifunctor
+import Data.Foldable
import Data.Function
import Data.Functor
+import Data.List qualified as L
import Options.Applicative
import System.FilePath (FilePath)
import System.Process.Typed qualified as P
@@ -16,6 +18,14 @@ main :: IO ()
main = undefined
+run :: CLIArgs -> IO ()
+run c = runNix $
+ [ case _action c of
+ Build _ -> "build"
+ Deploy _ -> "run"
+ , flakeString (_flake c) (_system c) $ toKoboAttr $ _target . _action c
+ ] <> _nixArgs c
+
flakeArg :: Parser Flake
flakeArg = argument (maybeReader parseFlake) $ fold
@@ -27,44 +37,71 @@ sysOption :: Parser String
sysOption = strOption $ fold
[ long "system"
, metavar "SYSTEM"
- , help "Like x86_64-linux"
+ , help "e.g. x86_64-linux"
]
-koboConfigFlake :: Flake -> String -> Flake
-koboConfigFlake (Flake u a) sys = Flake u $ "koboConfigurations" : sys : a
+-- koboConfigFlake :: Flake -> String -> Flake
+-- koboConfigFlake (Flake u a) sys = Flake u $ "koboConfigurations" : sys :
+-- case a of
+-- [] -> [ "default" ]
+-- _ -> a
+
+
+flakeString :: KoboFlake -> NixSystem -> KoboAttr -> String
+flakeString (KoboFlake u n) sys attr = fold
+ [ q u
+ , "#"
+ , L.intercalate "." $ q <$> ([ "koboConfigurations", sys, n] <> attr)
+ ]
+ where
+ q s = "\"" <> s <> "\""
+
+
+type KoboAttr = [String]
-data Flake = Flake
- { uri :: !FilePath
- , attrs :: ![String]
+type NixSystem = String
+
+data KoboFlake = KoboFlake
+ { flakeURI :: !FilePath
+ , koboName :: !String
} deriving stock (Eq, Show)
-parseFlake :: String -> Maybe Flake
-parseFlake str =
+
+parseKoboFlake :: String -> Maybe Flake
+parseKoboFlake str =
let (u, a) = second (drop 1) $ break (== '#') str
in case u of
[] -> Nothing
- _ -> Flake u $ splitter a
- where
- splitter xs =
- let (y, ys) = second (drop 1) $ break (== '.') xs
- in case ys of
- [] -> [y]
- _ -> y : splitter ys
+ _ -> KoboFlake u $ case a of
+ [] -> "default"
+ _ -> a
+
+toKoboAttr :: Target -> KoboAttr
+toKoboAttr = ("build":) . \case
+ Firmware -> ["firmware" "deploy"]
+ UserSpace -> ["koboroot" "deploy"]
+ Info -> ["info"]
+
+type NixArgs = [String]
+
+data Target
+ = Firmware
+ | UserSpace
+ | Info
+ deriving (Eq, Show)
data Action
- = Build
- | BuildFirmware
- | Deploy
- | DeployFirmware
- | Check
+ = Build { _target :: !Target }
+ | Deploy { _target :: !Target }
deriving stock (Eq, Show)
data CLIArgs = CLIArgs
{ _action :: !Action
- , _flake :: !Flake
+ , _flake :: !KoboFlake
, _system :: !String
+ , _nixArgs :: ![String]
} deriving stock (Eq, Show)