Repository navigation
Integrate dream2nix outputs into main flake #234
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
Changes from 4 commits
bd0464a
639b27e
13421f2
917d9df
93c2e71
c19cc60
84c33fb
5a63fa4
3b5a80c
e1aee09
dc701f7
7ab43d2
adfcb32
ba8d9b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Nix + dream2nix setup | ||
|
|
||
| This repo can build and expose all CLI tools declared in `package.json` using the exact versions from the lockfile, via [dream2nix]. | ||
|
|
||
| ## Prerequisites | ||
| - Nix installed | ||
| - Flakes enabled (see Nix docs) | ||
|
|
||
| ## Typical usage | ||
|
|
||
| Build the tools as a package: | ||
| ```bash | ||
| nix build .#node-tools | ||
| # The result symlink contains bin/ with your CLI tools | ||
| ls -l result/bin | ||
| ``` | ||
|
|
||
| Open a dev shell with Node and tools on PATH: | ||
|
|
||
| ```bash | ||
| nix develop | ||
| # then run your tools, e.g. | ||
| tsc --version | ||
| prettier --version | ||
| eslint_d --version | ||
| ``` | ||
|
|
||
| Use in Home Manager (example): | ||
|
|
||
| ```nix | ||
| { pkgs, ... }: | ||
| { | ||
| home.packages = [ | ||
| (builtins.getFlake ".").packages.${builtins.currentSystem}.node-tools | ||
| ]; | ||
| } | ||
| ``` | ||
|
Comment on lines
+30
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Home Manager example uses I recommend updating the example to demonstrate this more common and robust pattern. For example: "To use these packages in your Home Manager configuration, first add this repository as an input to your # flake.nix
inputs.my-tools = {
url = "github:shunkakinoki/dotfiles"; # Or the path to this repo
};Then, you can add the package to # home-manager.nix
{ pkgs, inputs, ... }:
{
home.packages = [
inputs.my-tools.packages.${pkgs.system}.node-tools
];
}
```" |
||
|
|
||
| ## Notes | ||
|
|
||
| * Versions are pinned by the lockfile (`package-lock.json`, `yarn.lock`, or `pnpm-lock.yaml`). | ||
| * If you change dependencies, update the lockfile, then rebuild. | ||
| * If your package has native deps, dream2nix will build them; ensure required system libs are available in nixpkgs. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| * **Missing lockfile**: generate one (`npm i`, `pnpm i`, or `yarn install`) before running `nix build`. | ||
|
shunkakinoki marked this conversation as resolved.
Resolved
|
||
| * **Postinstall script fails**: check logs from `nix build`; you may need to add system libraries or patch scripts. | ||
| * **Bins missing**: ensure the dependency actually exposes a `bin` entry in its `package.json`. | ||
|
|
||
| [dream2nix]: https://github.com/nix-community/dream2nix | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,10 @@ | |||||||||||||
| url = "github:numtide/treefmt-nix"; | ||||||||||||||
| inputs.nixpkgs.follows = "nixpkgs"; | ||||||||||||||
| }; | ||||||||||||||
| dream2nix = { | ||||||||||||||
| url = "github:nix-community/dream2nix"; | ||||||||||||||
| inputs.nixpkgs.follows = "nixpkgs"; | ||||||||||||||
| }; | ||||||||||||||
| agenix = { | ||||||||||||||
| url = "github:ryantm/agenix"; | ||||||||||||||
| inputs.nixpkgs.follows = "nixpkgs"; | ||||||||||||||
|
|
@@ -124,7 +128,18 @@ | |||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| perSystem = | ||||||||||||||
| { ... }: | ||||||||||||||
| { system, pkgs, ... }: | ||||||||||||||
| let | ||||||||||||||
| # Build the workspace's Node tools using dream2nix. This reads package.json + | ||||||||||||||
| # lockfile from the repo root and exposes any dependency bins. | ||||||||||||||
| dream2nixOutputs = inputs.dream2nix.lib.makeFlakeOutputs { | ||||||||||||||
| systems = [ system ]; | ||||||||||||||
| config.projectRoot = ./.; | ||||||||||||||
| source = ./.; | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a couple of improvements to be made here:
I suggest removing the
|
||||||||||||||
| source = ./.; | |
| source = ./.; | |
| # Intentionally left empty for future package customizations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Guard dream2nix integration against missing Node project
The new per-system block unconditionally calls inputs.dream2nix.lib.makeFlakeOutputs expecting a package.json and lockfile in the repository root, then exposes the result as nodeTools. The repository currently contains no package.json or lock file (see find . -name package.json … returning nothing), so evaluating the flake now fails before any other output can be used. This breaks all nix flake commands for users who do not have a Node workspace checked in. Please gate this call or default it to a no-op when no Node project is present so the flake remains evaluable.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For creating development shells that don't require a C/C++ compiler toolchain, it's better to use pkgs.mkShellNoCC instead of pkgs.mkShell. mkShell adds the standard environment (stdenv), which includes many build-time dependencies like GCC. mkShellNoCC creates a more lightweight shell, which is sufficient here since you are only adding Node.js and related tools to the PATH.
devShells.default = pkgs.mkShellNoCC {
Copilot
AI
Sep 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using || true to suppress command failures can hide legitimate errors. Consider using a more explicit error handling approach or checking if corepack is available before enabling it.
| corepack enable || true | |
| if command -v corepack >/dev/null 2>&1; then | |
| corepack enable | |
| else | |
| echo "Warning: 'corepack' not found. Yarn/PNPM version management may not work as expected." | |
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
builtins.getFlakewith a relative path in Home Manager configuration is not recommended as it creates impure evaluations. Consider using a proper flake input or absolute path reference instead.