Skip to content

Commit

Permalink
Merge pull request #65 from expipiplus1/joe-hnix-1.3
Browse files Browse the repository at this point in the history
Adjust for hnix >= 0.13 2
  • Loading branch information
expipiplus1 authored May 23, 2021
2 parents e10464e + 854e5ee commit 6d38dca
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## WIP

## [0.2.7] - 2021-05-23

- `hnix-0.13` support

## [0.2.6] - 2021-05-17

- `git ls-remote` calls are printed in verbose mode
Expand Down
3 changes: 0 additions & 3 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,3 @@ instance Read Regex where
instance ParseField Regex where
metavar _ = "REGEX"
readField = eitherReader makeRegexM

instance (e ~ String) => MonadFail (Either e) where
fail = Left
10 changes: 9 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ let
in hp.developPackage {
name = "update-nix-fetchgit";
root = nix-gitignore.gitignoreSource [ ] ./.;
overrides = self: _super: { };
overrides = self: super: {
hnix = pkgs.haskell.lib.dontCheck (self.callHackageDirect {
pkg = "hnix";
ver = "0.13.1";
sha256 = "0v3r33azlv050fv8y5vw0pahdnch7vqq94viwrp9vlw8hpiys8qn";
} { });
relude = self.relude_1_0_0_1;
semialign = self.semialign_1_2;
};
modifier = drv: haskell.lib.addBuildTools drv [ git nix nix-prefetch-git ];
returnShellEnv = forShell;
}
Expand Down
82 changes: 82 additions & 0 deletions hnix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
diff --git a/src/Nix/Parser.hs b/src/Nix/Parser.hs
index 0a820b8..7e0a4d2 100644
--- a/src/Nix/Parser.hs
+++ b/src/Nix/Parser.hs
@@ -609,9 +609,10 @@ annotateLocation :: Parser a -> Parser (Ann SrcSpan a)
annotateLocation p =
do
begin <- getSourcePos
+ res <- p
end <- get -- The state set before the last whitespace

- Ann (SrcSpan begin end) <$> p
+ pure $ Ann (SrcSpan begin end) res

annotateLocation1 :: Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 = fmap annToAnnF . annotateLocation
diff --git a/tests/ParserTests.hs b/tests/ParserTests.hs
index 0b50cf6..5720999 100644
--- a/tests/ParserTests.hs
+++ b/tests/ParserTests.hs
@@ -357,6 +357,42 @@ in null|] [text|let
in (matcher.case or null).foo (v.case);
in null|]

+case_simpleLoc =
+ let
+ mkSPos l c = SourcePos "<string>" (mkPos l) (mkPos c)
+ mkSpan l1 c1 l2 c2 = SrcSpan (mkSPos l1 c1) (mkSPos l2 c2)
+ in
+ assertParseTextLoc [text|let
+ foo = bar
+ baz "qux";
+ in foo
+ |]
+ (Fix
+ (NLet_
+ (mkSpan 1 1 4 7)
+ [ NamedVar
+ (StaticKey "foo" :| [])
+ (Fix
+ (NBinary_
+ (mkSpan 2 7 3 15)
+ NApp
+ (Fix
+ (NBinary_ (mkSpan 2 7 3 9)
+ NApp
+ (Fix (NSym_ (mkSpan 2 7 2 10) "bar"))
+ (Fix (NSym_ (mkSpan 3 6 3 9) "baz"))
+ )
+ )
+ (Fix (NStr_ (mkSpan 3 10 3 15) (DoubleQuoted [Plain "qux"])))
+ )
+ )
+ (mkSPos 2 1)
+ ]
+ (Fix (NSym_ (mkSpan 4 4 4 7) "foo"))
+ )
+ )
+
+
tests :: TestTree
tests = $testGroupGenerator

@@ -375,6 +411,18 @@ assertParseText str expected =
)
(parseNixText str)

+assertParseTextLoc :: Text -> NExprLoc -> Assertion
+assertParseTextLoc str expected =
+ either
+ (\ err ->
+ assertFailure $ toString $ "Unexpected fail parsing `" <> str <> "':\n" <> show err
+ )
+ (assertEqual
+ ("When parsing " <> toString str)
+ expected
+ )
+ (parseNixTextLoc str)
+
assertParseFile :: FilePath -> NExpr -> Assertion
assertParseFile file expected =
do
4 changes: 2 additions & 2 deletions nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
let
nixpkgsSrc = builtins.fetchTarball {
url =
"https://github.com/NixOS/nixpkgs/archive/83d907fd760d9ee4f49b4b7e4b1c6682f137b573.tar.gz"; # nixos-unstable
sha256 = "0qc8gfkbga7v5p8r6h2hbdi8bjl3piikdwcbb9fff5cjnxi7v7qa";
"https://github.com/NixOS/nixpkgs/archive/d42cd445dde587e9a993cd9434cb43da07c4c5de.tar.gz"; # nixos-unstable
sha256 = "0dzrn97srxyw5a3g7hf8chwccxns5z3aij23hc0fch7ygc8w0gq0";
};

in import nixpkgsSrc { }
Expand Down
4 changes: 2 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: update-nix-fetchgit
version: "0.2.6"
version: "0.2.7"
synopsis: A program to update fetchgit values in Nix expressions
description: |
This command-line utility is meant to be used by people maintaining Nix
Expand Down Expand Up @@ -46,7 +46,7 @@ library:
- bytestring >= 0.10
- data-fix
- github-rest
- hnix >= 0.11 && < 0.13
- hnix >= 0.13.1
- monad-validate
- mtl
- process >= 1.2
Expand Down
4 changes: 2 additions & 2 deletions src/Nix/Match/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ typedMatcherGen
-> Q (([T.Text], [T.Text]), Exp)
typedMatcherGen parseNix collect add strip s = do
expr <- case parseNix (T.pack s) of
Failure err -> fail $ show err
Success e -> pure e
Left err -> fail $ show err
Right e -> pure e
let (opt, req) = collect expr
optT = symbolList opt
reqT = symbolList req
Expand Down
10 changes: 5 additions & 5 deletions src/Update/Nix/FetchGit/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import Data.Time ( Day
)
import Nix.Atoms ( NAtom(NBool) )
import Nix.Expr hiding ( SourcePos )
import Nix.Parser ( Result(..)
import Nix.Parser ( Result
, parseNixFileLoc
, parseNixTextLoc
)
Expand All @@ -48,13 +48,13 @@ import Update.Span

ourParseNixText :: Text -> Either Warning NExprLoc
ourParseNixText t = case parseNixTextLoc t of
Failure parseError -> Left (CouldNotParseInput (tShow parseError))
Success expr -> pure expr
Left parseError -> Left (CouldNotParseInput (tShow parseError))
Right expr -> pure expr

ourParseNixFile :: FilePath -> M NExprLoc
ourParseNixFile f = liftIO (parseNixFileLoc f) >>= \case
Failure parseError -> refute1 (CouldNotParseInput (tShow parseError))
Success expr -> pure expr
Left parseError -> refute1 (CouldNotParseInput (tShow parseError))
Right expr -> pure expr

-- | Get the url from either a nix expression for the url or a repo and owner
-- expression.
Expand Down
4 changes: 2 additions & 2 deletions update-nix-fetchgit.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: update-nix-fetchgit
version: 0.2.6
version: 0.2.7
synopsis: A program to update fetchgit values in Nix expressions
description: This command-line utility is meant to be used by people maintaining Nix
expressions that fetch files from Git repositories. It automates the process
Expand Down Expand Up @@ -108,7 +108,7 @@ library
, bytestring >=0.10
, data-fix
, github-rest
, hnix >=0.11 && <0.13
, hnix >=0.13.1
, monad-validate
, mtl
, process >=1.2
Expand Down

0 comments on commit 6d38dca

Please sign in to comment.