add nixify/flakify helper

This commit is contained in:
Jörg Thalheim 2021-05-29 13:04:44 +02:00
parent b45b9dc614
commit 40b96cbd35
No known key found for this signature in database
GPG key ID: B3F5D81B0C6967C4

View file

@ -214,6 +214,41 @@ $ touch shell.nix
$ touch flake.nix
```
## Shell integration
To quickly add a default.nix/flake.nix to a project you can put the following snippets in your bashrc/zshrc
```bash
nixify() {
if [ ! -e ./.envrc ]; then
echo "use nix" > .envrc
direnv allow
fi
if [[ ! -e shell.nix ]] && [[ ! -e default.nix ]]; then
cat > default.nix <<'EOF'
with import <nixpkgs> {};
mkShell {
nativeBuildInputs = [
bashInteractive
];
}
EOF
${EDITOR:-vim} default.nix
fi
}
flakifiy() {
if [ ! -e flake.nix ]; then
nix flake new -t github:nix-community/nix-direnv .
elif [ ! -e .envrc ]; then
echo "use flake" > .envrc
direnv allow
fi
${EDITOR:-vim} flake.nix
}
```
## Known Bugs
At the moment `nix-direnv` depends on GNU Grep and a modern Bash version.