module Main where import Control.Applicative import Control.Monad import Data.Bifunctor import Data.Function import Data.Functor import Options.Applicative import System.FilePath (FilePath) import System.Process.Typed qualified as P -- import Turtle main :: IO () main = undefined flakeArg :: Parser Flake flakeArg = argument (maybeReader parseFlake) $ fold [ metavar "FLAKE" , help "Flake location" ] sysOption :: Parser String sysOption = strOption $ fold [ long "system" , metavar "SYSTEM" , help "Like x86_64-linux" ] koboConfigFlake :: Flake -> String -> Flake koboConfigFlake (Flake u a) sys = Flake u $ "koboConfigurations" : sys : a data Flake = Flake { uri :: !FilePath , attrs :: ![String] } deriving stock (Eq, Show) parseFlake :: String -> Maybe Flake parseFlake 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 data Action = Build | BuildFirmware | Deploy | DeployFirmware | Check deriving stock (Eq, Show) data CLIArgs = CLIArgs { _action :: !Action , _flake :: !Flake , _system :: !String } deriving stock (Eq, Show) runNix :: [String] -> IO () runNix = P.runProcess_ . P.proc "nix"