Skip to content

Commit

Permalink
docs(readme): Document pre-flake usage
Browse files Browse the repository at this point in the history
  • Loading branch information
PetarKirov committed Jan 28, 2024
1 parent a47c589 commit b9b7ef6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nixpkgs> {}}: 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

Expand Down
8 changes: 8 additions & 0 deletions templates/pre-flake-devshell/.envrc
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions templates/pre-flake-devshell/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{pkgs ? import <nixpkgs> {}}: 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!"
'';
}

0 comments on commit b9b7ef6

Please sign in to comment.