WEYL WEYL
← Back to Weyl Standard
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:

What’s in the Prelude

CategoryExamples
Fundamentalsid, const, compose, pipe, fix
Listsmap, filter, fold, zip, sort
Attrsmap-attrs, filter-attrs, merge, keys
Stringssplit, join, trim, replace
Maybemaybe, from-maybe, cat-maybes
Eitherleft, right, either, from-right
Comparisoneq, lt, min, max, clamp
Arithmeticadd, sub, mul, div, sum
Typesis-list, is-string, typeof
Platformplatform.current, platform.is-linux
GPUgpu.sm_120, gpu.supports-fp8
Stdenvstdenv.default, stdenv.portable
Crosscross.grace, cross.jetson
Languagespython.build, rust.build, cpp.bin