autodocodec-nix 0.1.0.0 → 0.1.0.2
raw patch · 4 files changed
+33/−5 lines, 4 filesdep ~autodocodecPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: autodocodec
API changes (from Hackage documentation)
- Autodocodec.Nix: renderNixOptionTypeViaCodec :: forall a. HasCodec a => Text
+ Autodocodec.Nix: renderNixOptionTypeViaCodec :: HasCodec a => Text
- Autodocodec.Nix: renderNixOptionsViaCodec :: forall a. HasObjectCodec a => Text
+ Autodocodec.Nix: renderNixOptionsViaCodec :: HasObjectCodec a => Text
- Autodocodec.Nix.Options: renderNixOptionTypeViaCodec :: forall a. HasCodec a => Text
+ Autodocodec.Nix.Options: renderNixOptionTypeViaCodec :: HasCodec a => Text
- Autodocodec.Nix.Options: renderNixOptionsViaCodec :: forall a. HasObjectCodec a => Text
+ Autodocodec.Nix.Options: renderNixOptionsViaCodec :: HasObjectCodec a => Text
Files
- CHANGELOG.md +12/−0
- autodocodec-nix.cabal +3/−3
- src/Autodocodec/Nix/Expression.hs +17/−1
- src/Autodocodec/Nix/Options.hs +1/−1
CHANGELOG.md view
@@ -1,5 +1,17 @@ # Changelog +## [0.1.0.2] - 2026-07-14++### Changed++* Lower bound on `autodocodec >=0.6`++## [0.1.0.1] - 2026-04-25++### Changed++* Attribute keys that are not valid Nix identifiers are now quoted in rendered expressions.+ ## [0.1.0.0] - 2025-02-13 ### Added
autodocodec-nix.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.36.0.+-- This file has been generated from package.yaml by hpack version 0.38.3. -- -- see: https://github.com/sol/hpack name: autodocodec-nix-version: 0.1.0.0+version: 0.1.0.2 synopsis: Autodocodec interpreters for nix homepage: https://github.com/NorfairKing/autodocodec#readme bug-reports: https://github.com/NorfairKing/autodocodec/issues@@ -35,7 +35,7 @@ src build-depends: aeson- , autodocodec >=0.4.0.0+ , autodocodec >=0.6.0.0 , base >=4.7 && <5 , containers , scientific
src/Autodocodec/Nix/Expression.hs view
@@ -18,6 +18,7 @@ import Data.Aeson as JSON import qualified Data.Aeson.Key as Key import qualified Data.Aeson.KeyMap as KeyMap+import Data.Char (isAsciiLower, isAsciiUpper, isDigit) import Data.Map.Strict (Map) import qualified Data.Map.Strict as M import Data.Scientific@@ -82,9 +83,24 @@ parensWhen (d > 10) $ ("with " <> t <> ";") : go 0 e goBind key e =- prependWith " " (key <> " =") $+ prependWith " " (nixAttrKey key <> " =") $ (`append` ";") $ go 0 e++-- | Quote an attribute key if it is not a valid Nix identifier.+-- Valid identifiers match @[a-zA-Z_][a-zA-Z0-9_'-]*@.+nixAttrKey :: Text -> Text+nixAttrKey key+ | isNixIdentifier key = key+ | otherwise = T.pack $ show $ T.unpack key++isNixIdentifier :: Text -> Bool+isNixIdentifier t = case T.uncons t of+ Nothing -> False+ Just (c, rest) -> isNixIdentStart c && T.all isNixIdentChar rest+ where+ isNixIdentStart c = c == '_' || isAsciiLower c || isAsciiUpper c+ isNixIdentChar c = isNixIdentStart c || isDigit c || c == '-' || c == '\'' indent :: [Text] -> [Text] indent = map (" " <>)
src/Autodocodec/Nix/Options.hs view
@@ -71,7 +71,7 @@ go = \case NullCodec -> Just OptionTypeNull BoolCodec _ -> Just $ OptionTypeSimple "lib.types.bool"- StringCodec _ -> Just $ OptionTypeSimple "lib.types.str"+ StringCodec _ _ -> Just $ OptionTypeSimple "lib.types.str" IntegerCodec _ bounds -> Just $ OptionTypeSimple $ case guessIntegerBoundsSymbolic bounds of