Nix Language Reference
  
    Grammar
    
      Expressions
      
      
        Expr
        
          
        
      
      
      
        ExprFunction
        
          '{'  '}' ':' 
          |
          
        
      
      
      
        ExprAssert
        
          'assert'  ';' 
          |
          
        
      
      
      
        ExprIf
        
          'if'  'then' 
          'else' 
          |
          
        
      
      
      
        ExprOp
        
          '!' 
          |
           '==' 
          |
           '!=' 
          |
           '&&' 
          |
           '||' 
          |
           '->' 
          |
           '//' 
          |
           '~' 
          |
           '?' 
          |
          
        
      
      
      
        ExprApp
        
           '.' 
          |
          
        
      
      
      
        ExprSelect
        
           
          |
          
        
      
      
      
        ExprSimple
        
           |
           |
           |
           |
          
          |
          'true' | 'false' | 'null'
          |
          '('  ')'
          |
          '{' * '}'
          |
          'let' '{' * '}'
          |
          'rec' '{' * '}'
          |
          '[' * ']'
        
      
      
        Bind
        
           '='  ';'
          |
          'inherit' ('('  ')')? * ';'
        
      
      
        Formals
        
           ',' 
          | 
        
      
          
      
        Formal
        
          
          |
           '?' 
        
      
          
    
    
      Terminals
      
        Id
        [a-zA-Z\_][a-zA-Z0-9\_\']*
      
    
      
        Int
        [0-9]+
      
    
      
        Str
        \"[^\n\"]*\"
      
      
        Path
        [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+
      
    
      
        Uri
        [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']+
      
      
        Whitespace
        
          [ \t\n]+
          |
          \#[^\n]*
          |
          \/\*(.|\n)*\*\/
        
      
    
    
  
  
  
    Semantics
    
    
      Built-in functions
      
        The Nix language provides the following built-in function
        (primops
):
      
      
        
          import
          e
          
            
              Evaluates the expression e,
              which must yield a path value.  The Nix expression
              stored at this path in the file system is then read,
              parsed, and evaluated.  Returns the result of the
              evaluation of the Nix expression just read.
            
            
              Example: import ./foo.nix evaluates
              the expression stored in foo.nix
              (in the directory containing the expression in which the
              import occurs).
            
          
        
        
          derivation
          e
          
            
              Evaluates the expression e,
              which must yield an attribute set.  [...]
            
          
        
        
          baseNameOf
          e
          
            
              Evaluates the expression e,
              which must yield a string value, and returns a string
              representing its base name.  This
              is the substring following the last path separator
              (/).
            
            
              Example: baseNameOf "/foo/bar"
              returns "bar", and
              baseNameOf "/foo/bar/" returns
              "".
            
          
        
        
          toString
          e
          
            
              Evaluates the expression e
              and coerces it into a string, if possible.  Only
              strings, paths, and URIs can be so coerced.
            
            
              Example: toString
              http://www.cs.uu.nl/ returns
              "http://www.cs.uu.nl/".