Skip to content

Commit

Permalink
Getting started example project (#274)
Browse files Browse the repository at this point in the history
* fix `nix develop` shell in template

#272

* template example from "Getting Started" documentation

A working example project put together from https://numtide.github.io/devshell/getting_started.html
  • Loading branch information
peterbecich authored Sep 16, 2023
1 parent f6aec2e commit 6b52efc
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
/dist

# direnv
/.direnv
/.direnv
2 changes: 2 additions & 0 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ cd project/
nix develop # or `direnv allow` if you want to use direnv
```

Find `templates/gettingStartedExample` in this repository for a working example of the additional configuration below: `env`, `packages`, and `serviceGroups`.

## Adding environment variables

Environment variables that are specific to the project can be added with the
Expand Down
113 changes: 113 additions & 0 deletions templates/flake-parts/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions templates/gettingStartedExample/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# ^ added for shellcheck and file-type detection

# Watch & reload direnv on change
watch_file devshell.toml

if [[ $(type -t use_flake) != function ]]; then
echo "ERROR: use_flake function missing."
echo "Please update direnv to v2.30.0 or later."
exit 1
fi
use flake
3 changes: 3 additions & 0 deletions templates/gettingStartedExample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.direnv/
/pgdata/*
/.data/
39 changes: 39 additions & 0 deletions templates/gettingStartedExample/devshell.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# https://numtide.github.io/devshell
# https://numtide.github.io/devshell/getting_started.html
[[commands]]
package = "hello"

[[commands]]
package = "go"

[[commands]]
package = "nodejs_20"

[[commands]]
package = "python311"

[[env]]
name = "GO111MODULE"
value = "on"

[devshell]
packages = [
"postgresql_15",
"memcached",
]

[[commands]]
name = "initPostgres"
help = "Initialize the Postgres database"
command = """\
initdb pgdata; \
chmod -R 700 pgdata; \
echo -e "Use the devshell command 'database:start'"
"""

[serviceGroups.database]
description = "Runs a database in the background"
[serviceGroups.database.services.postgres]
command = "postgres -D ./pgdata"
[serviceGroups.database.services.memcached]
command = "memcached"
110 changes: 110 additions & 0 deletions templates/gettingStartedExample/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions templates/gettingStartedExample/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
description = "getting started example";

inputs.devshell.url = "github:numtide/devshell";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, flake-utils, devshell, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system: {
devShell =
let
pkgs = import nixpkgs {
inherit system;

overlays = [ devshell.overlays.default ];
};
in
pkgs.devshell.mkShell {
imports = [ (pkgs.devshell.importTOML ./devshell.toml) ];
};
});
}
10 changes: 10 additions & 0 deletions templates/gettingStartedExample/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

[Getting Started](https://numtide.github.io/devshell/getting_started.html)

This example will run Postgres and Memcached natively on your machine.

You may have to be a member of the `postgres` group to allow Postgres to start. Otherwise, Postgres may be unable to create its lockfile.

First create the Postgres database with the devshell command `initPostgres`. This is defined in the TOML. It uses Postgres command `initdb`.

Then the devshell command `database:start`.
Loading

0 comments on commit 6b52efc

Please sign in to comment.