Skip to content

Commit 2818b54

Browse files
authored
Go Mod Example + Doc Links (#1017)
## Summary * Add a Go Mod Flake Example * Add links back to our docs for some key examples ## How was it tested? Markdown Only
1 parent 684a933 commit 2818b54

File tree

16 files changed

+223
-10
lines changed

16 files changed

+223
-10
lines changed

examples/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Example dev environments built with Devbox:
66

77
1. `databases` - Examples of popular DBs (eg.,MariaDB, Postgres, Redis)
8-
2. `development` - Shells for developing in different programming languages
9-
2. `stacks` - Full projects and web stacks, like LAMP and Drupal
10-
3. `servers` - Examples of servers, like Apache + Nginx
8+
1. `development` - Shells for developing in different programming languages
9+
1. `flakes` - Examples of using Nix Flakes with Devbox
10+
1. `servers` - Examples of servers, like Apache + Nginx
11+
1. `stacks` - Full projects and web stacks, like LAMP and Drupal
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Haskell
22

3-
This example was generated using `stack`. To generate a similar example, you can copy the devbox json and run `devbox shell`.
3+
This example was generated using `stack`. To generate a similar example, you can copy the devbox json and run `devbox shell`.
44

5-
Once your shell has activated, run:
5+
Once your shell has activated, run:
66

77
```
88
stack new my-project
99
cd my-project
1010
stack build
1111
stack exec my-project-exe
1212
```
13+
14+
For more details, check out the [Haskell + Devbox Docs](https://www.jetpack.io/devbox/docs/devbox_examples/languages/haskell/)

examples/development/ruby/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ruby
2+
3+
Basic Ruby "Hello World" example. For more details on how Ruby + Devbox works, check out our [docs page](https://www.jetpack.io/devbox/docs/devbox_examples/languages/ruby/).
4+
5+
## Related Docs
6+
7+
* [Rails + Devbox](https://www.jetpack.io/devbox/docs/devbox_examples/stacks/rails/)
8+
* [Jekyll + Devbox](https://www.jetpack.io/devbox/docs/devbox_examples/stacks/jekyll/)

examples/flakes/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Flakes
22

3-
Examples that show how to add custom flakes to your devbox project.
3+
Examples that show how to add custom flakes to your Devbox project. These examples require [Devbox 0.4.7](https://www.jetpack.io/blog/devbox-0-4-7/) or later.
4+
5+
For more details, you can also consult our Docs page on [using flakes](https://www.jetpack.io/devbox/docs/guides/using_flakes/)
46

57
## Local flakes (usually committed to your project)
68

examples/flakes/go-mod/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ory-cli/result/*

examples/flakes/go-mod/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Building a Go Module with Flakes
2+
3+
This flake shows how to build a custom Go module and add it to your Devbox project. In this case, we're building the [Ory CLI](https://github.com/ory/cli)
4+
5+
This example uses `buildGoModule` from Nix to build the module as a package in our Flake. You can view the flake.nix file in the ory-cli folder to see a commented example of how this function is used.
6+
7+
We import the ory CLI in our project by adding it to our packages in `devbox.json`:
8+
9+
```json
10+
{
11+
"packages": [
12+
"path:ory-cli"
13+
],
14+
...
15+
}
16+
```
17+
18+
Note: you will need [Devbox 0.4.7](https://www.jetpack.io/blog/devbox-0-4-7/) or later for this to work. You can use this as an example to create your own templates.
19+
20+
For more details on using Flakes with Devbox, read our post on [Using Nix Flakes with Devbox](https://www.jetpack.io/blog/using-nix-flakes-with-devbox/)

examples/flakes/go-mod/devbox.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"packages": [
3+
"path:ory-cli"
4+
],
5+
"shell": {
6+
"init_hook": null
7+
},
8+
"nixpkgs": {
9+
"commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
10+
}
11+
}

examples/flakes/go-mod/devbox.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"lockfile_version": "1",
3+
"packages": {}
4+
}

examples/flakes/go-mod/ory-cli/flake.lock

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
description =
3+
"This flake builds the Ory CLI using Nix's buildGoModule Function.";
4+
5+
inputs = {
6+
nixpkgs.url = "nixpkgs/nixos-unstable";
7+
flake-utils.url = "github:numtide/flake-utils";
8+
# The Ory CLI is not a flake, so we have to use the Github input and build it ourselves.
9+
ory-cli = {
10+
type = "github";
11+
owner = "ory";
12+
repo = "cli";
13+
ref = "v0.2.2";
14+
flake = false;
15+
};
16+
};
17+
18+
outputs = { self, nixpkgs, flake-utils, ory-cli }:
19+
# Use the flake-utils lib to easily create a multi-system flake
20+
flake-utils.lib.eachDefaultSystem (system:
21+
let
22+
# Define some variables that we want to use in our package build. You'll want to update version and `ref` above to use a different version of Ory.
23+
version = "0.2.2";
24+
in {
25+
packages = let
26+
pkgs = import nixpkgs{inherit system;};
27+
pname = "ory";
28+
name = "ory-${version}";
29+
in {
30+
# Build the Ory CLI using Nix's buildGoModuleFunction
31+
ory-cli = pkgs.buildGoModule {
32+
inherit version;
33+
inherit pname;
34+
inherit name;
35+
36+
# Path to the source code we want to build. In this case, it's the `ory-cli` input we defined above.
37+
src = ory-cli;
38+
39+
# This was in the Makefile in the Ory repo, not sure if it's required
40+
tags = [ "sqlite"];
41+
42+
doCheck = false;
43+
44+
# If the vendor folder is not checked in, we have to provide a hash for the vendor folder. Nix requires this to ensure the vendor folder is reproducible, and matches what we expect.
45+
vendorSha256 = "sha256-J9jyeLIT+1pFnHOUHrzmblVCJikvY05Sw9zMz5qaDOk=";
46+
47+
# The Go Mod is named `cli` by default, so we rename it to `ory`.
48+
postInstall = ''
49+
mv $out/bin/cli $out/bin/ory
50+
'';
51+
};
52+
};
53+
54+
# Set Ory as the default package output for this flake
55+
defaultPackage = self.packages.ory-cli;
56+
}
57+
);
58+
}
59+

0 commit comments

Comments
 (0)