mirror of
https://github.com/nmattia/niv.git
synced 2024-09-19 11:27:40 +03:00
Add experimental (working) implementation of git specs
This commit is contained in:
parent
3ecde0148f
commit
45a6020028
@ -18,6 +18,9 @@ let
|
||||
else
|
||||
pkgs.fetchzip { inherit (spec) url sha256; };
|
||||
|
||||
fetch_git = spec:
|
||||
builtins.fetchGit { url = spec.repo; inherit (spec) rev; };
|
||||
|
||||
fetch_builtin-tarball = spec:
|
||||
builtins.trace
|
||||
''
|
||||
@ -80,6 +83,7 @@ let
|
||||
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
|
||||
else if spec.type == "file" then fetch_file spec
|
||||
else if spec.type == "tarball" then fetch_tarball spec
|
||||
else if spec.type == "git" then fetch_git spec
|
||||
else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec
|
||||
else if spec.type == "builtin-url" then fetch_builtin-url spec
|
||||
else
|
||||
|
@ -1,4 +1,5 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE Arrows #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
@ -13,6 +14,7 @@ import Niv.Sources
|
||||
import Niv.Update
|
||||
import System.Exit (ExitCode(ExitSuccess))
|
||||
import System.Process (readProcessWithExitCode)
|
||||
import qualified Data.Aeson as Aeson
|
||||
import qualified Data.HashMap.Strict as HMS
|
||||
import qualified Data.Text as T
|
||||
import qualified Options.Applicative as Opts
|
||||
@ -29,7 +31,15 @@ gitCmd = Cmd
|
||||
|
||||
-- TODO: don't hardcode here
|
||||
parseGitPackageSpec :: Opts.Parser PackageSpec
|
||||
parseGitPackageSpec = pure $ PackageSpec $ HMS.singleton "repo" "git@github.com:nmattia/niv"
|
||||
parseGitPackageSpec =
|
||||
(PackageSpec . HMS.singleton "repo") <$>
|
||||
parseRepo
|
||||
where
|
||||
parseRepo =
|
||||
Aeson.String <$> Opts.strOption
|
||||
( Opts.long "repo" <>
|
||||
Opts.metavar "URL"
|
||||
)
|
||||
|
||||
describeGit :: Opts.InfoMod a
|
||||
describeGit = mconcat
|
||||
|
@ -3,11 +3,12 @@
|
||||
# TODO: this doesn' test anything meaningful yet because "niv git PACKAGE"
|
||||
# doesn't parse yet
|
||||
pkgs.runCommand "foo"
|
||||
{ nativeBuildInputs = [ pkgs.git niv ]; }
|
||||
{ nativeBuildInputs = [ pkgs.git niv pkgs.nix pkgs.jq ]; }
|
||||
(
|
||||
# First we create a dummy git repo with a single commit
|
||||
''
|
||||
gitdir=$(mktemp -d)
|
||||
|
||||
pushd $gitdir
|
||||
pushd $gitdir > /dev/null
|
||||
git init .
|
||||
echo hello > file
|
||||
git config user.email "niv@foo.bar"
|
||||
@ -15,17 +16,40 @@ pkgs.runCommand "foo"
|
||||
git add file
|
||||
git commit -m "Initial commit"
|
||||
gitrev=$(git rev-parse HEAD)
|
||||
popd
|
||||
popd > /dev/null
|
||||
'' +
|
||||
|
||||
# Then we `niv add` that repo and check some properties, like the revision
|
||||
# and revCount, to make sure it was imported properly, and that sources.nix
|
||||
# does what it's supposed to do.
|
||||
''
|
||||
nivdir=$(mktemp -d)
|
||||
pushd $nivdir
|
||||
pushd $nivdir > /dev/null
|
||||
mkdir -p nix
|
||||
echo "{}" > nix/sources.json
|
||||
niv init
|
||||
# niv add git -n my-git-repo file://$gitdir
|
||||
# nix eval --json '(import ./nix/sources.nix).my-git-repo.rev'
|
||||
popd
|
||||
niv add git -n my-git-repo --repo file://$gitdir
|
||||
nivrev=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.rev' | jq -r)
|
||||
if [ ! "$gitrev" = "$nivrev" ]; then
|
||||
echo "Mismatched revs: $gitrev != $nivrev"
|
||||
exit 42
|
||||
fi
|
||||
|
||||
# here we cheat a bit and use "outPath", which actually is the result of
|
||||
# builtins.fetchGit.
|
||||
nivnixrev=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.outPath.rev' | jq -r)
|
||||
if [ ! "$gitrev" = "$nivnixrev" ]; then
|
||||
echo "Mismatched revs: $gitrev != $nivnixrev"
|
||||
exit 42
|
||||
fi
|
||||
nivnixrevcount=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.outPath.revCount')
|
||||
if [ ! "1" -eq "$nivnixrevcount" ]; then
|
||||
echo "Mismatched revCount: 1 != $nivnixrevcount"
|
||||
exit 42
|
||||
fi
|
||||
popd > /dev/null
|
||||
|
||||
touch $out
|
||||
''
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user