Skip to content

pc-magas/mkdotenv

Repository files navigation

 __  __ _    _____        _                  
|  \/  | |  |  __ \      | |                 
| \  / | | _| |  | | ___ | |_ ___ _ ____   __
| |\/| | |/ / |  | |/ _ \| __/ _ \ '_ \ \ / /
| |  | |   <| |__| | (_) | ||  __/ | | \ V / 
|_|  |_|_|\_\_____/ \___/ \__\___|_| |_|\_/  

Stop Hardcoding Secrets – Use mkdotenv to Build Your Environment!

Managing .env files shouldn't be a manual chore. MkDotenv automates the population of your environment variables by resolving secrets from your preferred backends. Just define your requirements in a template, run mkdotenv, and get a ready-to-use .env file for any environment—local, staging, or production.

Copr build status

Quick Usage

  1. Create a .env.dist template file containing these:
#mkdotenv(prod):resolve("web/secret")::keepassx(file="mydb.kpbx",password="XXXXX").PASSWORD
DB_PASSWORD=
  1. Setup KeePassXC:
  • Create a Group named web.
  • Inside that group, create an Entry with the Title secret.
  • Set the Password field of that entry to your actual secret value.

The final structure should be:

web (Group)
 └── secret (Entry)
  ├── Password: [your_password]
  └── Title: secret

Consult this youtube video on how save a password on keepassx.

  1. Run
mkdotenv --environment prod

This would populate the DB_PASSWORD value from the password stored upon keepassx db into a new file named .env. Have a look upon project's docs folder for mote info.

Build from source (Supported in Linux & macOS)

Compilation required to have make and golang installed. Both Go 1.23 and 1.24 supported.

Step 0: Install golang and make:

On Ubuntu Linux and Linux mint

On Linux Mint and Ubuntu, you can run:

sudo apt-get install make golang-1.23*

On macOS and other distros

For other linux distros and macOS follow official instructions https://go.dev/doc/install

Install make upon macOs

You can use either xcode or homebrew. Homebrew method is in https://formulae.brew.sh/formula/make

Step 1: Clone repo:

git clone https://github.com/pc-magas/mkdotenv.git

For a specific version (e.g v0.3.2) you can also do:

export VERSION=v0.3.2
git clone --depth 1 --branch ${VERSION} https://github.com/pc-magas/mkdotenv.git

Step 2: Compile

make

Note

In case you use the golang-1.23 package shipped with ubuntu and linux mint, and unable to run go command line into the shell you can also run this command:

make GO=/usr/lib/go-1.23/bin/go

Step 3: Install

sudo make install

(If run as root omit sudo)

Once make install is successfully run golang can be uninstalled if desired, it is a build-only requirement.

Uninstall

If cloned this repo and built the tool you can do:

sudo make uninstall

Otherwise you can do it manually:

sudo rm -f /usr/bin/mkdotenv
sudo rm -f /usr/local/share/man/man1/mkdotenv.1 

sudo rm -f /usr/local/bin/mkdotenv
sudo rm -f /usr/local/share/man/man1/mkdotenv.1 

Installation

Install In linux

From Executable Binaries

# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
wget -o mkdotenv https://github.com/pc-magas/mkdotenv/releases/download/${VERSION}/mkdotenv-linux-amd64 
sudo cp mkdotenv-linux-amd64  /bin/mkdotenv
sudo chmod 755 /bin/mkdotenv

mkdotenv --version

For environments that do not provide root access use these commands:

# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
wget -o mkdotenv https://github.com/pc-magas/mkdotenv/releases/download/${VERSION}/mkdotenv-linux-amd64 
cp mkdotenv-linux-amd64  ~/.local/bin/mkdotenv
chmod 755 ~/.local/bin/mkdotenv

mkdotenv --version

Uninstall

rm -rf /bin/mkdotenv

Using PPA for Ubuntu & Linux Mint

If running ubuntu or Linux mint you can use our PPA repository:

sudo add-apt-repository ppa:pcmagas/mkdotenv
sudo apt-get update
sudo apt-get install mkdotenv

From debian package

Works in Debian, Mint and Ubuntu (or any other Debian-compatible distros)

# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
wget https://github.com/pc-magas/mkdotenv/releases/download/${VERSION}/mkdotenv_${VERSION}_amd64.deb
sudo dpkg -i mkdotenv_${VERSION}_amd64.deb

At code above replace ^found_version^ with the version shown at Detect Latest Version.

Uninstalling the package is easy as:

sudo apt-get remove mkdotenv

Using RPM package

Tested on Fedora

# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
wget https://github.com/pc-magas/mkdotenv/releases/download/v${VERSION}/mkdotenv.rpm
sudo rpm -i mkdotenv-${VERSION}-1.fc41.x86_64.rpm

At code above replace ^found_version^ with the version shown at Detect Latest Version.

In Fedora Linux

App is delivered via corpr you can install it like this:

sudo dnf install dnf-plugins-core
dnf copr enable pc-magas/mkdotenv 
sudo dnf install mkdotenv

In amazon Linux 2023

Packages available through corpr

sudo dnf install -y 'dnf-command(copr)'
sudo dnf copr enable pc-magas/mkdotenv 
sudo dnf install -y mkdotenv

In OpenSuse

Fedora Corpr repositories also are available for OpenSuse (both leap and tumbleweed)

sudo zypper install opi
opi copr pc-magas/mkdotenv
sudo zypper install mkdotenv

In Alpine Linux

# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
wget https://github.com/pc-magas/mkdotenv/releases/download/v${VERSION}/mkdotenv-${VERSION}-r0.apk

There's a pending release for alpine linux on official repositories.

Then as root user run:

apk add --allow-untrusted mkdotenv-${VERSION}-r0.apk

At code above replace ^found_version^ with the version shown at Detect Latest Version.

In arch Linux

Mkdotenv is shipped via AUR, use yay to install:

yay mkdotenv

Install upon Windows

Windows builds are provided as standalone binaries without an installer.

Just download the .exe from releases page ( https://github.com/pc-magas/mkdotenv/releases ) and run it through cmd/powershell:

mkdotenv-windows-amd64.exe 

Once downloaded it can be renamed as mkdotenv.exe.

Install upon MacOS

Using Homebrew

macOS binaries for M Series are shipped via homebrew. For intel based releases compile it from source.

brew tap pc-magas/mkdotenv
brew install pc-magas/mkdotenv/mkdotenv
mkdotenv --help

For intel macs you need to compile from source

From Statically Built Binaries

Statically-built binaries that can be converted into executable for M series macOS are also shipped as well.

# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
wget -o mkdotenv https://github.com/pc-magas/mkdotenv/releases/download/${VERSION}/mkdotenv-darwin-arm64 
sudo cp mkdotenv /usr/local/bin/mkdotenv
sudo chmod 755 /usr/local/mkdotenv

mkdotenv --version

Extended Documentation

For usage consult ./docs folder:

Local Help

Furthermore argument usage is documented via man:

man mkdotenv

Or via --help argument:

mkdotenv --help

About

Simplify Your .env Files – Populate variable values from secrets

Resources

License

Stars

Watchers

Forks

Packages