guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Named environments


From: Sarah Morgensen
Subject: Re: Named environments
Date: Sun, 12 Sep 2021 12:33:26 -0700

Ryan Prior <rprior@protonmail.com> writes:

> Hey Guix.
>
> I've been thinking lately it would be convenient to create certain uniquely
> named execution environments on my machine. For example, I might have one
> set up with dependencies for my Python webapp & environment variables set to
> autoconnect to a Postgres server. I might have another that's got test
> dependencies and is containerized, such that it can only access the network
> & not the rest of my filesystem. Suppose I name these two "webapp" and
> "test" respectively.
>
> I picture running eg `guix env @webapp -- uvicorn main:app` to start my
> server, then `guix env @test -- pytest` to run my tests.
>
> I might write a wrapper in some scripting language that sets up this kind of
> system. Would anybody else be interested in using such a thing? Would it
> make sense to integrate this capability into Guix itself?
>
>Ryan

I like this idea!  (And adding a built-in alias from "environment" to "env"
might be worth it, too.)

I actually use an ad-hoc version of this in my ~/.bashrc, using aliases. For
example,

  alias geg='guix environment guix --pure --ad-hoc nano git git:send-email less 
help2man strace nss-certs'

This also lets me add on any ad-hoc packages at the end, like

  geg dejagnu expect

However, an actual `guix env' could do a lot more!  Like you allude to, being
able to essentially save the options of a `guix environment' invocation would
be great:

  $ guix env --edit @test <lots of packages and environment options>
  $ guix env @test -- pytest

But also imagine portable environments (used, for example, for project dev
environments, checked in with the source):

--8<---------------cut here---------------start------------->8---
$ guix env --export @myapp-test --pure -C -f guix.scm --ad-hoc strace coreutils

(environment "@myapp-test"
 (load '("guix.scm"))
 (ad-hoc-packages '("strace" "coreutils" "findutils")) 
 (flags '(pure container)))
--8<---------------cut here---------------end--------------->8---

Of course, this isn't entirely reproducible, as packages could change as you
update your Guix, even if you give a version spec (the same issue that exists
for manifests).  So, we could pin the channel used to make the environment:

--8<---------------cut here---------------start------------->8---
$ guix env --export @myapp-test --pin-channels ...

(environment "@myapp-test"
 (channels (list (channel (name 'guix)
                          (url ...)
                          (commit ...)))
 (load '("guix.scm"))
 (ad-hoc-packages '("strace" "coreutils" "findutils")) 
 (flags '(pure container))))
--8<---------------cut here---------------end--------------->8---

which, when evaluated, would internally do what `guix time-machine --channels
file' does.

These environments could then be used like:

  $ guix env -e environment.scm @myapp-test

but that's quite long... perhaps we could allow `guix env' to automatically
read a "guix.scm" or "environment.scm" file in the current directory, and make
the environment definitions within available?

...so I definitely think there's room for such a feature in Guix :)

--
Sarah



reply via email to

[Prev in Thread] Current Thread [Next in Thread]