Created
October 4, 2019 21:09
-
-
Save LnL7/eeac6c554ee9e422eab5a0b4ef924c57 to your computer and use it in GitHub Desktop.
Example hnix transformation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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