add project template

This commit is contained in:
Jörg Thalheim 2021-05-29 09:19:31 +02:00
parent 1134713112
commit 5655ef0fbd
No known key found for this signature in database
GPG key ID: B3F5D81B0C6967C4
7 changed files with 85 additions and 20 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
.direnv/
/template/flake.lock

View file

@ -160,31 +160,16 @@ guarantee stability after an nix upgrade.
Likewise `use_nix` the `use_flake` implementation will prevent garbage
collection of downloaded packages and also for flake inputs.
Save this file as `flake.nix`:
You can run `nix flake new -t github:nix-community/nix-direnv` to get [this](https://github.com/nix-community/nix-direnv/tree/master/template) project template.
or just add:
``` nix
{
description = "A very basic flake";
# Provides abstraction to boiler-code when specifying multi-platform outputs.
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
devShell = pkgs.mkShell {
nativeBuildInputs = [ pkgs.hello ];
};
});
}
```
Then add `use flake` to your `.envrc`:
```console
$ echo "use flake" >> .envrc
$ direnv allow
```
in case the project already comes with a `flake.nix`
## Storing .direnv outside the project directory
A `.direnv` directory will be created in each `use_nix` project, which might

43
flake.lock generated Normal file
View file

@ -0,0 +1,43 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1620759905,
"narHash": "sha256-WiyWawrgmyN0EdmiHyG2V+fqReiVi8bM9cRdMaKQOFg=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1622059058,
"narHash": "sha256-t1/ZMtyxClVSfcV4Pt5C1YpkeJ/UwFF3oitLD7Ch/UA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "84aa23742f6c72501f9cc209f29c438766f5352d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

17
flake.nix Normal file
View file

@ -0,0 +1,17 @@
{
description = "A faster, persistent implementation of `direnv`'s `use_nix`, to replace the built-in one.";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
defaultPackage = pkgs.callPackage ./default.nix {};
}) // {
defaultTemplate = {
path = ./template;
description = "nix flake new -t github:Mic92/nix-direnv .";
};
};
}

View file

@ -21,7 +21,7 @@ fi
sed -i direnvrc \
-e 's!\(declare major=\).*\( # UPDATE(nix-direnv version)\)!\1'"${ver[0]@Q} minor=${ver[1]@Q} patch=${ver[2]@Q}"'\2!'
sed -i README.md \
sed -i README.md template/.envrc \
-e 's!\(nix-direnv/\).*\(/direnvrc\)!\1'"${version}"'\2!' \
-e 's?\( ! nix_direnv_version \)[0-9.]\+\(; \)?\1'"${version}"'\2?'
git add README.md direnvrc

4
template/.envrc Normal file
View file

@ -0,0 +1,4 @@
if ! has nix_direnv_version || ! nix_direnv_version 1.3.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/1.3.0/direnvrc" "sha256-1VWM1BnI1GvclYBky5f5Y9HqeThmQUwCWQbsFQM1Eu0="
fi
use flake

15
template/flake.nix Normal file
View file

@ -0,0 +1,15 @@
{
description = "A basic flake with a shell";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
devShell = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = [ ];
};
});
}