Skip to content

Add a nix flake - #26

Open
pcasaretto wants to merge 3 commits into
tobi:mainfrom
pcasaretto:nix-flake
Open

pcasaretto wants to merge 3 commits into
tobi:mainfrom
pcasaretto:nix-flake

Conversation

@pcasaretto

@pcasaretto pcasaretto commented Sep 25, 2026 •

Copy link
Copy Markdown

Summary

Add flake.nix and flake.lock so Nix can build and run disktree without manual setup of Rust or native dependencies.

  • Provide default and named disktree packages for aarch64-darwin, aarch64-linux, and x86_64-linux.
  • Pin nixpkgs through flake.lock and use the existing Cargo.lock for Rust dependencies.
  • Include Linux runtime library paths, the desktop entry, and the application icon.

Usage

From the checkout:

nix build .#disktree
nix run .#disktree

The build produces result/bin/disktree.

Testing

  • nix flake check --no-build --all-systems: evaluation passes for all three systems.
  • nix build .#disktree: build and core tests pass on aarch64-darwin.
  • ./result/bin/disktree --help: prints usage.

The Nix check phase excludes two macOS tests that depend on the host environment and the app test suite. Linux checks cover evaluation only, not builds or runtime behavior.

pcasaretto and others added 2 commits September 25, 2026 17:11
Build the disktree binary with buildRustPackage from the existing
Cargo.lock. Linux gets a RUNPATH for the GPU libraries GPUI dlopens at
runtime plus a desktop entry and icon; darwin needs only the bindgen
hook. Tests outside the sandbox skip the three host-reading cases.
A Nix-built vulkan-loader looks for its ICD manifests under
/run/opengl-driver/share/vulkan/icd.d, a path that only NixOS creates, so
on any other distribution the loader found no drivers at all, wgpu came up
with no enabled backend, and the app died in create_surface with "Failed to
create surface for any enabled backend: {}" before a window was shown. The
host's own Mesa cannot fill the gap — its ICD names the vendor library
relatively and Nix's glibc does not read /etc/ld.so.cache, while forcing
the issue with LD_LIBRARY_PATH shadows glibc itself and breaks the process
— so the driver has to come from the closure.

- postFixup now runs addDriverRunpath on the binary, keeping NixOS and
  proprietary-NVIDIA hosts working through /run/opengl-driver/lib
- postFixup wraps the binary so this closure's Mesa is offered as an
  additional driver source: VK_ADD_DRIVER_FILES for Vulkan,
  __EGL_VENDOR_LIBRARY_DIRS and LIBGL_DRIVERS_PATH for GL, all suffixed so
  a driver the loader discovers for itself still wins
- addDriverRunpath and makeWrapper join nativeBuildInputs under the
  existing isLinux guard
- the comment above postFixup explains driver discovery, not just the
  dlopened loaders, and records that NVIDIA's proprietary stack still
  needs nixGL
…gl-driver

Find a GPU driver on hosts without /run/opengl-driver
@levonk

levonk commented Sep 28, 2026

Copy link
Copy Markdown

Nice flake — the fileset scoping, version-from-Cargo.toml, and the Mesa
driver wrapping for non-NixOS hosts are all the right shape. A few findings
from exercising it:

x86_64-darwin is a supported platform here. The systems comment says
"if Intel Macs ever matter", but this repo ships x86_64-macos.zip release
assets and runs macos-15-intel in the other-architectures CI matrix. On an
Intel Mac today:

$ nix build .#disktree
error: flake 'github:tobi/disktree/...' does not provide attribute
'packages.x86_64-darwin.disktree', 'legacyPackages.x86_64-darwin.disktree'
or 'disktree'

nixpkgs-unstable dropped x86_64-darwin in 26.11, but the
nixpkgs-26.05-darwin branch still supports it. A second input pinned there,
selected only for x86_64-darwin, adds the platform without touching the
other three.

meta.platforms and systems disagree. platforms.linux ++ platforms.darwin
advertises x86_64-darwin while systems excludes it — whichever way the
above lands, these should match.

The branch is stale and carries a merge commit. It evaluates to
disktree-0.10.0 but main is at 0.10.1; a rebase onto main would also flatten
the Merge pull request #1 commit.

Nothing guards the flake against nixpkgs drift. A small path-filtered
workflow (nix flake check --all-systems --no-build + nix build) would
catch a broken nixpkgs-unstable bump before users do.

The Linux build is untested (per the PR body). The dep set looks right
against GPUI's actual linkage — CI's apt list (alsa/openssl/zstd) has no
matching crates in Cargo.lock — but two things only show up on a real
Linux build: doCheck runs the full disktree-core suite there (both skipped
tests are #[cfg(target_os = "macos")], so nothing is skipped on Linux), and
the loader wrapping only proves itself on a running system.

Minor: nix run/nix profile add work via the packages fallback plus
mainProgram, but explicit apps.<system>.{default,disktree} outputs are
conventional. And the flake floats on nixpkgs' rustc while CI deliberately
pins 1.97 — harmless for building (lints don't run in the derivation), just
worth knowing.

Verified locally: nix flake check --all-systems --no-build passes clean on
all three systems.

fzakaria added a commit to fzakaria/nix-home that referenced this pull request Sep 30, 2026
disktree (https://github.com/tobi/disktree) is not in nixpkgs yet.
Package it locally in nixpkgs style, adapted from the flake proposed
upstream in tobi/disktree#26, so it can be dropped or upstreamed
later. It builds from the unstable set because upstream requires
rust >= 1.97 and nixos-25.11 ships 1.91.

pkgs/default.nix took a bare pkgs argument while flake.nix passes
{pkgs, inputs}, which only worked because the file was empty. Take
{pkgs, ...} and have the additions overlay pass the same shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants