Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Nix through haskell #129

Open
nmattia opened this issue Jun 12, 2019 · 5 comments
Open

Type Nix through haskell #129

nmattia opened this issue Jun 12, 2019 · 5 comments

Comments

@nmattia
Copy link
Owner

nmattia commented Jun 12, 2019

Most of snack's flakiness comes from the fact that the logic is written in Nix - which is untyped and doesn't really have test frameworks.

An idea I played with a while ago was to wrap Nix with haskell types: https://github.com/nmattia/nix-reloaded

It provides a nice way to write Nix by lifting all expressions to typed haskell values, e.g.

https://github.com/nmattia/nix-reloaded/blob/82489bd9d58e21cc4611b2c00c757a859f5fe70a/Test.hs#L16-L21

test1 :: IO ()
test1 = do
    x <- withNixRepl $ \nixRepl -> do
        seven <- bindVar nixRepl (3 + 4)
        eval nixRepl $ Pkgs.map (+ seven) (toNix [1 .. 10])
    x @=? ((+ 7) <$> [1 .. 10] :: [Int])

an expression like builtins.map would be lifted to a haskell value of type (Var a -> Var b) -> Var [a] -> Var [b] which can then be used and applied like any other haskell function.

@smatting
Copy link
Contributor

What do you think about moving more of the logic to Haskell directly in addition to this? For example hpack.nix?

@nmattia
Copy link
Owner Author

nmattia commented Jun 13, 2019

One of the goals of snack is to allow the user to run nix-build and everything should work. If we push some of the logic to haskell that means that, somehow, the nix build needs to first call something like snack dump-build-procedure > foo.nix and then do some import from derivation. If we manage to get everything nice and typed in nix-reloaded then we can do snack dump-nix-files > lib.nix and just upload lib.nix on GitHub, and everyone else can just use that.

@smatting
Copy link
Contributor

smatting commented Jun 13, 2019

Ah, I see! The build process should not even depend on snack itself, only nix. So this is basically goal 1 mentioned in the readme, but more explicit.
And I guess the output of snack dump-nix-files should not depend on the project at all too, correct? (EDIT: well except on the choice of which config files to use)

@masaeedu
Copy link

FWIW there's an existing https://github.com/regnat/ptyx project that attempts to add a type system to Nix.

@nmattia
Copy link
Owner Author

nmattia commented Jun 19, 2019

Last time I talked to @regnat he mentioned it wasn't looking really good. However @jwiegley mentioned there's a rudimentary type system in https://github.com/haskell-nix/hnix, so that could work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants