Skip to content

Instantly share code, notes, and snippets.

@LnL7
Created October 4, 2019 21:09
Show Gist options
  • Save LnL7/eeac6c554ee9e422eab5a0b4ef924c57 to your computer and use it in GitHub Desktop.
Save LnL7/eeac6c554ee9e422eab5a0b4ef924c57 to your computer and use it in GitHub Desktop.
Example hnix transformation
#!/usr/bin/env nix-shell
#!nix-shell -i runhaskell -p "haskellPackages.ghcWithPackages (p: with p; [ hnix ])"
module Main where
import Data.Text.IO as T
import System.Exit
import Nix
import Nix.Atoms
import Nix.Utils (transport)
{-
$ echo "x: x + 1" | ./Increment.hs
x:
x + 2
-}
main :: IO ()
main = do
stdin <- T.getContents
case parseNixText stdin of
Success expr ->
let expr' = transport update expr in
print $ prettyNix expr'
e -> error (show e)
where
update (NConstant (NInt i)) = NConstant (NInt (i+1))
update x = x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment