diff --git a/.gitignore b/.gitignore index 9b42106..375afd0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .direnv/ +/template/flake.lock diff --git a/README.md b/README.md index 3901b9c..c850c6c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e45f646 --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f36120e --- /dev/null +++ b/flake.nix @@ -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 ."; + }; + }; +} diff --git a/scripts/create-release.sh b/scripts/create-release.sh index 74ecd02..6f93bec 100755 --- a/scripts/create-release.sh +++ b/scripts/create-release.sh @@ -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 diff --git a/template/.envrc b/template/.envrc new file mode 100644 index 0000000..ab38c5f --- /dev/null +++ b/template/.envrc @@ -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 diff --git a/template/flake.nix b/template/flake.nix new file mode 100644 index 0000000..b65b154 --- /dev/null +++ b/template/flake.nix @@ -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 = [ ]; + }; + }); +}