diff options
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/manager/main.hs | 79 |
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) |
