From 217094dd42b9af5189311387aa1dbc80cf4c3a37 Mon Sep 17 00:00:00 2001 From: Peter Becich Date: Sat, 2 Sep 2023 16:49:29 -0700 Subject: [PATCH] template example from "Getting Started" documentation A working example project put together from https://numtide.github.io/devshell/getting_started.html --- .gitignore | 2 +- docs/getting_started.md | 2 + templates/flake-parts/flake.lock | 113 ++++++++++++++++++ templates/gettingStartedExample/.envrc | 12 ++ templates/gettingStartedExample/.gitignore | 3 + templates/gettingStartedExample/devshell.toml | 39 ++++++ templates/gettingStartedExample/flake.lock | 110 +++++++++++++++++ templates/gettingStartedExample/flake.nix | 21 ++++ templates/gettingStartedExample/readme.md | 10 ++ templates/toml/flake.lock | 110 +++++++++++++++++ 10 files changed, 421 insertions(+), 1 deletion(-) create mode 100644 templates/flake-parts/flake.lock create mode 100644 templates/gettingStartedExample/.envrc create mode 100644 templates/gettingStartedExample/.gitignore create mode 100644 templates/gettingStartedExample/devshell.toml create mode 100644 templates/gettingStartedExample/flake.lock create mode 100644 templates/gettingStartedExample/flake.nix create mode 100644 templates/gettingStartedExample/readme.md create mode 100644 templates/toml/flake.lock diff --git a/.gitignore b/.gitignore index e93a75f8..0f5bce7a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ /dist # direnv -/.direnv \ No newline at end of file +/.direnv diff --git a/docs/getting_started.md b/docs/getting_started.md index 1820f24a..df31b0d7 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -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 diff --git a/templates/flake-parts/flake.lock b/templates/flake-parts/flake.lock new file mode 100644 index 00000000..ba80534c --- /dev/null +++ b/templates/flake-parts/flake.lock @@ -0,0 +1,113 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + }, + "locked": { + "lastModified": 1692793255, + "narHash": "sha256-yVyj0AE280JkccDHuG1XO9oGxN6bW8ksr/xttXcXzK0=", + "owner": "numtide", + "repo": "devshell", + "rev": "2aa26972b951bc05c3632d4e5ae683cb6771a7c6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1693611461, + "narHash": "sha256-aPODl8vAgGQ0ZYFIRisxYG5MOGSkIczvu2Cd8Gb9+1Y=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "7f53fdb7bdc5bb237da7fefef12d099e4fd611ca", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1677383253, + "narHash": "sha256-UfpzWfSxkfXHnb4boXZNaKsAcUrZT9Hw+tao1oZxd08=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9952d6bc395f5841262b006fbace8dd7e143b634", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1693471703, + "narHash": "sha256-0l03ZBL8P1P6z8MaSDS/MvuU8E75rVxe5eE1N6gxeTo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3e52e76b70d5508f3cec70b882a29199f4d1ee85", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1693626178, + "narHash": "sha256-Rpiy6lIOu4zny8tfGuIeN1ji9eSz9nPmm9yBhh/4IOM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bfb7dfec93f3b5d7274db109f2990bc889861caf", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/gettingStartedExample/.envrc b/templates/gettingStartedExample/.envrc new file mode 100644 index 00000000..31ca1731 --- /dev/null +++ b/templates/gettingStartedExample/.envrc @@ -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 \ No newline at end of file diff --git a/templates/gettingStartedExample/.gitignore b/templates/gettingStartedExample/.gitignore new file mode 100644 index 00000000..5066b0a1 --- /dev/null +++ b/templates/gettingStartedExample/.gitignore @@ -0,0 +1,3 @@ +/.direnv/ +/pgdata/* +/.data/ diff --git a/templates/gettingStartedExample/devshell.toml b/templates/gettingStartedExample/devshell.toml new file mode 100644 index 00000000..c0bc41ed --- /dev/null +++ b/templates/gettingStartedExample/devshell.toml @@ -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 backgroup" +[serviceGroups.database.services.postgres] +command = "postgres -D ./pgdata" +[serviceGroups.database.services.memcached] +command = "memcached" diff --git a/templates/gettingStartedExample/flake.lock b/templates/gettingStartedExample/flake.lock new file mode 100644 index 00000000..21011f3a --- /dev/null +++ b/templates/gettingStartedExample/flake.lock @@ -0,0 +1,110 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + }, + "locked": { + "lastModified": 1692793255, + "narHash": "sha256-yVyj0AE280JkccDHuG1XO9oGxN6bW8ksr/xttXcXzK0=", + "owner": "numtide", + "repo": "devshell", + "rev": "2aa26972b951bc05c3632d4e5ae683cb6771a7c6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1677383253, + "narHash": "sha256-UfpzWfSxkfXHnb4boXZNaKsAcUrZT9Hw+tao1oZxd08=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9952d6bc395f5841262b006fbace8dd7e143b634", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1693563790, + "narHash": "sha256-qUx+8lQSCiPXbwWBwRHynHuhQT+6I7kEuDFFNQ6RSPU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fd8ad63083882605e8a7f659be6c9509e6e28d28", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/gettingStartedExample/flake.nix b/templates/gettingStartedExample/flake.nix new file mode 100644 index 00000000..421d1412 --- /dev/null +++ b/templates/gettingStartedExample/flake.nix @@ -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) ]; + }; + }); +} diff --git a/templates/gettingStartedExample/readme.md b/templates/gettingStartedExample/readme.md new file mode 100644 index 00000000..2db9a94b --- /dev/null +++ b/templates/gettingStartedExample/readme.md @@ -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`. diff --git a/templates/toml/flake.lock b/templates/toml/flake.lock new file mode 100644 index 00000000..21011f3a --- /dev/null +++ b/templates/toml/flake.lock @@ -0,0 +1,110 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + }, + "locked": { + "lastModified": 1692793255, + "narHash": "sha256-yVyj0AE280JkccDHuG1XO9oGxN6bW8ksr/xttXcXzK0=", + "owner": "numtide", + "repo": "devshell", + "rev": "2aa26972b951bc05c3632d4e5ae683cb6771a7c6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1677383253, + "narHash": "sha256-UfpzWfSxkfXHnb4boXZNaKsAcUrZT9Hw+tao1oZxd08=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9952d6bc395f5841262b006fbace8dd7e143b634", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1693563790, + "narHash": "sha256-qUx+8lQSCiPXbwWBwRHynHuhQT+6I7kEuDFFNQ6RSPU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fd8ad63083882605e8a7f659be6c9509e6e28d28", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +}