Skip to content

Commit 62459ec

Browse files
committed
Effects: StorePath: reduce newtype accessor
1 parent 291d2e0 commit 62459ec

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

src/Nix/Builtins.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ toFileNix name s =
11221122
(stringIgnoreContext s')
11231123

11241124
let
1125-
t = toText $ unStorePath mres
1125+
t = toText @FilePath $ coerce mres
11261126
sc = StringContext t DirectPath
11271127

11281128
toValue $ makeNixStringWithSingletonContext t sc

src/Nix/Convert.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,8 @@ instance ( Convertible e t f m
195195
\case
196196
NVStr' ns -> pure $ pure ns
197197
NVPath' p ->
198-
fmap
199-
(pure . (\s -> makeNixStringWithSingletonContext s (StringContext s DirectPath)) . toText . unStorePath)
200-
(addPath p)
198+
(\path -> pure $ makeNixStringWithSingletonContext path (StringContext path DirectPath)) . toText @FilePath . coerce <$>
199+
addPath p
201200
NVSet' s _ ->
202201
maybe
203202
stub
@@ -368,7 +367,7 @@ instance Convertible e t f m
368367

369368
instance Convertible e t f m
370369
=> ToValue StorePath m (NValue' t f m (NValue t f m)) where
371-
toValue = toValue . Path . unStorePath
370+
toValue = toValue @Path . coerce
372371

373372
instance ( Convertible e t f m
374373
)

src/Nix/Effects.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import qualified System.Nix.Store.Remote as Store.Remote
4141
import qualified System.Nix.StorePath as Store
4242

4343
-- | A path into the nix store
44-
newtype StorePath = StorePath { unStorePath :: FilePath }
44+
newtype StorePath = StorePath FilePath
4545

4646

4747
-- All of the following type classes defer to the underlying 'm'.

src/Nix/Effects/Derivation.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ writeDerivation drv@Derivation{inputs, name} = do
7575
let (inputSrcs, inputDrvs) = inputs
7676
references <- Set.fromList <$> traverse parsePath (Set.toList $ inputSrcs <> Set.fromList (Map.keys inputDrvs))
7777
path <- addTextToStore (Text.append name ".drv") (unparseDrv drv) (S.fromList $ Set.toList references) False
78-
parsePath $ toText $ unStorePath path
78+
parsePath $ toText @FilePath $ coerce path
7979

8080
-- | Traverse the graph of inputDrvs to replace fixed output derivations with their fixed output hash.
8181
-- this avoids propagating changes to their .drv when the output hash stays the same.
@@ -275,7 +275,7 @@ defaultDerivationStrict val = do
275275
pure $ drv
276276
{ inputs
277277
, outputs = outputs'
278-
, env = ifNotJsonModEnv $ (outputs' <>)
278+
, env = ifNotJsonModEnv (outputs' <>)
279279
}
280280

281281
drvPath <- pathToText <$> writeDerivation drv'

src/Nix/Json.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ nvalueToJSON = \case
4242
(HM.lookup "outPath" m)
4343
NVPath p ->
4444
do
45-
fp <- lift $ unStorePath <$> addPath p
46-
addSingletonStringContext $ StringContext (toText fp) DirectPath
45+
fp <- lift $ coerce <$> addPath p
46+
addSingletonStringContext $ StringContext (toText @FilePath fp) DirectPath
4747
pure $ A.toJSON fp
4848
v -> lift $ throwError $ CoercionToJson v
4949

0 commit comments

Comments
 (0)