guides
Consuming Weyl Standard
How to use weyl-std in your projects.
Consuming Weyl Standard
How to use weyl-std in your projects.
Quick Start
Add weyl-std to your flake inputs:
{ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; weyl-std.url = "github:weyl-ai/weyl-std"; };
outputs = inputs@{ flake-parts, weyl-std, ... }: flake-parts.lib.mkFlake { inherit inputs; } { imports = [ weyl-std.flakeModules.default ];
# weyl-std configuration weyl-std = { formatter.enable = true; devshell.enable = true; };
perSystem = { config, pkgs, ... }: let P = config.weyl.prelude; in { packages.default = P.stdenv.default { pname = "my-app"; version = "1.0"; src = ./.; }; }; };}Modules
Batteries Included
Import everything at once:
imports = [ weyl-std.flakeModules.default ];Includes: formatter, docs, nixpkgs config, overlays, devshell, prelude.
A La Carte
Pick what you need:
imports = [ weyl-std.flakeModules.formatter # treefmt-nix with opinionated defaults weyl-std.flakeModules.nixpkgs # nixpkgs config weyl-std.flakeModules.std # overlays (includes prelude + nvidia-sdk) weyl-std.flakeModules.prelude # prelude flake-module only weyl-std.flakeModules.devshell # Development shell weyl-std.flakeModules.docs # Documentation generation];The Weyl Prelude
Access the prelude via config.weyl.prelude:
perSystem = { config, ... }: let P = config.weyl.prelude; in { # Functional library example = P.map (x: x * 2) [ 1 2 3 ]; # [ 2 4 6 ]
# Stdenvs packages.my-app = P.stdenv.default { pname = "my-app"; version = "1.0"; src = ./.; };
# Language toolchains packages.py-app = P.python.app { pname = "py-app"; version = "1.0"; src = ./.; }; };Using Stdenvs
Basic Build
perSystem = { config, ... }: let P = config.weyl.prelude; in { packages.my-app = P.stdenv.default { pname = "my-app"; version = "1.0"; src = ./.; build-phase = '' $CXX -o app src/main.cpp install -D app $out/bin/app ''; }; };NVIDIA Build
packages.nvidia-kernel = P.stdenv.nvidia { pname = "nvidia-kernel"; version = "1.0"; src = ./.; build-phase = '' $CXX -o kernel src/kernel.cu install -D kernel $out/bin/kernel '';};Static Binary
packages.static-tool = P.stdenv.portable { pname = "static-tool"; version = "1.0"; src = ./.; # Result: single static binary, runs anywhere};Cross-Compilation
Build for ARM from x86_64:
packages.arm-binary = P.cross.aarch64 { name = "arm-app"; src = ./.;};
packages.grace-hopper = P.cross.grace { name = "grace-app"; src = ./.; # Targets aarch64 + Hopper GPU};Configuration Options
Devshell
weyl-std.devshell = { enable = true; nvidia.enable = true; # Include NVIDIA SDK extra-packages = pkgs: [ pkgs.ripgrep ];};Formatter
weyl-std.formatter = { enable = true; line-length = 100; indent-width = 2;};Direct Overlay Access
If you need direct access via pkgs:
perSystem = { pkgs, ... }: { # Via overlay (pkgs must have weyl-std overlay applied) packages.my-app = pkgs.weyl.stdenv.default { pname = "my-app"; version = "1.0"; src = ./.; };};The overlay provides:
pkgs.weyl.prelude— Functional librarypkgs.weyl.stdenv.*— Build environmentspkgs.weyl.cross.*— Cross-compilation targetspkgs.weyl.platform— Platform detectionpkgs.weyl.gpu— GPU architecturespkgs.weyl.the-law— Build flags
What’s in the Prelude
| Category | Examples |
|---|---|
| Fundamentals | id, const, compose, pipe, fix |
| Lists | map, filter, fold, zip, sort |
| Attrs | map-attrs, filter-attrs, merge, keys |
| Strings | split, join, trim, replace |
| Maybe | maybe, from-maybe, cat-maybes |
| Either | left, right, either, from-right |
| Comparison | eq, lt, min, max, clamp |
| Arithmetic | add, sub, mul, div, sum |
| Types | is-list, is-string, typeof |
| Platform | platform.current, platform.is-linux |
| GPU | gpu.sm_120, gpu.supports-fp8 |
| Stdenv | stdenv.default, stdenv.portable |
| Cross | cross.grace, cross.jetson |
| Languages | python.build, rust.build, cpp.bin |