Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to hnix-0.17 #82

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## WIP
## [0.2.12] - 2024-01-DD
- Changes for hnix-0.17

## [0.2.11] - 2022-12-06
- Changes for hnix-0.16
Expand Down
2 changes: 0 additions & 2 deletions Setup.hs

This file was deleted.

1 change: 0 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
packages: ./*.cabal
optimization: 2
allow-newer: all:base, all:ghc-prim, hnix:template-haskell
82 changes: 0 additions & 82 deletions hnix.patch

This file was deleted.

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/d7af8ae032b081ab01461be06838ba5ea89110f1.tar.gz"; # haskell-updates
sha256 = "1n6ky9lczwh2dk2q0ckdv4wm096q1syk2pddrhidj1vy34aigpxd";
"https://github.com/NixOS/nixpkgs/archive/50d354db00061ebfc6992b6040e81e7bfbedd473.tar.gz"; # haskell-updates
sha256 = "08i444lcs8m8kby1hcylbddlllyyh3dnxvy6lv0sicbymra4jw7z";
};

in import nixpkgsSrc { }
Expand Down
4 changes: 2 additions & 2 deletions src/Nix/Comments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ annotateWithComments sourceLines = go

go' :: NExprLocF f -> NExprCommentsF f
go' e =
let comment = case spanEnd . annotation . getCompose $ e of
SourcePos _ line col -> do
let comment = case getSpanEnd . annotation . getCompose $ e of
NSourcePos _ (NPos line) (NPos col) -> do
theLine <- sourceLines !? (unPos line - 1)
theLineAfterExpression <- dropMaybe (unPos col - 1) theLine
let theLineAfterCruft =
Expand Down
2 changes: 1 addition & 1 deletion src/Update/Nix/FetchGit/Prefetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ getGitHubRevisionDate owner repo revision = do
ghState :: GitHubSettings
ghState = GitHubSettings { token = Nothing
, userAgent = "expipiplus1/update-nix-fetchgit"
, apiVersion = "v3"
, apiVersion = "2022-11-28"
}

----------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/Update/Nix/FetchGit/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ formatWarning (DuplicateAttrs attrName) =
"Error: The \"" <> attrName <> "\" attribute appears twice in a set."
formatWarning (NotAString expr) =
"Error: The expression at "
<> (T.pack . prettyPrintSourcePos . spanBegin . exprSpan) expr
<> (T.pack . prettyPrintSourcePos . getSpanBegin . exprSpan) expr
<> " is not a string literal."
formatWarning (NotABool expr) =
"Error: The expression at "
<> (T.pack . prettyPrintSourcePos . spanBegin . exprSpan) expr
<> (T.pack . prettyPrintSourcePos . getSpanBegin . exprSpan) expr
<> " is not a boolean literal."
formatWarning (NixPrefetchGitFailed exitCode errorOutput) =
"Error: nix-prefetch-git failed with exit code "
Expand Down Expand Up @@ -185,7 +185,7 @@ tShow = T.pack . show

containsPosition :: NExprLoc -> (Int, Int) -> Bool
containsPosition (Fix (Compose (AnnUnit (SrcSpan begin end) _))) p =
let unSourcePos (SourcePos _ l c) = (unPos l, unPos c)
let unSourcePos (NSourcePos _ (NPos l) (NPos c)) = (unPos l, unPos c)
in p >= unSourcePos begin && p < unSourcePos end

----------------------------------------------------------------
Expand Down
20 changes: 12 additions & 8 deletions src/Update/Span.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Update.Span
( SpanUpdate(..)
, SrcSpan(..)
, SourcePos(..)
, NSourcePos(..)
, updateSpan
, updateSpans
, linearizeSourcePos
Expand All @@ -25,7 +25,11 @@ import Data.Text ( Text
, lines
, splitAt
)
import Nix.Expr.Types.Annotated
import Nix.Expr.Types ( NPos(..)
, NSourcePos(..)
, unPos
)
import Nix.Expr.Types.Annotated ( SrcSpan(..) )
import Prelude hiding ( length
, lines
, splitAt
Expand All @@ -42,7 +46,7 @@ data SpanUpdate = SpanUpdate
-- | Update many spans in a file. They must be non-overlapping.
updateSpans :: [SpanUpdate] -> Text -> Text
updateSpans us t =
let sortedSpans = sortOn (spanBegin . spanUpdateSpan) us
let sortedSpans = sortOn (getSpanBegin . spanUpdateSpan) us
anyOverlap =
any (uncurry overlaps) (zip <*> tail $ spanUpdateSpan <$> sortedSpans)
in assert (not anyOverlap) (foldr updateSpan t sortedSpans)
Expand All @@ -60,9 +64,9 @@ overlaps :: SrcSpan -> SrcSpan -> Bool
overlaps (SrcSpan b1 e1) (SrcSpan b2 e2) =
b2 >= b1 && b2 < e1 || e2 >= b1 && e2 < e1

-- | Split some text at a particular 'SourcePos'
split :: SourcePos -> Text -> (Text, Text)
split (SourcePos _ row col) t = splitAt
-- | Split some text at a particular 'NSourcePos'
split :: NSourcePos -> Text -> (Text, Text)
split (NSourcePos _ (NPos row) (NPos col)) t = splitAt
(fromIntegral
(linearizeSourcePos t
(fromIntegral (unPos row - 1))
Expand All @@ -84,6 +88,6 @@ linearizeSourcePos t l c = fromIntegral lineCharOffset + c
where
lineCharOffset = sum . fmap ((+ 1) . length) . genericTake l . lines $ t

prettyPrintSourcePos :: SourcePos -> String
prettyPrintSourcePos (SourcePos _ row column) =
prettyPrintSourcePos :: NSourcePos -> String
prettyPrintSourcePos (NSourcePos _ (NPos row) (NPos column)) =
show (unPos row) <> ":" <> show (unPos column)
2 changes: 1 addition & 1 deletion update-nix-fetchgit.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ library
, bytestring >=0.10
, data-fix
, github-rest >=1.1
, hnix ==0.16.*
, hnix >=0.17 && <0.18
, monad-validate
, mtl
, process >=1.2
Expand Down