1
1
mirror of https://github.com/nmattia/niv.git synced 2024-11-08 08:26:02 +03:00
niv/Main.hs

559 lines
18 KiB
Haskell
Raw Normal View History

2019-01-23 23:55:26 +03:00
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
2019-01-28 23:25:09 +03:00
{-# LANGUAGE QuasiQuotes #-}
2019-01-24 23:58:22 +03:00
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ViewPatterns #-}
2019-01-23 23:55:26 +03:00
2019-01-28 23:25:09 +03:00
{-# OPTIONS_GHC "-Wall" #-}
module Main (main) where
2019-01-18 01:00:48 +03:00
-- TODO: qualified imports
-- TODO: format code
2019-01-28 23:25:09 +03:00
-- TODO: document commands
2019-01-18 01:00:48 +03:00
import Control.Monad
2019-01-27 01:39:38 +03:00
import Control.Monad.State
2019-01-27 23:18:10 +03:00
import Control.Applicative
2019-01-23 23:55:26 +03:00
import Data.Aeson
2019-01-24 23:58:22 +03:00
import Data.Char (toUpper)
2019-01-23 23:55:26 +03:00
import Data.Hashable (Hashable)
2019-01-27 23:18:10 +03:00
import Data.Maybe (mapMaybe, fromMaybe)
2019-01-18 01:00:48 +03:00
import Data.Semigroup ((<>))
2019-01-27 01:39:38 +03:00
import GHC.Exts (toList)
2019-01-18 01:00:48 +03:00
import System.Directory
import System.FilePath
2019-01-27 23:18:10 +03:00
import System.Process (readProcess)
2019-01-28 23:25:09 +03:00
import Data.String.QQ (s)
2019-01-23 23:55:26 +03:00
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
2019-01-24 23:58:22 +03:00
import qualified Data.HashMap.Strict as HMap
2019-01-23 23:55:26 +03:00
import qualified Data.Text as T
2019-01-27 01:39:38 +03:00
import qualified GitHub as GH
import qualified GitHub.Data.Name as GH
2019-01-27 23:18:10 +03:00
import qualified Options.Applicative as Opts
2019-01-18 01:00:48 +03:00
2019-01-24 23:58:22 +03:00
newtype VersionsSpec = VersionsSpec
{ unVersionsSpec :: HMap.HashMap PackageName PackageSpec }
deriving newtype (FromJSON, ToJSON)
2019-01-23 23:55:26 +03:00
getVersionsSpec :: IO VersionsSpec
getVersionsSpec = do
putStrLn $ "Reading versions file"
2019-01-28 23:25:09 +03:00
decodeFileStrict pathNixVersionsJson >>= \case
2019-01-27 23:18:10 +03:00
Just (Object obj) ->
2019-01-23 23:55:26 +03:00
fmap (VersionsSpec . mconcat) $
2019-01-27 23:18:10 +03:00
forM (HMap.toList obj) $ \(k, v) ->
2019-01-23 23:55:26 +03:00
case v of
Object v' ->
pure $ HMap.singleton (PackageName (T.unpack k)) (PackageSpec v')
_ -> error "baaaaz"
Just _ -> error "foo"
Nothing -> error "Cannot decode versions"
2019-01-27 23:18:10 +03:00
setVersionsSpec :: VersionsSpec -> IO ()
2019-01-28 23:25:09 +03:00
setVersionsSpec versionsSpec = encodeFile pathNixVersionsJson versionsSpec
2019-01-27 23:18:10 +03:00
2019-01-23 23:55:26 +03:00
newtype PackageName = PackageName { unPackageName :: String }
2019-01-24 23:58:22 +03:00
deriving newtype (Eq, Hashable, FromJSONKey, ToJSONKey, Show)
2019-01-27 23:18:10 +03:00
parsePackageName :: Opts.Parser PackageName
parsePackageName = PackageName <$>
Opts.argument Opts.str (Opts.metavar "PACKAGE")
2019-01-23 23:55:26 +03:00
newtype PackageSpec = PackageSpec { unPackageSpec :: Object }
2019-01-24 23:58:22 +03:00
deriving newtype (FromJSON, ToJSON, Show)
2019-01-23 23:55:26 +03:00
2019-01-27 23:18:10 +03:00
parsePackageSpec :: Opts.Parser PackageSpec
2019-01-24 23:58:22 +03:00
parsePackageSpec =
(PackageSpec . HMap.fromList . fmap fixupAttributes) <$>
many parseAttribute
where
2019-01-27 23:18:10 +03:00
parseAttribute :: Opts.Parser (String, String)
2019-01-24 23:58:22 +03:00
parseAttribute = shortcutAttributes <|>
2019-01-27 23:18:10 +03:00
Opts.option (Opts.maybeReader parseKeyVal)
( Opts.long "attribute" <>
Opts.short 'a' <>
Opts.metavar "KEY=VAL"
2019-01-24 23:58:22 +03:00
)
2019-01-23 23:55:26 +03:00
2019-01-24 23:58:22 +03:00
-- Parse "key=val" into ("key", "val")
parseKeyVal :: String -> Maybe (String, String)
parseKeyVal str = case span (/= '=') str of
(key, '=':val) -> Just (key, val)
_ -> Nothing
-- Shortcuts for common attributes
2019-01-27 23:18:10 +03:00
shortcutAttributes :: Opts.Parser (String, String)
2019-01-24 23:58:22 +03:00
shortcutAttributes = foldr (<|>) empty $ mkShortcutAttribute <$>
2019-01-27 23:18:10 +03:00
[ "branch", "owner", "repo" ]
2019-01-24 23:58:22 +03:00
2019-01-27 23:18:10 +03:00
mkShortcutAttribute :: String -> Opts.Parser (String, String)
mkShortcutAttribute = \case
attr@(c:_) -> (attr,) <$> Opts.strOption
( Opts.long attr <> Opts.short c <> Opts.metavar (toUpper <$> attr) )
_ -> error "The attribute name should not be an empty string"
2019-01-24 23:58:22 +03:00
fixupAttributes :: (String, String) -> (T.Text, Value)
fixupAttributes (k, v) = (T.pack k, String (T.pack v))
2019-01-27 23:18:10 +03:00
parsePackage :: Opts.Parser (PackageName, PackageSpec)
2019-01-24 23:58:22 +03:00
parsePackage = (,) <$> parsePackageName <*> parsePackageSpec
2019-01-27 23:18:10 +03:00
-------------------------------------------------------------------------------
-- PACKAGE SPEC OPS
-------------------------------------------------------------------------------
updatePackageSpec :: PackageSpec -> IO PackageSpec
updatePackageSpec = execStateT $ do
-- Figures out the URL from the template
withPackageSpecAttr "url_template" (\case
String (T.unpack -> template) -> do
packageSpec <- get
let stringValues = packageSpecStringValues packageSpec
case renderTemplate stringValues template of
Just renderedURL ->
setPackageSpecAttr "url" (String $ T.pack renderedURL)
Nothing -> pure ()
_ -> pure ()
)
-- Updates the sha256 based on the URL contents
withPackageSpecAttr "url" (\case
String (T.unpack -> url) -> do
sha256 <- liftIO $ nixPrefetchURL url
setPackageSpecAttr "sha256" (String $ T.pack sha256)
_ -> pure ()
)
completePackageSpec
:: PackageSpec
-> IO (PackageSpec)
completePackageSpec = execStateT $ do
-- In case we have @owner@ and @repo@, pull some data from GitHub
(,) <$> getPackageSpecAttr "owner" <*> getPackageSpecAttr "repo" >>= \case
(Just (String owner), Just (String repo)) -> do
liftIO (GH.executeRequest' $ GH.repositoryR (GH.N owner) (GH.N repo))
>>= \case
Left _ -> pure ()
Right ghRepo -> do
-- Description
whenNotSet "description" $ case GH.repoDescription ghRepo of
Just descr -> setPackageSpecAttr "description" (String descr)
Nothing -> pure ()
-- Branch and rev
whenNotSet "branch" $ case GH.repoDefaultBranch ghRepo of
Just branch -> setPackageSpecAttr "branch" (String branch)
Nothing -> pure ()
withPackageSpecAttr "branch" (\case
String branch -> do
liftIO (GH.executeRequest' $
GH.commitsWithOptionsForR
(GH.N owner) (GH.N repo) (GH.FetchAtLeast 1)
[GH.CommitQuerySha branch]) >>= \case
Right (toList -> (commit:_)) -> do
let GH.N rev = GH.commitSha commit
setPackageSpecAttr "rev" (String rev)
_ -> pure ()
_ -> pure ()
)
(_,_) -> pure ()
-- Figures out the URL template
whenNotSet "url_template" $
setPackageSpecAttr "url_template" (String $ T.pack githubURLTemplate)
where
githubURLTemplate :: String
githubURLTemplate =
"https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
2019-01-27 01:39:38 +03:00
-------------------------------------------------------------------------------
-- PackageSpec State helpers
-------------------------------------------------------------------------------
2019-01-23 23:55:26 +03:00
2019-01-27 01:39:38 +03:00
whenNotSet
:: T.Text
2019-01-27 23:18:10 +03:00
-> StateT PackageSpec IO ()
-> StateT PackageSpec IO ()
2019-01-27 01:39:38 +03:00
whenNotSet attrName act = getPackageSpecAttr attrName >>= \case
Just _ -> pure ()
Nothing -> act
withPackageSpecAttr
:: T.Text
2019-01-27 23:18:10 +03:00
-> (Value -> StateT PackageSpec IO ())
-> StateT PackageSpec IO ()
2019-01-27 01:39:38 +03:00
withPackageSpecAttr attrName act = getPackageSpecAttr attrName >>= \case
Just v -> act v
Nothing -> pure ()
getPackageSpecAttr
:: T.Text
2019-01-27 23:18:10 +03:00
-> StateT PackageSpec IO (Maybe Value)
2019-01-27 01:39:38 +03:00
getPackageSpecAttr attrName = do
2019-01-27 23:18:10 +03:00
PackageSpec obj <- get
2019-01-27 01:39:38 +03:00
pure $ HMap.lookup attrName obj
setPackageSpecAttr
:: T.Text -> Value
2019-01-27 23:18:10 +03:00
-> StateT PackageSpec IO ()
2019-01-27 01:39:38 +03:00
setPackageSpecAttr attrName attrValue = do
2019-01-27 23:18:10 +03:00
PackageSpec obj <- get
2019-01-27 01:39:38 +03:00
let obj' = HMap.insert attrName attrValue obj
2019-01-27 23:18:10 +03:00
put (PackageSpec obj')
2019-01-27 01:39:38 +03:00
packageSpecStringValues :: PackageSpec -> [(String, String)]
packageSpecStringValues (PackageSpec m) = mapMaybe toVal (HMap.toList m)
where
toVal :: (T.Text, Value) -> Maybe (String, String)
toVal = \case
(key, String val) -> Just (T.unpack key, T.unpack val)
_ -> Nothing
2019-01-23 23:55:26 +03:00
-------------------------------------------------------------------------------
-- INIT
-------------------------------------------------------------------------------
2019-01-27 23:18:10 +03:00
parseCmdInit :: Opts.ParserInfo (IO ())
parseCmdInit = (Opts.info (pure cmdInit <**> Opts.helper)) Opts.fullDesc
2019-01-23 23:55:26 +03:00
2019-01-18 01:00:48 +03:00
cmdInit :: IO ()
cmdInit = do
2019-01-28 23:25:09 +03:00
-- Writes all the default files
forM_
[ (pathNixVersionsJson, initNixVersionsJsonContent)
, (pathNixFetchNix, initNixFetchNixContent)
, (pathNixDefaultNix, initNixDefaultNixContent)
, (pathDefaultNix, initDefaultNixContent)
, (pathShellNix, initShellNixContent)
] $ \(path, content) -> do
putStrLn $ "Creating file " <> path <> " (if it doesn't exist)"
let dir = takeDirectory path
createDirectoryIfMissing True dir
exists <- doesFileExist path
if exists
then do
putStrLn $ "Not creating " <> path <> " (already exists)"
else do
putStrLn $ "Creating " <> path <> " (doesn't exist)"
writeFile path content
-- Imports @niv@ and @nixpkgs@ (18.09)
putStrLn "Importing 'niv' ..."
cmdAdd (PackageName "nmattia/niv", PackageSpec HMap.empty) Nothing
putStrLn "Importing 'nixpkgs' ..."
cmdAdd
( PackageName "NixOS/nixpkgs-channels"
, PackageSpec (HMap.singleton "branch" "nixos-18.09"))
(Just (PackageName "nixpkgs"))
2019-01-18 01:00:48 +03:00
2019-01-23 23:55:26 +03:00
-------------------------------------------------------------------------------
-- ADD
-------------------------------------------------------------------------------
2019-01-27 23:18:10 +03:00
parseCmdAdd :: Opts.ParserInfo (IO ())
parseCmdAdd =
Opts.info ((cmdAdd <$> parsePackage <*> optName) <**> Opts.helper)
Opts.fullDesc
where
optName :: Opts.Parser (Maybe PackageName)
optName = Opts.optional $ PackageName <$> Opts.strOption
( Opts.long "name" <>
Opts.short 'n' <>
Opts.metavar "NAME"
)
2019-01-23 23:55:26 +03:00
2019-01-27 23:18:10 +03:00
cmdAdd :: (PackageName, PackageSpec) -> Maybe PackageName -> IO ()
cmdAdd (PackageName str, spec) mPackageName = do
2019-01-27 01:39:38 +03:00
-- Figures out the owner and repo
2019-01-27 23:18:10 +03:00
(packageName, spec') <- flip runStateT spec $ case span (/= '/') str of
2019-01-27 01:39:38 +03:00
(owner@(_:_), '/':repo@(_:_)) -> do
whenNotSet "owner" $
setPackageSpecAttr "owner" (String $ T.pack owner)
whenNotSet "repo" $ do
setPackageSpecAttr "repo" (String $ T.pack repo)
2019-01-27 23:18:10 +03:00
pure (PackageName repo)
_ -> pure (PackageName str)
2019-01-27 01:39:38 +03:00
2019-01-28 23:25:09 +03:00
versionsSpec <- unVersionsSpec <$> getVersionsSpec
2019-01-27 01:39:38 +03:00
2019-01-27 23:18:10 +03:00
let packageName' = fromMaybe packageName mPackageName
2019-01-27 01:39:38 +03:00
2019-01-27 23:18:10 +03:00
when (HMap.member packageName' versionsSpec) $ do
error $ unlines
[ "Use niv drop <package> and then niv add"
, "Or use nix update --attr foo bar to update"
]
2019-01-27 01:39:38 +03:00
2019-01-27 23:18:10 +03:00
spec'' <- updatePackageSpec =<< completePackageSpec spec'
2019-01-27 01:39:38 +03:00
2019-01-27 23:18:10 +03:00
putStrLn $ "Writing new versions file"
setVersionsSpec $ VersionsSpec $
HMap.insert packageName' spec'' versionsSpec
2019-01-24 23:58:22 +03:00
2019-01-23 23:55:26 +03:00
-------------------------------------------------------------------------------
-- SHOW
-------------------------------------------------------------------------------
2019-01-18 01:00:48 +03:00
2019-01-27 23:18:10 +03:00
parseCmdShow :: Opts.ParserInfo (IO ())
parseCmdShow = Opts.info (pure cmdShow <**> Opts.helper) Opts.fullDesc
2019-01-24 23:58:22 +03:00
2019-01-18 01:00:48 +03:00
cmdShow :: IO ()
2019-01-23 23:55:26 +03:00
cmdShow = do
putStrLn $ "Showing versions file"
2019-01-28 23:25:09 +03:00
fileVersionsValue <- unVersionsSpec <$> getVersionsSpec
2019-01-23 23:55:26 +03:00
forWithKeyM_ fileVersionsValue $ \key (PackageSpec spec) -> do
putStrLn $ "Package: " <> unPackageName key
forM_ (HMap.toList spec) $ \(attrName, attrValValue) -> do
let attrValue = case attrValValue of
String str -> str
_ -> "<barabajagal>"
putStrLn $ " " <> T.unpack attrName <> ": " <> T.unpack attrValue
-------------------------------------------------------------------------------
-- UPDATE
-------------------------------------------------------------------------------
2019-01-18 01:00:48 +03:00
2019-01-27 23:18:10 +03:00
parseCmdUpdate :: Opts.ParserInfo (IO ())
parseCmdUpdate =
Opts.info
((cmdUpdate <$> Opts.optional parsePackage) <**> Opts.helper)
Opts.fullDesc
2019-01-24 23:58:22 +03:00
2019-01-27 23:18:10 +03:00
cmdUpdate :: Maybe (PackageName, PackageSpec) -> IO ()
cmdUpdate = \case
Just (packageName, packageSpec) -> do
putStrLn $ "Updating single package: " <> unPackageName packageName
2019-01-28 23:25:09 +03:00
versionsSpec <- unVersionsSpec <$> getVersionsSpec
2019-01-23 23:55:26 +03:00
2019-01-27 23:18:10 +03:00
packageSpec' <- case HMap.lookup packageName versionsSpec of
Just packageSpec' -> do
updatePackageSpec $ PackageSpec $ HMap.union
(unPackageSpec packageSpec)
(unPackageSpec packageSpec')
Nothing -> error $ "Package not found: " <> unPackageName packageName
2019-01-23 23:55:26 +03:00
2019-01-27 23:18:10 +03:00
setVersionsSpec $ VersionsSpec $
HMap.insert packageName packageSpec' versionsSpec
2019-01-23 23:55:26 +03:00
2019-01-27 23:18:10 +03:00
Nothing -> do
2019-01-28 23:25:09 +03:00
versionsSpec <- unVersionsSpec <$> getVersionsSpec
2019-01-23 23:55:26 +03:00
2019-01-27 23:18:10 +03:00
versionsSpec' <- forWithKeyM versionsSpec $
\packageName packageSpec -> do
putStrLn $ "Package: " <> unPackageName packageName
updatePackageSpec packageSpec
2019-01-23 23:55:26 +03:00
2019-01-27 23:18:10 +03:00
setVersionsSpec $ VersionsSpec versionsSpec'
2019-01-23 23:55:26 +03:00
2019-01-27 23:18:10 +03:00
-------------------------------------------------------------------------------
-- DROP
-------------------------------------------------------------------------------
2019-01-23 23:55:26 +03:00
2019-01-27 23:18:10 +03:00
parseCmdDrop :: Opts.ParserInfo (IO ())
parseCmdDrop =
Opts.info
((cmdDrop <$> parsePackageName) <**> Opts.helper)
Opts.fullDesc
cmdDrop :: PackageName -> IO ()
cmdDrop packageName = do
putStrLn $ "Dropping package: " <> unPackageName packageName
2019-01-28 23:25:09 +03:00
versionsSpec <- unVersionsSpec <$> getVersionsSpec
2019-01-27 23:18:10 +03:00
when (not $ HMap.member packageName versionsSpec) $
error $ "No such package: " <> unPackageName packageName
2019-01-18 01:00:48 +03:00
2019-01-27 23:18:10 +03:00
setVersionsSpec $ VersionsSpec $
HMap.delete packageName versionsSpec
parseCommand :: Opts.Parser (IO ())
parseCommand = Opts.subparser (
Opts.command "init" parseCmdInit <>
Opts.command "add" parseCmdAdd <>
Opts.command "show" parseCmdShow <>
Opts.command "update" parseCmdUpdate <>
Opts.command "drop" parseCmdDrop )
2019-01-18 01:00:48 +03:00
main :: IO ()
2019-01-27 23:18:10 +03:00
main = join $ Opts.execParser opts
2019-01-23 23:55:26 +03:00
where
2019-01-27 23:18:10 +03:00
opts = Opts.info (parseCommand <**> Opts.helper)
( Opts.fullDesc
<> Opts.header "NIV - Nix Version manager" )
2019-01-23 23:55:26 +03:00
nixPrefetchURL :: String -> IO String
2019-01-27 23:18:10 +03:00
nixPrefetchURL url =
lines <$> readProcess "nix-prefetch-url" ["--unpack", url] "" >>=
\case
(l:_) -> pure l
_ -> error "Expected at least one line from nix-prefetch-url"
2019-01-23 23:55:26 +03:00
-------------------------------------------------------------------------------
-- Aux
-------------------------------------------------------------------------------
--- Aeson
-- | Efficiently deserialize a JSON value from a file.
-- If this fails due to incomplete or invalid input, 'Nothing' is
-- returned.
--
-- The input file's content must consist solely of a JSON document,
-- with no trailing data except for whitespace.
--
-- This function parses immediately, but defers conversion. See
-- 'json' for details.
decodeFileStrict :: (FromJSON a) => FilePath -> IO (Maybe a)
decodeFileStrict = fmap decodeStrict . B.readFile
-- | Efficiently serialize a JSON value as a lazy 'L.ByteString' and write it to a file.
encodeFile :: (ToJSON a) => FilePath -> a -> IO ()
encodeFile fp = L.writeFile fp . encode
--- HashMap
forWithKeyM
:: (Eq k, Hashable k, Monad m)
=> HMap.HashMap k v1
-> (k -> v1 -> m v2)
-> m (HMap.HashMap k v2)
forWithKeyM = flip mapWithKeyM
forWithKeyM_
:: (Eq k, Hashable k, Monad m)
=> HMap.HashMap k v1
-> (k -> v1 -> m ())
-> m ()
forWithKeyM_ = flip mapWithKeyM_
mapWithKeyM
:: (Eq k, Hashable k, Monad m)
=> (k -> v1 -> m v2)
-> HMap.HashMap k v1
-> m (HMap.HashMap k v2)
mapWithKeyM f m = do
fmap mconcat $ forM (HMap.toList m) $ \(k, v) ->
HMap.singleton k <$> f k v
mapWithKeyM_
:: (Eq k, Hashable k, Monad m)
=> (k -> v1 -> m ())
-> HMap.HashMap k v1
-> m ()
mapWithKeyM_ f m = do
forM_ (HMap.toList m) $ \(k, v) ->
HMap.singleton k <$> f k v
2019-01-27 01:39:38 +03:00
-- | Renders the template. Returns 'Nothing' if some of the attributes are
-- missing.
--
-- renderTemplate [("foo", "bar")] "<foo>" == Just "bar"
-- renderTemplate [("foo", "bar")] "<baz>" == Nothing
renderTemplate :: [(String, String)] -> String -> Maybe String
renderTemplate vals = \case
'<':str -> do
case span (/= '>') str of
(key, '>':rest) ->
liftA2 (<>) (lookup key vals) (renderTemplate vals rest)
2019-01-27 23:18:10 +03:00
_ -> Nothing
2019-01-27 01:39:38 +03:00
c:str -> (c:) <$> renderTemplate vals str
[] -> Just []
2019-01-28 23:25:09 +03:00
-------------------------------------------------------------------------------
-- Files and their content
-------------------------------------------------------------------------------
-- | @nix/fetch.nix@
pathNixFetchNix :: FilePath
pathNixFetchNix = "nix" </> "fetch.nix"
-- | Glue code between nix and versions.json
initNixFetchNixContent :: String
initNixFetchNixContent = [s|
# A record, from name to path, of the third-party packages
let
versions = builtins.fromJSON (builtins.readFile ./versions.json);
fetchTarball =
# fetchTarball version that is compatible between all the versions of
# Nix
{ url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
else
fetchTarball attrs;
in
builtins.mapAttrs (_: spec:
fetchTarball {
url =
with spec;
"https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = spec.sha256;
}
) versions
|]
-- | @nix/default.nix@
pathNixDefaultNix :: FilePath
pathNixDefaultNix = "nix" </> "default.nix"
-- | File importing @nixpkgs@, setting up overlays, etc
initNixDefaultNixContent :: String
initNixDefaultNixContent = [s|
with { fetch = import ./fetch.nix; };
import fetch.nixpkgs
{ overlays =
[ (self: super:
{ niv = import fetch.niv {};
}
)
] ;
config = { } ;
}
|]
-- | @default.nix@
pathDefaultNix :: FilePath
pathDefaultNix = "default.nix"
-- | Top level @default.nix@
initDefaultNixContent :: String
initDefaultNixContent = [s|
let pkgs = import ./nix; in pkgs.hello
|]
-- | @shell.nix@
pathShellNix :: FilePath
pathShellNix = "shell.nix"
-- | Simple shell that loads @niv@
initShellNixContent :: String
initShellNixContent = [s|
let pkgs = import ./nix;
in pkgs.mkShell
{ buildInputs = [ pkgs.niv ];
}
|]
-- | @nix/versions.json"
pathNixVersionsJson :: FilePath
pathNixVersionsJson = "nix" </> "versions.json"
-- | Empty JSON map
initNixVersionsJsonContent :: String
initNixVersionsJsonContent = "{}"