Skip to content

Commit

Permalink
add direnv boiler plate to module
Browse files Browse the repository at this point in the history
  • Loading branch information
jashan-lco committed Feb 5, 2025
1 parent 7165b03 commit 8dabe30
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
14 changes: 12 additions & 2 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# https://github.com/nix-community/nix-direnv
if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
fi

use flake . --impure
watch_file flake.nix
watch_file flake.lock

DEVENV_ROOT_FILE="$(mktemp)"
printf %s "$PWD" > "$DEVENV_ROOT_FILE"
if ! use flake . --override-input devenv-root "file+file://$DEVENV_ROOT_FILE"
then
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.devenv

.pre-commit-config.yaml

.direnv
6 changes: 6 additions & 0 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ in
in {
name = "devenv-k8s";

devenv.root =
let
devenvRootFileContent = builtins.readFile localFlake.inputs.devenv-root.outPath;
in
pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;

imports = [
./skaffold-builder.nix
./cd.nix
Expand Down
13 changes: 13 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
description = "A devenv with common tools needed for K8s, GitOps, etc.";

inputs = {
devenv-root = {
url = "file+file:///dev/null";
flake = false;
};

nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
devenv.url = "github:cachix/devenv";
Expand Down Expand Up @@ -62,7 +67,7 @@

systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];

perSystem = { inputs', ...}: {
perSystem = { pkgs, inputs', ...}: {

packages = {
kpt = inputs'.kpt.packages.default;
Expand Down
13 changes: 13 additions & 0 deletions templates/app-repo/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
fi

watch_file flake.nix
watch_file flake.lock

DEVENV_ROOT_FILE="$(mktemp)"
printf %s "$PWD" > "$DEVENV_ROOT_FILE"
if ! use flake . --override-input devenv-root "file+file://$DEVENV_ROOT_FILE"
then
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi
5 changes: 5 additions & 0 deletions templates/app-repo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.devenv

.pre-commit-config.yaml

.direnv

0 comments on commit 8dabe30

Please sign in to comment.