aboutsummaryrefslogtreecommitdiff
path: root/pkgs/manager/main.hs
blob: 6eac0a7cf0538389ce0c75befdc97697eba12ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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"