HORIZON HASKELLDocslts/ghc-9.14.x3e2d5682026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 3e2d568 · 2026-10-11

Modulelanguage-nix-2.3.0Haskell2010

Language.Nix.Identifier

  • 1 type
  • 6 values
  • Packagelanguage-nix-2.3.0
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceIdentifier.hs

Type-safe Identifiers

4 declarations
newtypenewtype Identifier
#

Identifiers in Nix are essentially strings. They can be constructed (and viewed) with the ident isomorphism. For the sake of convenience, Identifiers are an instance of the IsString class.

It is usually wise to only use identifiers of the form [a-zA-Z_][a-zA-Z0-9_'-]*, because these don't need quoting. Consequently, they can appear almost anywhere in a Nix expression (whereas quoted identifiers e.g. can't be used in function patterns). The methods of the Pretty class can be used to print an identifier with proper quoting:

Example2 expressions
pPrint (ident # "test")testpPrint (ident # "foo.bar")"foo.bar"

The HasParser class allows parsing rendered identifiers even if they are quoted:

Example2 expressions
parseM "Identifier" "hello" :: Maybe IdentifierJust (Identifier "hello")parseM "Identifier" "\"3rd party\"" :: Maybe IdentifierJust (Identifier "3rd party")

Warning: Identifiers may not contain '\0', but this is not checked during construction!

See also https://nix.dev/manual/nix/2.30/language/identifiers.html.

Instances11Eq, Ord, Show, IsString, Generic, NFData, …

Parsec parser for simple identifiers, i.e. those that don't need quoting. The parser is equivalent to the regular expression ^[a-zA-Z_][a-zA-Z0-9_'-]*$ which the Nix parser uses.

Note that this parser will accept keywords which would not be parsed as identifiers by Nix, see nixKeywords.

String Predicates

1 declaration

Internals

2 declarations
valuequote :: String -> String
#

Helper function to quote a given identifier string if necessary. Usually, one should use the Pretty instance of Identifier instead.

Example4 expressions
putStrLn (quote "abc")abcputStrLn (quote "abc.def")"abc.def"putStrLn (quote "$foo")"$foo"putStrLn (quote "${foo}")"\${foo}"