69 lines
1.8 KiB
Nix
69 lines
1.8 KiB
Nix
{ lib, pkgs, ... }:
|
|
let
|
|
flake-dir = {flake, impure ? false}: pkgs.writeShellScript "nix-prepare" ''
|
|
run() {
|
|
local dir="$1"
|
|
echo "Preparing nix environment in $dir"
|
|
|
|
if [ "$dir" = "" ]; then
|
|
echo "Usage: nix-prepare <dir>"
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p $dir
|
|
cd $dir
|
|
|
|
git init
|
|
|
|
# Insert the nix flake
|
|
cp ${flake} flake.nix
|
|
chmod 644 flake.nix
|
|
|
|
echo '/*' > .gitignore
|
|
echo '!/.gitignore' >> .gitignore
|
|
echo '!/flake.nix' >> .gitignore
|
|
echo '!/flake.lock' >> .gitignore
|
|
echo 'use flake .${(if impure then " --impure" else "")}' > .envrc
|
|
|
|
git add flake.nix .gitignore
|
|
git commit -m "Setup initial flake"
|
|
|
|
direnv allow
|
|
eval "$(direnv export bash)"
|
|
|
|
git add flake.lock
|
|
git commit -m "Lock flakes"
|
|
}
|
|
|
|
run "$@"
|
|
'';
|
|
|
|
git-flake-dir-clone = { flake, impure? false}: pkgs.writeShellScript "git-nix-clone" ''
|
|
# Input is a git repository such as git@github.com:group/project-name.git
|
|
run() {
|
|
local repo="$1"
|
|
local projectName=$(echo "$repo" | sed 's/.*\///' | sed 's/\.git//')
|
|
|
|
if [ "$repo" = "" ]; then
|
|
echo "Usage: git-nix-clone <repo>"
|
|
exit 1
|
|
fi
|
|
|
|
${flake-dir {inherit flake impure;}} "$projectName"-nix
|
|
|
|
git clone "$repo" "$projectName"-nix"/$projectName"
|
|
}
|
|
|
|
run "$@"
|
|
'';
|
|
in
|
|
{
|
|
programs.zsh.shellAliases = {
|
|
git-c3c-clone = lib.mkDefault "${git-flake-dir-clone { flake = ./flake-templates/c3c-flake.nix; impure = false;}}";
|
|
flake-dir-c3c = lib.mkDefault "${flake-dir { flake = ./flake-templates/c3c-flake.nix; impure = false;}}";
|
|
flake-dir-yp = lib.mkDefault "${flake-dir { flake = ./flake-templates/yp-flake.nix; impure = false;}}";
|
|
flake-dir-investbay = lib.mkDefault "${flake-dir { flake = ./flake-templates/investbay-flake.nix; impure = false;}}";
|
|
};
|
|
|
|
}
|