Skip to content

Instantly share code, notes, and snippets.

@jahkeup
Last active April 30, 2020 18:32
Show Gist options
  • Select an option

  • Save jahkeup/1dd24208ec35596da7d78ffddcd0738a to your computer and use it in GitHub Desktop.

Select an option

Save jahkeup/1dd24208ec35596da7d78ffddcd0738a to your computer and use it in GitHub Desktop.
Bottlerocket development with direnv

direnv workspace environment helper

Using direnv, one can load the Bottlerocket environment to build single packages and iterate as needed.

Using this

# Assuming you have direnv installed:
curl -sSL https://gist.githubusercontent.com/jahkeup/1dd24208ec35596da7d78ffddcd0738a/raw/10-bottlerocket-os-direnv-dotenv.sh >> .envrc
direnv allow
# .envrc
#use nix # requires a shell.nix next to .envrc
# Add tools to PATH.
path_add PATH "bin"
path_add PATH "tools/bin"
# Build and load a dotenv from the cargo-make build setup. This allows running
# package local builds within the source tree.
log_status "exporting cargo-make environment as dotenv"
# Extend the main Makefile.toml with a task to print out its environment
# variables.
cargo make dotenv --loglevel error --cwd $(expand_path .) --makefile /dev/stdin <<EOF
extend = "$(expand_path "Makefile.toml")"
[tasks.dotenv]
script = [
'''
env | grep -e ^DOCKER -e ^BUILDSYS -e ^CARGO -e ^GO_ | grep -v ^CARGO_MAKE | sort > .env
'''
]
EOF
# Track Makefile.toml to rebuild dotenv on change.
watch_file Makefile.toml
# Load the created dotenv
dotenv
# Place a dummy value so the "real build" doesn't use dotenv's builds.
export BUILDSYS_VERSION_BUILD="dotenv"
# shell.nix - add to .envrc by uncommenting 'use nix'
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
mkShell {
name = "bottlerocket-dev";
buildInputs = [
# Workspace bootstrap (ex: buildsys)
openssl zlib pkg-config gcc
# General tools
jq lz4 quilt bat rpm gptfdisk
# Debugging tools
#libguestfs-with-appliance # Very big derivation, don't uncomment until needed!
# KConfig config tools (in $kernel_src/scripts/kconfig)
flex bison
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment