Skip to content

Instantly share code, notes, and snippets.

@rektide
Last active August 25, 2016 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rektide/c6a23abd77114d23854ce88c9d66b91f to your computer and use it in GitHub Desktop.
Save rektide/c6a23abd77114d23854ce88c9d66b91f to your computer and use it in GitHub Desktop.
Use `direnv` instead of systemd

Direnv-launch

Systemd is supposed to be the swiss army knife of starting things and keeping them going. For the most part, it works really really well. It has a very flexible developer-friendly way of letting one specify EnvironmentFile's providing environmental variables for programs it's launching.

The major pitfall is that it does not in any way support multi-line values. If you want to pass in a normal boring certificate to your applicatino (because you are a good respectful 12factor dev practicing proper config), you may be S.O.L (shit out of luck).

Thie horrible helper, direnv-launch, lets one use direnv-ish files when launching programs. Direnv's .envrc files can be multi-line, which is great. This is also going to be compatible and useful with your fellow Mac & Windows developers. Note that variables must be declared as export in envrc, as in export FOO=bar, which is different, but closely mimics how everything else in the world is done.

Downsides

The primary downside is the loss of systemd's awesome ability to pick a whole lot of different EnvironmentFiles to run from. Having ~/.config/user/my-app.d/20-env-a.conf ~/.config/user/my-app.d/30-env-b.conf &c is a far more pleasant way to break up config that direnv has no means to support.

#!/bin/bash
. ./.envrc
eval $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment