Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
145 changes: 145 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,150 @@ tags
# Ignore
result
ref

.direnv/
.env

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.*
!.env.example

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist
.output

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Sveltekit cache directory
.svelte-kit/

# vitepress build output
**/.vitepress/dist

# vitepress cache directory
**/.vitepress/cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# Firebase cache directory
.firebase/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v3
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Vite files
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
.vite/
.env
.env.local
52 changes: 52 additions & 0 deletions README-nix.md
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

Copilot AI Sep 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using builtins.getFlake with 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.

Suggested change
(builtins.getFlake ".").packages.${builtins.currentSystem}.node-tools
inputs.nodeToolsFlake.packages.${pkgs.system}.node-tools

Copilot uses AI. Check for mistakes.
];
}
```
Comment on lines +30 to +37

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Home Manager example uses (builtins.getFlake "."), which relies on the current working directory. This is not a robust pattern for consuming flakes. A more idiomatic approach is to add the flake as an input to the user's configuration.

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:

# flake.nix
inputs.my-tools = {
  url = "github:shunkakinoki/dotfiles"; # Or the path to this repo
};

Then, you can add the package to home.packages in your Home Manager module:

# 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`.
Comment thread
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

105 changes: 105 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 = ./.;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are a couple of improvements to be made here:

  1. The config.projectRoot argument is not a valid top-level argument for makeFlakeOutputs in this form. projectRoot is a direct argument to the function, but it's not necessary here as it defaults to the source value.
  2. Using source = ./.; includes the entire project directory in the Nix store, including files that are not needed for the build (e.g., .git directory). It's a best practice to filter the source to only include necessary files. You can use pkgs.lib.cleanSource for this, which by default filters out common version control files.

I suggest removing the config.projectRoot line and using pkgs.lib.cleanSource for the source.

            source = pkgs.lib.cleanSource ./.;

Copilot AI Oct 3, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty packageOverrides object should be removed or documented if intentionally left for future customization.

Suggested change
source = ./.;
source = ./.;
# Intentionally left empty for future package customizations.

Copilot uses AI. Check for mistakes.
packageOverrides = { };
};
nodeTools = dream2nixOutputs.packages.${system}.default;

Copy link
Copy Markdown

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 👍 / 👎.

in
{
treefmt = {
projectRootFile = "flake.nix";
Expand All @@ -139,6 +154,23 @@
yamlfmt.enable = true;
};
};

packages = {
node-tools = nodeTools;
default = nodeTools;
};

devShells.default = pkgs.mkShell {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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 {

packages = [
pkgs.nodejs_20
nodeTools
];
shellHook = ''
# Enable Corepack so Yarn/PNPM versions follow packageManager field
corepack enable || true

Copilot AI Sep 26, 2025

Copy link

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
echo "Dev shell ready: Node + tools from package.json/lockfile are on PATH."
'';
};
};
};
}
Loading