all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Should Guix support writing CLI Common Lisp scripts? (Think Roswell)
@ 2022-12-27 18:14 jgart
  2022-12-27 18:25 ` John Kehayias
  2022-12-27 19:23 ` jgart
  0 siblings, 2 replies; 9+ messages in thread
From: jgart @ 2022-12-27 18:14 UTC (permalink / raw)
  To: guix-devel; +Cc: glv, Charles, contact

Hi Guixers,

Should Guix support writing CLI Common Lisp scripts? (Think Roswell)

> Although Roswell is a unified interface to Common Lisp implementations, it also encourages writing scripts with it.
> A "Roswell script" is an implementation-independent script which can be invoked from a shell command line, launched by > Roswell and run under standard CL environment.

Just insert "Guix" wherever you see Roswell mentioned in the above quote.

> * A roswell script can be distributed using quicklisp's infrastructure

Just insert "Guix" wherever you see quicklisp is mentioned in the above quote.

> If you're the author of the library, then consider adding the ros file to the repository and automatically providing a roswell-installable command-line interface to it.

Same above, insert Guix.

I think we should make it easier for Lispers to write CLI scripts with Guix.

WDYT

https://roswell.github.io/Roswell-as-a-Scripting-Environment.html


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Should Guix support writing CLI Common Lisp scripts? (Think Roswell)
  2022-12-27 18:14 Should Guix support writing CLI Common Lisp scripts? (Think Roswell) jgart
@ 2022-12-27 18:25 ` John Kehayias
  2023-01-16  1:01   ` Charles
  2022-12-27 19:23 ` jgart
  1 sibling, 1 reply; 9+ messages in thread
From: John Kehayias @ 2022-12-27 18:25 UTC (permalink / raw)
  To: jgart; +Cc: glv, Charles, contact, guix-devel

Hi Guixers/Lispers,

On Tue, Dec 27, 2022 at 06:14 PM, jgart wrote:

> Hi Guixers,
>
> Should Guix support writing CLI Common Lisp scripts? (Think Roswell)
>
>> Although Roswell is a unified interface to Common Lisp implementations, it also
>> encourages writing scripts with it.
>> A "Roswell script" is an implementation-independent script which can be invoked from a
>> shell command line, launched by > Roswell and run under standard CL environment.
>
> Just insert "Guix" wherever you see Roswell mentioned in the above quote.
>
>> * A roswell script can be distributed using quicklisp's infrastructure
>
> Just insert "Guix" wherever you see quicklisp is mentioned in the above quote.
>
>> If you're the author of the library, then consider adding the ros file to the repository
>> and automatically providing a roswell-installable command-line interface to it.
>
> Same above, insert Guix.
>
> I think we should make it easier for Lispers to write CLI scripts with Guix.
>
> WDYT
>
> <https://roswell.github.io/Roswell-as-a-Scripting-Environment.html>

I'm not sure what you mean if it is something beyond what we can do already with 'guix shell.' Do you mean using a particular hashbang as well? I haven't done that but my simplistic usage is quick and easy for me.

For example, I like to have some CL scripts I use for file processing that lives as a single .lisp file. To run it I just do:

guix shell sbcl sbcl-cl-csv unoconv -- sbcl --load myscript.lisp ~/Downloads/*.xlsx

where I can include the compiler/interpreters sbcl, needed library, and an external tool that is called by the script for pre-processing. Works great, and of course instantly after the first caching. This could be combined with a manifest, version/channel pinning, making my script a package in a channel, guix.scm file, and so on, to make it more reproducible. But for me this is already super handy and easy, just one line.

John



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Should Guix support writing CLI Common Lisp scripts? (Think Roswell)
  2022-12-27 18:14 Should Guix support writing CLI Common Lisp scripts? (Think Roswell) jgart
  2022-12-27 18:25 ` John Kehayias
@ 2022-12-27 19:23 ` jgart
  2022-12-27 19:58   ` Russell Sim
                     ` (2 more replies)
  1 sibling, 3 replies; 9+ messages in thread
From: jgart @ 2022-12-27 19:23 UTC (permalink / raw)
  To: John Kehayias, guix-devel

> I'm not sure what you mean if it is something beyond what we can do already with 'guix shell.' Do
> you mean using a particular hashbang as well? 

Yes, that is one feature that I was nodding ambiguously at. Sorry

> guix shell sbcl sbcl-cl-csv unoconv -- sbcl --load myscript.lisp ~/Downloads/*.xlsx

That command is too long. What Roswell does is create binaries and installs them in your PATH for your usage like a traditional script that you can call without also having to call the interpreter in your terminal invocation.

I want to type just the following and have `myscript` be an executable program available in my `guix home` environment:

> myscript ~/Downloads/*.xlsx

I want an automated way to prepare the script for that command line user experience. That is the convenience that roswell provides. I agree that is is sweet sugar but I'm lazy and don't want to type long CLI invocations.

Thanks for sharing the above though.

It's great to see how people are using `guix shell`.

Given what I said, I might just do what you're suggesting John, because I'm not sure when I'll be able to implement a solution like the roswell one in Guix.

Thanks for your thoughts on the topic. They are appreciated.

all best,

jgart


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Should Guix support writing CLI Common Lisp scripts? (Think Roswell)
  2022-12-27 19:23 ` jgart
@ 2022-12-27 19:58   ` Russell Sim
  2022-12-27 21:06   ` jgart
  2022-12-27 22:06   ` bokr
  2 siblings, 0 replies; 9+ messages in thread
From: Russell Sim @ 2022-12-27 19:58 UTC (permalink / raw)
  To: jgart, John Kehayias, guix-devel

"jgart" <jgart@dismail.de> writes:

>> I'm not sure what you mean if it is something beyond what we can do already with 'guix shell.' Do
>> you mean using a particular hashbang as well? 
>
> Yes, that is one feature that I was nodding ambiguously at. Sorry
>
>> guix shell sbcl sbcl-cl-csv unoconv -- sbcl --load myscript.lisp ~/Downloads/*.xlsx
>
> That command is too long. What Roswell does is create binaries and installs them in your PATH for your usage like a traditional script that you can call without also having to call the interpreter in your terminal invocation.
>
> I want to type just the following and have `myscript` be an executable program available in my `guix home` environment:
>
>> myscript ~/Downloads/*.xlsx

What about something like this?

--8<---------------cut here---------------start------------->8---
#!/bin/sh
#|-*- mode:lisp -*-|#
#|
exec guix shell sbcl -- sbcl --script $0 "$@"
|#

(format t "test~%")
--8<---------------cut here---------------end--------------->8---

This example is pretty similar to the ROS file header which would be
like.

--8<---------------cut here---------------start------------->8---
#!/bin/sh
#|-*- mode:lisp -*-|#
#|
exec ros -Q -- $0 "$@"
|#

(format t "test~%")
--8<---------------cut here---------------end--------------->8---

Cheers,
Russell


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Should Guix support writing CLI Common Lisp scripts? (Think Roswell)
  2022-12-27 19:23 ` jgart
  2022-12-27 19:58   ` Russell Sim
@ 2022-12-27 21:06   ` jgart
  2022-12-27 21:42     ` Russell Sim
  2022-12-27 22:06   ` bokr
  2 siblings, 1 reply; 9+ messages in thread
From: jgart @ 2022-12-27 21:06 UTC (permalink / raw)
  To: Russell Sim, John Kehayias, guix-devel

> What about something like this?
> 
> --8<---------------cut here---------------start------------->8---
> #!/bin/sh
> #|-*- mode:lisp -*-|#
> #|
> exec guix shell sbcl -- sbcl --script $0 "$@"
> |#
> 
> (format t "test~%")
> --8<---------------cut here---------------end--------------->8---
> 
> This example is pretty similar to the ROS file header which would be
> like.
> 
> --8<---------------cut here---------------start------------->8---
> #!/bin/sh
> #|-*- mode:lisp -*-|#
> #|
> exec ros -Q -- $0 "$@"
> |#
> 
> (format t "test~%")
> --8<---------------cut here---------------end--------------->8---
> 
> Cheers,
> Russell


Yaaaaas!

That's it!!!


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Should Guix support writing CLI Common Lisp scripts? (Think Roswell)
  2022-12-27 21:06   ` jgart
@ 2022-12-27 21:42     ` Russell Sim
  2023-01-17 10:07       ` Attila Lendvai
  0 siblings, 1 reply; 9+ messages in thread
From: Russell Sim @ 2022-12-27 21:42 UTC (permalink / raw)
  To: jgart, John Kehayias, guix-devel

"jgart" <jgart@dismail.de> writes:

>> What about something like this?
>> 
>> --8<---------------cut here---------------start------------->8---
>> #!/bin/sh
>> #|-*- mode:lisp -*-|#
>> #|
>> exec guix shell sbcl -- sbcl --script $0 "$@"
>> |#
>> 
>> (format t "test~%")
>> --8<---------------cut here---------------end--------------->8---
>> 
>
> Yaaaaas!

I have found there are limitations with the `--script' option. Namely
that ASDF can't be used because it disable the userinit file.  I'm not
sure how to locate where that file is in guix.  So to avoid that the one
option is to emulate the behaviour, which is a bit more complicated. :/

so a full script example would be more like this

--8<---------------cut here---------------start------------->8---
#!/bin/bash
#|-*- mode:lisp -*-|#
#|
exec guix shell \
  -m $(dirname "${BASH_SOURCE[0]}")/../manifest.scm \
  -- sbcl \
   --noinform \
   --disable-ldb \
   --lose-on-corruption \
   --disable-debugger \
   --non-interactive \
   --eval "(set-dispatch-macro-character #\\# #\\! (lambda (stream char arg) (declare (ignore char arg)) (read-line stream)))" \
   --load $0 "$@"
|#

(unless (let ((*standard-output* (make-broadcast-stream))
	      (*trace-output* (make-broadcast-stream))
	      (*error-output* (make-broadcast-stream)))
	  (asdf:load-system :balanced-parentheses))
  (warn "Failed to load balanced-parentheses")
  (uiop:quit 1))

(format t "Success~%")
--8<---------------cut here---------------end--------------->8---

This is using a guix manifest, because I want this for development with
a local project, but any guix shell options should work.  So I switched
it to bash, to support the manifest loading, but sh would work work if
you are happy listing the dependencies.

Cheers,
Russell


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Should Guix support writing CLI Common Lisp scripts? (Think Roswell)
  2022-12-27 19:23 ` jgart
  2022-12-27 19:58   ` Russell Sim
  2022-12-27 21:06   ` jgart
@ 2022-12-27 22:06   ` bokr
  2 siblings, 0 replies; 9+ messages in thread
From: bokr @ 2022-12-27 22:06 UTC (permalink / raw)
  To: jgart; +Cc: John Kehayias, guix-devel

Hi Jgart,

On +2022-12-27 19:23:18 +0000, jgart wrote:
> > I'm not sure what you mean if it is something beyond what we can do already with 'guix shell.' Do
> > you mean using a particular hashbang as well? 
> 
> Yes, that is one feature that I was nodding ambiguously at. Sorry
> 
> > guix shell sbcl sbcl-cl-csv unoconv -- sbcl --load myscript.lisp ~/Downloads/*.xlsx
> 
> That command is too long. What Roswell does is create binaries and installs them in your PATH for your usage like a traditional script that you can call without also having to call the interpreter in your terminal invocation.
> 
> I want to type just the following and have `myscript` be an executable program available in my `guix home` environment:
> 
> > myscript ~/Downloads/*.xlsx

If bash is interpreting your script, could you use alias myscript=YOUR_MAGIC_HERE
to get the concise invocations you want?
(which bash BTW? -- from logind, child of that, or via a guix profile, or minimal-something ??)
┌──────────────────────────────────────────────────────────────────────────────┐
│                                  help alias                                  │
├──────────────────────────────────────────────────────────────────────────────┤
│ alias: alias [-p] [name[=value] ... ]                                        │
│     Define or display aliases.                                               │
│                                                                              │
│     Without arguments, `alias' prints the list of aliases in the reusable    │
│     form `alias NAME=VALUE' on standard output.                              │
│                                                                              │
│     Otherwise, an alias is defined for each NAME whose VALUE is given.       │
│     A trailing space in VALUE causes the next word to be checked for         │
│     alias substitution when the alias is expanded.                           │
│                                                                              │
│     Options:                                                                 │
│       -p      print all defined aliases in a reusable format                 │
│                                                                              │
│     Exit Status:                                                             │
│     alias returns true unless a NAME is supplied for which no alias has been │
│     defined.                                                                 │
└──────────────────────────────────────────────────────────────────────────────┘

> 
> I want an automated way to prepare the script for that command line user experience. That is the convenience that roswell provides. I agree that is is sweet sugar but I'm lazy and don't want to type long CLI invocations.
>

I think it's possible, the question for me is what language
do you want to code your automation in :)

> Thanks for sharing the above though.
> 
> It's great to see how people are using `guix shell`.
> 
> Given what I said, I might just do what you're suggesting John, because I'm not sure when I'll be able to implement a solution like the roswell one in Guix.
> 
> Thanks for your thoughts on the topic. They are appreciated.
> 
> all best,
> 
> jgart
>
--
Regards,
Bengt Richter


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Should Guix support writing CLI Common Lisp scripts? (Think Roswell)
  2022-12-27 18:25 ` John Kehayias
@ 2023-01-16  1:01   ` Charles
  0 siblings, 0 replies; 9+ messages in thread
From: Charles @ 2023-01-16  1:01 UTC (permalink / raw)
  To: john.kehayias, jgart; +Cc: glv, contact, guix-devel

Hello. I have done scripts exactly as John describe before. I think this way is fine for making common lisp scripts on guix; that command line you shared can be put in a file and run as a shell script, or even put into a package. 

I think what Jgart is asking for is a program that may or may not be a part of gnu guix, but certainly depends on it. This program will be able to run roswell scripts with 100% compatibility using guix instead of roswell for loading systems. I'm not too sure how roswell knows which system to load or which common lisp implementation to use for a given script.

The purpose of this program would be to use guix's common lisp implementations and systems for roswell scripts. As I understand it, running roswell on a guix system will result in roswell downloading and installing it's own common lisp implementation and loading systems from quicklisp. 

-------- Original Message --------
On Dec 27, 2022, 12:25 PM, John Kehayias < john.kehayias@protonmail.com> wrote:

> 
> Hi Guixers/Lispers, On Tue, Dec 27, 2022 at 06:14 PM, jgart wrote: > Hi Guixers, > > Should Guix support writing CLI Common Lisp scripts? (Think Roswell) > >> Although Roswell is a unified interface to Common Lisp implementations, it also >> encourages writing scripts with it. >> A "Roswell script" is an implementation-independent script which can be invoked from a >> shell command line, launched by > Roswell and run under standard CL environment. > > Just insert "Guix" wherever you see Roswell mentioned in the above quote. > >> * A roswell script can be distributed using quicklisp's infrastructure > > Just insert "Guix" wherever you see quicklisp is mentioned in the above quote. > >> If you're the author of the library, then consider adding the ros file to the repository >> and automatically providing a roswell-installable command-line interface to it. > > Same above, insert Guix. > > I think we should make it easier for Lispers to write CLI scripts with Guix. > > WDYT > > I'm not sure what you mean if it is something beyond what we can do already with 'guix shell.' Do you mean using a particular hashbang as well? I haven't done that but my simplistic usage is quick and easy for me. For example, I like to have some CL scripts I use for file processing that lives as a single .lisp file. To run it I just do: guix shell sbcl sbcl-cl-csv unoconv -- sbcl --load myscript.lisp ~/Downloads/*.xlsx where I can include the compiler/interpreters sbcl, needed library, and an external tool that is called by the script for pre-processing. Works great, and of course instantly after the first caching. This could be combined with a manifest, version/channel pinning, making my script a package in a channel, guix.scm file, and so on, to make it more reproducible. But for me this is already super handy and easy, just one line. John


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Should Guix support writing CLI Common Lisp scripts? (Think Roswell)
  2022-12-27 21:42     ` Russell Sim
@ 2023-01-17 10:07       ` Attila Lendvai
  0 siblings, 0 replies; 9+ messages in thread
From: Attila Lendvai @ 2023-01-17 10:07 UTC (permalink / raw)
  To: Russell Sim; +Cc: jgart, John Kehayias, guix-devel

i have this, which uses guix when available, but works without it, too:

the entire file:

https://hub.darcs.net/hu.dwim/hu.dwim.environment/browse/bin/build-development-image.sh

it builds an executable SBCL image with every dependency of our project loaded. we start it as an inferior for Slime.

the essence:

#!/usr/bin/env bash
#| -*- mode: lisp; coding: utf-8-unix -*-

SCRIPT_DIR=`dirname "$0"`
SCRIPT_DIR=`readlink -f ${SCRIPT_DIR}`

if command -v guix &> /dev/null; then
  echo "Guix detected, entering the environment."
  eval $(guix shell --search-paths libffi openssl sdl2 sdl2-gfx sdl2-image sdl2-ttf bluez sqlite graphviz libfixposix pkg-config clang-toolchain --development sbcl)
  # this is needed for SBCL to find some of the .so files
  export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}${LIBRARY_PATH}"
  echo "Setting LD_LIBRARY_PATH based on LIBRARY_PATH to ${LD_LIBRARY_PATH}"
fi

# NOTE: using --script would also imply --no-userinit (i.e. quicklisp wouldn't get loaded from .sbclrc), so we use a different trick here to skip the first line of this shell script file when reading it as a lisp file.
exec ${LISP} --noinform --end-runtime-options \
  --eval "(require :asdf)" --eval "(asdf:load-system :asdf)" \
  --eval "(with-open-file (s \"${0}\" :element-type 'character) (read-line s) (load s))" \
  --end-toplevel-options 2>&1 | tee ${BUILD_LOG_FILE}

# let's quit the shell part before the shell interpreter runs on the lisp stuff below
kill -INT $$

# and from here follows the lisp part that gets "called" above |#

(in-package :cl-user)

[...]

-- 
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“To put the world in order, we must first put the nation in order; to put the nation in order, we must first put the family in order; to put the family in order; we must first cultivate our personal life; we must first set our hearts right.”
	— Confucius (551–479 BC)



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-01-17 10:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-27 18:14 Should Guix support writing CLI Common Lisp scripts? (Think Roswell) jgart
2022-12-27 18:25 ` John Kehayias
2023-01-16  1:01   ` Charles
2022-12-27 19:23 ` jgart
2022-12-27 19:58   ` Russell Sim
2022-12-27 21:06   ` jgart
2022-12-27 21:42     ` Russell Sim
2023-01-17 10:07       ` Attila Lendvai
2022-12-27 22:06   ` bokr

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.