diff --git a/README.md b/README.md index 5c60eb42..2c1079e3 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,41 @@ $ dub --version DUB version 1.30.0, built on Jan 1 1980 ``` -See complete example in [`templates/devshell/flake.nix`](./templates/devshell/flake.nix). +You can find the full example in [`templates/devshell/`](./templates/devshell/). + +### Pre-flakes usage + +The `default.nix` file in the root of this repo exposes all flake outputs as +Nix attributes. This is useful for users who haven't yet made the jump to the +Nix Flakes world. + +For example, if you have an existing `shell.nix` file, all you need to do is add +the changes marked as "NEW" from the snippet below: + +```nix +{pkgs ? import {}}: let + # NEW: Import the dlang-nix Nix library: + dlang-nix = import (pkgs.fetchFromGitHub { + owner = "PetarKirov"; + repo = "dlang.nix"; + rev = "3502a9f6dd2074c2f84d49baa5043f6601ca6407"; + hash = "sha256-djp8c2iONh+ET+wHbPLruNTuF7xSAYoMmwp1HfsrVTA="; + }); + + # NEW: Add `dpkgs` shorthand: + dpkgs = dlang-nix.packages."${pkgs.system}"; +in + pkgs.mkShell { + packages = [ + # NEW: Reference D-related packages from `dpkgs`: + dpkgs.dmd + dpkgs.dub + ]; + } +``` + +You can find the full example in +[`templates/pre-flake-devshell/`](./templates/pre-flake-devshell/). ## Source and binary variants diff --git a/templates/pre-flake-devshell/.envrc b/templates/pre-flake-devshell/.envrc new file mode 100644 index 00000000..87c33791 --- /dev/null +++ b/templates/pre-flake-devshell/.envrc @@ -0,0 +1,8 @@ +# shellcheck shell=bash +if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4=" +fi + +dotenv_if_exists +watch_file shell.nix +use nix diff --git a/templates/pre-flake-devshell/shell.nix b/templates/pre-flake-devshell/shell.nix new file mode 100644 index 00000000..cf6a8cc7 --- /dev/null +++ b/templates/pre-flake-devshell/shell.nix @@ -0,0 +1,21 @@ +{pkgs ? import {}}: let + dlang-nix = import (pkgs.fetchFromGitHub { + owner = "PetarKirov"; + repo = "dlang.nix"; + rev = "3502a9f6dd2074c2f84d49baa5043f6601ca6407"; + hash = "sha256-djp8c2iONh+ET+wHbPLruNTuF7xSAYoMmwp1HfsrVTA="; + }); + + dpkgs = dlang-nix.packages."${pkgs.system}"; +in + pkgs.mkShell { + packages = [ + pkgs.figlet + dpkgs.dmd + dpkgs.dub + ]; + + shellHook = '' + figlet "Hello, D world!" + ''; + }