[Nix-dev] Use Haskell for Shell Scripting

Karn Kallio tierpluspluslists at skami.org
Sat Jan 31 23:45:18 CET 2015


On Saturday, January 31, 2015 22:59:21 nix-dev-request at lists.science.uu.nl 
wrote:
> Send nix-dev mailing list submissions to
> 	nix-dev at lists.science.uu.nl
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://lists.science.uu.nl/mailman/listinfo/nix-dev
> or, via email, send a message with subject or body 'help' to
> 	nix-dev-request at lists.science.uu.nl
> 
> You can reach the person managing the list at
> 	nix-dev-owner at lists.science.uu.nl
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of nix-dev digest..."
> 
> 
> Today's Topics:
> 
>    1. Re: overriding a package (Catonano)
>    2. Re: overriding a package (Bj?rn Forsman)
>    3. Re: overriding a package (Catonano)
>    4. Check the priority of package in the nix store (Richard Wallace)
>    5. Re: Use Haskell for Shell Scripting (Shea Levy)
>    6. Re: Use Haskell for Shell Scripting (Ertugrul S?ylemez)
>    7. Re: Use Haskell for Shell Scripting (Tim Barbour)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Sat, 31 Jan 2015 18:29:06 +0100
> From: Catonano <catonano at gmail.com>
> Subject: Re: [Nix-dev] overriding a package
> To: Bj?rn Forsman <bjorn.forsman at gmail.com>
> Cc: Nix Dev <nix-dev at lists.science.uu.nl>
> Message-ID:
> 	<CAJ98PDymFGCyhCDsF5ojRVwgdCV3EoRjuoVx5pxWaMDXSsx1uQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> 2015-01-31 16:50 GMT+01:00 Bj?rn Forsman <bjorn.forsman at gmail.com>:
> > That's weird. I copy/pasted your code into my ~/.nixpkgs/config.nix
> > and it worked just fine.
> 
> I removed it and reinstalled it again.
> 
> Now the sympthom is different
> 
> $ nix-env -i InfTaRacket
> error: selector ?InfTaRacket? matches no derivations
> 
> $ nix-env -i myRacket
> error: selector ?myRacket? matches no derivations
> 
> $ nix-env -qa racket
> racket-6.1.1
> racket-6.1.1
> 
> 
> BUT if I decomment the line
> 
> #name = "${pname}-${version}";
> 
> then this is the result
> 
> $ nix-env -qa racket
> error: undefined variable ?pname? at "/home/me/.nixpkgs/config.nix":9:16
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://lists.science.uu.nl/pipermail/nix-dev/attachments/20150131/a3b5e505/
> attachment-0001.html
> 
> ------------------------------
> 
> Message: 2
> Date: Sat, 31 Jan 2015 19:13:45 +0100
> From: Bj?rn Forsman <bjorn.forsman at gmail.com>
> Subject: Re: [Nix-dev] overriding a package
> To: Catonano <catonano at gmail.com>
> Cc: Nix Dev <nix-dev at lists.science.uu.nl>
> Message-ID:
> 	<CAEYzJUGy+tuf7etdgoag7E1jyKo+owrD3pNA5zRfY9N=NXbogQ at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
> 
> On 31 January 2015 at 18:29, Catonano <catonano at gmail.com> wrote:
> > 2015-01-31 16:50 GMT+01:00 Bj?rn Forsman <bjorn.forsman at gmail.com>:
> >> That's weird. I copy/pasted your code into my ~/.nixpkgs/config.nix
> >> and it worked just fine.
> > 
> > I removed it and reinstalled it again.
> > 
> > Now the sympthom is different
> > 
> > $ nix-env -i InfTaRacket
> > error: selector ?InfTaRacket? matches no derivations
> > 
> > $ nix-env -i myRacket
> > error: selector ?myRacket? matches no derivations
> > 
> > $ nix-env -qa racket
> > racket-6.1.1
> > racket-6.1.1
> > 
> > 
> > BUT if I decomment the line
> > 
> > #name = "${pname}-${version}";
> > 
> > then this is the result
> > 
> > $ nix-env -qa racket
> > error: undefined variable ?pname? at "/home/me/.nixpkgs/config.nix":9:16
> 
> To enable attributes to refer to each other, within the same attrset,
> you need to put 'rec' in front of the attrset. In other words, instead
> of "oldAttrs: {", use "oldAttrs: rec {".
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Sat, 31 Jan 2015 19:27:30 +0100
> From: Catonano <catonano at gmail.com>
> Subject: Re: [Nix-dev] overriding a package
> To: Bj?rn Forsman <bjorn.forsman at gmail.com>
> Cc: Nix Dev <nix-dev at lists.science.uu.nl>
> Message-ID:
> 	<CAJ98PDyWR9VR0XsVjgkak96ZQ+nROBKpx3vDBUrSLZj9R-Em8A at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> 2015-01-31 19:13 GMT+01:00 Bj?rn Forsman <bjorn.forsman at gmail.com>:
> 
> To enable attributes to refer to each other, within the same attrset,
> 
> > you need to put 'rec' in front of the attrset. In other words, instead
> > of "oldAttrs: {", use "oldAttrs: rec {".
> 
> Thank you
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://lists.science.uu.nl/pipermail/nix-dev/attachments/20150131/6844d62f/
> attachment-0001.html
> 
> ------------------------------
> 
> Message: 4
> Date: Sat, 31 Jan 2015 13:19:58 -0700
> From: Richard Wallace <rwallace at thewallacepack.net>
> Subject: [Nix-dev] Check the priority of package in the nix store
> To: nix-dev <nix-dev at lists.science.uu.nl>
> Message-ID:
> 	<CAGgpxwm3CZ8DGrjhK0=AGYHLvOFook9frw3QLyp03G6Twae66w at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> Hey folks,
> 
> I'm running into some issues with packages conflicting and the priority
> seeming to be ignored. I reported it last night thinking it was a problem
> with Haskell NG but now think it is something different.
> 
> I'm using nix-build to build it locally, copy-nix-closure to copy it to the
> machine I want to run it on, and on that remote machine run `nix-env -i`.
> 
> In the derivation for the package I've used the `hiPrio` function to make
> this new package a higher priority.  When I use the nix-repl and import and
> check the value, I can see that the meta.priority is indeed set to -10 as
> it should be.  But when `nix-env -i` is run it still complains about the
> conflict.
> 
> Is there a way to check the priority of something in the nix-store? Any
> ideas why the priority is being ignored and/or lost in this process? Am
> there something wrong in my process?
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://lists.science.uu.nl/pipermail/nix-dev/attachments/20150131/cb913c27/
> attachment-0001.html
> 
> ------------------------------
> 
> Message: 5
> Date: Sat, 31 Jan 2015 20:51:37 +0000
> From: Shea Levy <shea at shealevy.com>
> Subject: Re: [Nix-dev] Use Haskell for Shell Scripting
> To: Daniel Peebles <pumpkingod at gmail.com>
> Cc: nix-dev <nix-dev at lists.science.uu.nl>
> Message-ID: <1209C510-6ABC-4581-9C97-DA325D0F49D6 at shealevy.com>
> Content-Type: text/plain; charset=utf-8
> 
> Yes, I?m planning to work on multiple outputs for ghc soon :)
> 
> > On Jan 31, 2015, at 3:55 PM, Daniel Peebles <pumpkingod at gmail.com> wrote:
> > 
> > Yeah, was kidding around!
> > 
> > On Jan 31, 2015, at 10:47, Ertugrul S?ylemez <ertesx at gmx.de> wrote:
> >>> If only we had a way to produce multiple outputs from a single
> >>> package... :)
> >> 
> >> We have.  The `derivation` function supports producing multiple outputs,
> >> and I'm sure that `mkDerivation` forwards this ability.
> >> 
> >> 
> >> Greets,
> >> Ertugrul
> > 
> > _______________________________________________
> > nix-dev mailing list
> > nix-dev at lists.science.uu.nl
> > http://lists.science.uu.nl/mailman/listinfo/nix-dev
> 
> ------------------------------
> 
> Message: 6
> Date: Sat, 31 Jan 2015 22:03:50 +0100
> From: Ertugrul S?ylemez <ertesx at gmx.de>
> Subject: Re: [Nix-dev] Use Haskell for Shell Scripting
> To: Shea Levy <shea at shealevy.com>, Daniel Peebles
> 	<pumpkingod at gmail.com>
> Cc: nix-dev <nix-dev at lists.science.uu.nl>
> Message-ID: <m4bnleslvt.fsf at deimos.Speedport_W_723V_1_36_000>
> Content-Type: text/plain; charset="utf-8"
> 
> > Yes, I?m planning to work on multiple outputs for ghc soon :)
> 
> Great!  I'm looking forward to that. =)
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: not available
> Type: application/pgp-signature
> Size: 472 bytes
> Desc: not available
> Url :
> http://lists.science.uu.nl/pipermail/nix-dev/attachments/20150131/30b8da8f/
> attachment-0001.bin
> 
> ------------------------------
> 
> Message: 7
> Date: Sun, 01 Feb 2015 08:59:13 +1100
> From: Tim Barbour <trb at categorical.net>
> Subject: Re: [Nix-dev] Use Haskell for Shell Scripting
> To: Ertugrul S?ylemez <ertesx at gmx.de>
> Cc: nix-dev <nix-dev at lists.science.uu.nl>
> Message-ID: <87r3ualiha.wl-trb at categorical.net>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> At Sat, 31 Jan 2015 13:22:09 +0100,
> 
> Ertugrul S?ylemez wrote:
> > [...]
> > I have actually experimented with using Haskell (and a few other FP
> > languages) as a substitute for shells.
> > [...]
> > You might be interested why Curry didn't work.  Simple: I couldn't figure
> > out how to write a program.  Actually I went through the whole tutorial,
> > did all the exercises (they aren't really difficult to a Haskell
> > programmer) and then skimmed through the whole PAKCS manual.  I could
> > write extremely elegant algorithmic code and was quite amazed at the
> > beauty of this language, even compared to Haskell.  But in the end I
> > still didn't know how to turn all this beautiful Curry code into an
> > executable file that I can run without invoking PAKCS explicitly. 
> > Something with a shebang or ideally something binary.  It would probably
> > be possible to write wrapper scripts, but let's just wait until one of
> > the implementations becomes mature enough for systems programming.
> 
> Curry is indeed a beautiful language, and is essentially a conservative
> extension of Haskell. I am surprised that more Haskell folk have not adopted
> it.
> 
> PAKCS compiles Curry to Prolog (typically SICStus), which drags in the
> Prolog system. To get a binary executable, a better choice would be MCC
> (compiles Curry to native code) or KiCS2 (compiles Curry to Haskell, which
> can go into ghc):
> 
>    http://www-ps.informatik.uni-kiel.de/currywiki/implementations/overview
> 
> Tim
> 

The nixpkgs expression for PAKCS uses SWI prolog, and PAKCS has an option for 
producing a wrapper that calls swi to execute your program.  With this you can 
use PAKCS for "scripting" in more or less the same way as perl, php, bash, 
python, nodejs etc

For example:

[kkallio at eka:scratch]$ cat hello.curry
main :: IO ()
main = putStrLn "Hello world!"

[kkallio at eka:scratch]$ pakcs :load hello :save :quit
[1 of 2] Skipping  Prelude          ( 
/nix/store/9rbmp69y6mc578y7iwan8ywn51lf77iz-
pakcs-1.11.4/pakcs/lib/Prelude.curry, 
/nix/store/9rbmp69y6mc578y7iwan8ywn51lf77iz-
pakcs-1.11.4/pakcs/lib/.curry/Prelude.fcy )
[2 of 2] Skipping  hello            ( hello.curry, .curry/hello.fcy )
Executable saved in: hello

[kkallio at eka:scratch]$ ./hello 
Hello world!

[kkallio at eka:scratch]$ 



the produced file "hello" is a bash script which will exec SWI prolog.




More information about the nix-dev mailing list