[Nix-dev] "IO" in Nix

Ericson, John john_ericson at brown.edu
Fri May 27 04:09:12 CEST 2016


Not sure how relevant this is, but sometimes I think about a sort of
"quoting monad" where Q a = a derivation producing a nix expression with
"type" a. import-with-derivation would form the crux of the bind operation
of the monad.

On Tue, May 24, 2016 at 3:52 PM, Rickard Nilsson <rickard.nilsson at telia.com>
wrote:

> Hi Dan,
>
> On 05/23/2016 05:30 PM, Daniel Peebles wrote:
> > Hi all,
> >
> > I've been experimenting with a pattern recently that I'd say is fairly
> > close to a Haskell notion of IO. I have a collection of Nix-centered
> > scripts that need to perform fairly restricted side effects:
> >
> >   * Build an AMI (image) for AWS
> >   * Write some disk image stuff to a raw device
> >   * Run some tests that talk to the outside world
> >   * Build some stuff that depends in a fairly constrained way on mutable
> >     external state (e.g., RPM update repos, as opposed to the
> >     deterministic base repos)
> >   * Deploy stuff
> >
> > These things all have the following in common:
> >
> >   * I build as much stuff possible in "pure" Nix
> >   * I write out scripts (in the store) that all start with a
> >     ${stdenv.shell} shebang and an explicit `export PATH` clause to
> >     avoid inheriting an environment from the outside.
> >   * The scripts rarely take arguments at runtime; instead I run them
> >     with similarly to `sudo $(nix-build -A foobar)` or sometimes without
> >     `sudo`.
> >
> > I'm wondering if anyone else is doing something similar. It's basically
> > (right now) analogous to a non-composable IO value in Haskell: pure code
> > producing a "script" for some external impure interpreter to execute.
> >
> > I can think of a few next steps from here: start building composition
> > operators (like bind) to chain together these impure actions without
> > wanting to pull your hair out. I think Shea Levy's nix-exec already has
> > a monad-flavored API for IO but I haven't seen anything like it outside
> > of nix-exec.
>
> I'm interested in hearing a bit more about the composition operators you
> envision. I do a lot of shell script building like you describe above,
> and I tend to compose them by building other shell scripts. I assume
> that is what you mean by pulling your hair out?
>
> Sometimes I also do composition by building Makefiles, which is kind of
> nice when you want to assemble many tasks that could possibly run in
> parallel.
>
> To have useful composition operators, wouldn't you need more precise
> types for your IO actions?
>
>
> Regards,
>    Rickard
>
>
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160526/afc95f29/attachment.html 


More information about the nix-dev mailing list