Skip to content

Commit

Permalink
Add shell.nix to flake template (#230)
Browse files Browse the repository at this point in the history
* Add `shell.nix` to flake template

This allows `nix-shell` to be used from tools that have not yet been
updated to support `nix develop` (ex:
https://github.com/arrterian/nix-env-selector)

* Add edolstra's flake-compat shim to the template
  • Loading branch information
rummik authored Sep 16, 2023
1 parent 8ddd503 commit f26c2e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion templates/toml/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
inputs.devshell.url = "github:numtide/devshell";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, flake-utils, devshell, nixpkgs }:
inputs.flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};

outputs = { self, flake-utils, devshell, nixpkgs, ... }:
flake-utils.lib.eachDefaultSystem (system: {
devShell =
let
Expand Down
25 changes: 25 additions & 0 deletions templates/toml/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use `builtins.getFlake` if available
if builtins ? getFlake
then
let
scheme =
if builtins.pathExists ./.git
then "git+file"
else "path";
in
(builtins.getFlake "${scheme}://${toString ./.}")
.devShell
.${builtins.currentSystem}

# Otherwise we'll use the flake-compat shim
else
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).shellNix

0 comments on commit f26c2e0

Please sign in to comment.