Skip to content

Commit b1546d7

Browse files
authored
Merge pull request #761 from ForgeRock/add-flake
chore: add-nix-flake
2 parents 30563dd + e35d421 commit b1546d7

10 files changed

Lines changed: 277 additions & 20 deletions

File tree

‎.envrc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use flake
2+
eval "$(devenv direnvrc)"
3+
use devenv

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# OS files
22
.DS_Store
3+
.devenv/*
34
*/DS_Store
45
**/*.DS_Store
56
.pnpm-store/*

‎contributing_docs/README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
- [Module Types](./creating-a-package.md#optional-prompts)
1515
- [Publishing Considerations](./creating-a-package.md#notes)
1616

17+
### Environment Setup
18+
19+
- [Nix Environment](./nix-environment.md#nix-environment)
20+
- [What the flake provides](./nix-environment.md#what-the-flake-provides)
21+
- [What devenv adds on top](./nix-environment.md#what-devenv-adds-on-top)
22+
- [Troubleshooting](./nix-environment.md#troubleshooting)
23+
1724
### Version Control
1825

1926
- [Git Workflow](./git.md#git)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Nix Environment
2+
3+
This repository provides a reproducible development environment using [Nix](https://nixos.org/), with [direnv](https://direnv.net/) for automatic activation and [devenv](https://devenv.sh/) as a convenience layer on top.
4+
5+
## Prerequisites
6+
7+
- [Nix](https://nixos.org/download.html) with flakes enabled
8+
- [direnv](https://direnv.net/docs/installation.html) (and its shell hook installed)
9+
- Optionally, [devenv](https://devenv.sh/getting-started/) for the extras described below
10+
11+
## What the flake provides
12+
13+
The base environment is defined in `flake.nix` at the repository root. Entering the shell (`nix develop`, or automatically via direnv) gives you:
14+
15+
- `nodejs_24` and `pnpm_10` pinned from nixpkgs, so every contributor uses the same toolchain versions
16+
- `git`, plus `nixpkgs-fmt` and `nil` for editing Nix files themselves
17+
- Playwright browsers wired up automatically: `PLAYWRIGHT_BROWSERS_PATH` points at the nix-provided browser set and `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` is set, so e2e tests run without downloading browsers
18+
- A `packages/playwright-browsers` output you can build or reference directly if you need the browser bundle standalone
19+
- A formatter available as `nix fmt` (runs `nixpkgs-fmt` over the Nix files)
20+
21+
## What devenv adds on top
22+
23+
`devenv.nix` layers convenience on top of the base shell:
24+
25+
- **Cachix** (`ping-javascript-sdk`): artifacts are pulled from the binary cache so first installs are much faster, and pushed back so what you build is shared with the rest of the team
26+
- **`env.NX_SOCKET_DIR = "/tmp/nx"`**: fixes a macOS issue where the Nx daemon's Unix socket path exceeds the socket length limit because pnpm's deeply nested `node_modules` paths make the socket file path too long. Setting this redirects the socket to a short path.
27+
28+
## How they compose
29+
30+
The `.envrc` at the root wires everything together:
31+
32+
```bash
33+
use flake
34+
eval "$(devenv direnvrc)"
35+
use devenv
36+
```
37+
38+
`use flake` provides the base environment from nixpkgs (the flake); `use devenv` layers devenv's project services, env vars, and caching on top. In short: **flake = the base toolchain and environment; devenv = the convenience layer**. You need both files for the full experience, but the flake alone is enough if you only want the toolchain.
39+
40+
Once direnv is hooked into your shell, `cd`-ing into the repository activates everything automatically.
41+
42+
## Troubleshooting
43+
44+
### Nx socket errors on macOS
45+
46+
If you see errors about the Nx daemon failing to bind a Unix socket (path too long), the `NX_SOCKET_DIR` env var from `devenv.nix` fixes this. If you skipped devenv, set it manually:
47+
48+
```bash
49+
export NX_SOCKET_DIR=/tmp/nx
50+
```
51+
52+
## Note on `.devenv/`
53+
54+
The `.devenv/` directory is generated runtime state, gitignored, and recreated automatically the next time the environment is activated. Never commit it or edit files inside it.

‎devenv.lock‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"nodes": {
3+
"devenv": {
4+
"locked": {
5+
"dir": "src/modules",
6+
"lastModified": 1788213407,
7+
"narHash": "sha256-zxEb+L6moGAWY+HXqAOTKIBb7tNYYWc+Km1+6byphb0=",
8+
"owner": "cachix",
9+
"repo": "devenv",
10+
"rev": "97135e80b6e432f41f84f72383e1b8147f33ef0c",
11+
"type": "github"
12+
},
13+
"original": {
14+
"dir": "src/modules",
15+
"owner": "cachix",
16+
"repo": "devenv",
17+
"type": "github"
18+
}
19+
},
20+
"nixpkgs": {
21+
"inputs": {
22+
"nixpkgs-src": "nixpkgs-src"
23+
},
24+
"locked": {
25+
"lastModified": 1787753358,
26+
"narHash": "sha256-Tl77VbWyAKrOfRNQhL6JbQtb/MLzbYa/1RG1gWWfICk=",
27+
"owner": "cachix",
28+
"repo": "devenv-nixpkgs",
29+
"rev": "256551e45f6303e142ab4a98be1bf243feb77dc0",
30+
"type": "github"
31+
},
32+
"original": {
33+
"owner": "cachix",
34+
"ref": "rolling",
35+
"repo": "devenv-nixpkgs",
36+
"type": "github"
37+
}
38+
},
39+
"nixpkgs-src": {
40+
"flake": false,
41+
"locked": {
42+
"lastModified": 1787394516,
43+
"narHash": "sha256-pRGOQSClnXNI2iLUG6DYpsGvYcuw0drOutVZFTJNw90=",
44+
"owner": "NixOS",
45+
"repo": "nixpkgs",
46+
"rev": "c8f90650c15282fa8656a041bfbbd2403997a9a7",
47+
"type": "github"
48+
},
49+
"original": {
50+
"owner": "NixOS",
51+
"ref": "nixpkgs-unstable",
52+
"repo": "nixpkgs",
53+
"type": "github"
54+
}
55+
},
56+
"root": {
57+
"inputs": {
58+
"devenv": "devenv",
59+
"nixpkgs": "nixpkgs"
60+
}
61+
}
62+
},
63+
"root": "root",
64+
"version": 7
65+
}

‎devenv.nix‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
cachix.pull = [ "ping-javascript-sdk" ];
3+
cachix.push = "ping-javascript-sdk";
4+
5+
env.NX_SOCKET_DIR = "/tmp/nx";
6+
}

‎flake.lock‎

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
description = "development environment for ping-sdk repository";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
nixpkgs-darwin.url = "github:NixOS/nixpkgs/nixpkgs-26.05-darwin";
7+
};
8+
9+
outputs =
10+
{ self, nixpkgs, nixpkgs-darwin }:
11+
let
12+
systems = [
13+
"x86_64-linux"
14+
"aarch64-linux"
15+
"aarch64-darwin"
16+
"x86_64-darwin"
17+
];
18+
forAllSystems = nixpkgs.lib.genAttrs systems;
19+
20+
pkgsFor =
21+
system:
22+
let
23+
nixpkgsInput =
24+
if nixpkgs.lib.hasSuffix "darwin" system then nixpkgs-darwin else nixpkgs;
25+
in
26+
import nixpkgsInput { inherit system; };
27+
in
28+
{
29+
devShells = forAllSystems (
30+
system:
31+
let
32+
pkgs = pkgsFor system;
33+
playwrightBrowsers = pkgs.playwright-driver.browsers;
34+
in
35+
{
36+
default = pkgs.mkShell {
37+
buildInputs = with pkgs; [
38+
nodejs_24
39+
# package.json pins pnpm@10.21.0; nixpkgs provides 10.34.5 (latest pnpm_10)
40+
pkgs.pnpm_10
41+
git
42+
nixpkgs-fmt
43+
nil
44+
];
45+
46+
env = {
47+
PLAYWRIGHT_BROWSERS_PATH = "${playwrightBrowsers}";
48+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1";
49+
};
50+
51+
shellHook = ''
52+
echo "──────────────────────────────────────"
53+
echo " ping-sdk dev environment"
54+
echo " node $(node --version)"
55+
echo " pnpm $(pnpm --version)"
56+
echo " git $(git --version | cut -d' ' -f3)"
57+
echo " playwright browsers: $PLAYWRIGHT_BROWSERS_PATH"
58+
echo "──────────────────────────────────────"
59+
'';
60+
};
61+
}
62+
);
63+
64+
packages = forAllSystems (
65+
system:
66+
let
67+
pkgs = pkgsFor system;
68+
in
69+
{
70+
default = self.devShells.${system}.default;
71+
playwright-browsers = pkgs.playwright-driver.browsers;
72+
}
73+
);
74+
75+
formatter = forAllSystems (system: (pkgsFor system).nixpkgs-fmt);
76+
};
77+
}

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@
135135
"rollup": "^4.59.0",
136136
"picomatch@>=4": "^4.0.4",
137137
"picomatch@<3": "^2.3.2",
138-
"fast-uri": "^3.1.4",
139-
"qs": "^6.15.3",
138+
"fast-uri": "^3.1.6",
139+
"qs": "^6.16.0",
140140
"@opentelemetry/core": "^2.8.0",
141141
"brace-expansion@<2": "~1.1.15",
142142
"brace-expansion@>=2 <3": "~2.1.1",

0 commit comments

Comments
 (0)