Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting started example project #274

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.
2 changes: 1 addition & 1 deletion templates/toml/devshell.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# https://numtide.github.io/devshell
[[commands]]
package = "devshell.hello"
package = "hello"
Loading