Add flake template to nix-direnv

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-01-21 16:47:40 +00:00
parent d9c9e40f6c
commit 24401a18c6
2 changed files with 54 additions and 5 deletions

View File

@@ -32,15 +32,34 @@
nix-direnv() {
if [ -z "$1" ]; then
echo "use flake" > .envrc
if [ ! -f flake.nix ]; then
echo "Do you want to create an empty flake.nix? (y/N)"
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
cp "${./template.nix}" flake.nix
fi
fi
else
echo "use flake self#$1" > .envrc
fi
if git rev-parse --is-inside-work-tree &> /dev/null && ! grep -q "^\.envrc$" .gitignore .git/info/exclude; then
echo "Do you want to hide the .envrc file from git? (y/N)"
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
echo ".envrc" >> .git/info/exclude
if git rev-parse --is-inside-work-tree &> /dev/null; then
if ! grep -q "^\.envrc$" .gitignore .git/info/exclude; then
echo "Do you want to hide the .envrc file from git? (y/N)"
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
echo ".envrc" >> .git/info/exclude
fi
fi
if [ -f flake.nix ] && ! grep -q "^flake.nix$" .gitignore .git/info/exclude; then
echo "Do you want to hide the flake.nix and flake.lock files from git? (y/N)"
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
echo "flake.nix" >> .git/info/exclude
echo "flake.lock" >> .git/info/exclude
fi
fi
fi

View File

@@ -0,0 +1,30 @@
{
inputs = {
nixpkgs = {
type = "github";
owner = "karaolidis";
repo = "nixpkgs";
ref = "integration";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
};
outputs =
{ nixpkgs, ... }@inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
packages = [ ];
};
formatter = pkgs.nixfmt-rfc-style;
}
);
}