[Nix-dev] "IO" in Nix
Rickard Nilsson
rickard.nilsson at telia.com
Wed May 25 00:52:10 CEST 2016
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
More information about the nix-dev
mailing list