nanobrush / flake.nix
nmarshall's picture
formats: add txt conversion cli
18d65b9
Raw History Blame Contribute Delete
7.13 kB
{
description = "Nanobrush development and Microbrush reference preservation";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
inputs.parts.url = "github:hercules-ci/flake-parts";
inputs.my-nix = {
url = "github:nmrshll/my-nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.fp.follows = "parts";
};
outputs =
inputs@{ parts, ... }:
parts.lib.mkFlake { inherit inputs; } (
{ ... }: {
systems = [
"aarch64-darwin"
"x86_64-darwin"
"x86_64-linux"
"aarch64-linux"
];
imports =
builtins.attrValues (inputs.my-nix.flakeModuleGroups or inputs.my-nix.flakeModules).essentials
++ [ inputs.my-nix.flakeModules.rust ];
perSystem =
{
pkgs,
lib,
config,
...
}:
let
python = pkgs.python3.withPackages (ps: [
ps.huggingface-hub
ps.hf-xet
]);
runtimeDeps = lib.optionals pkgs.stdenv.isLinux (
with pkgs;
[
alsa-lib
udev
vulkan-loader
wayland
libxkbcommon
libX11
libXcursor
libXi
libXrandr
]
);
devTools = with pkgs; [
git
git-lfs
git-xet
python
unzip
zip
ripgrep
jq
coreutils
nixfmt
shellcheck
pkg-config
cmake
ninja
cargo-nextest
ilspycmd
mono
];
command = script: ''
set -eu
export PATH=${
lib.makeBinPath (
[
python
pkgs.git
pkgs.git-lfs
pkgs.git-xet
]
++ devTools
)
}:$PATH
cd "$(git rev-parse --show-toplevel)"
exec ${python}/bin/python3 ${script} "$@"
'';
scripts = builtins.mapAttrs pkgs.writeShellScriptBin {
setup-repository = command "scripts/setup-repository.py";
check-storage = command "scripts/storage_policy.py check --require-setup";
assets-check = command "scripts/assets.py check";
assets-fetch = command "scripts/assets.py fetch";
verify-references = command "scripts/references.py verify";
unpack-references = command "scripts/references.py unpack";
index-references = command "scripts/references.py index";
map-references = command "scripts/map_references.py";
check-reference-map = command "scripts/map_references.py --check";
analyze-converter = command "scripts/analyze_converter.py";
inspect-mb3dat = command "scripts/inspect_mb3dat.py";
test-setup = command "scripts/test_setup.py";
check-environment = command "scripts/check_environment.py";
};
codeSource = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./crates
./scripts
./tests
./config
./docs
./.githooks
./README.md
./.gitattributes
./.gitignore
./flake.nix
./flake.lock
./.envrc
];
};
setupCheck =
pkgs.runCommand "nanobrush-setup-checks"
{
nativeBuildInputs = [
pkgs.python3
pkgs.git
pkgs.git-lfs
pkgs.git-xet
];
}
''
cp -R ${codeSource}/. .
chmod -R u+w .
python3 scripts/test_setup.py
python3 scripts/storage_policy.py check-tree ${codeSource}
touch $out
'';
rustCheck =
pkgs.runCommand "nanobrush-rust-checks"
{
nativeBuildInputs = [
config.rust.toolchain
pkgs.stdenv.cc
];
}
''
cp -R ${codeSource}/. .
chmod -R u+w .
export CARGO_HOME="$TMPDIR/nanobrush-cargo"
cargo fmt --all --check
cargo clippy --workspace --all-targets --locked --offline -- -D warnings
cargo test --workspace --lib --locked --offline
cargo test --workspace --doc --locked --offline
touch $out
'';
cliPackage =
pkgs.runCommand "nanobrush-cli-0.1.0"
{
nativeBuildInputs = [
config.rust.toolchain
pkgs.stdenv.cc
];
meta.mainProgram = "nanobrush";
}
''
cp -R ${codeSource}/. .
chmod -R u+w .
export CARGO_HOME="$TMPDIR/nanobrush-cargo"
cargo build -p nanobrush-cli --release --locked --offline
mkdir -p "$out/bin"
cp target/release/nanobrush "$out/bin/nanobrush"
'';
in
{
packages = scripts // {
nanobrush = cliPackage;
};
rust.buildInputs = runtimeDeps;
rust.nativeBuildInputs = [ pkgs.pkg-config ];
rust.toolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
"rust-analyzer"
"rustfmt"
"clippy"
];
};
myDevShell.overrides.stdenv = pkgs.stdenv;
myDevShell.buildInputs = lib.mkForce (
[ config.rust.toolchain ] ++ devTools ++ runtimeDeps ++ builtins.attrValues scripts
);
myDevShell.env = {
RUST_BACKTRACE = "1";
}
// lib.optionalAttrs pkgs.stdenv.isLinux { LD_LIBRARY_PATH = lib.makeLibraryPath runtimeDeps; };
# Suppress shared editor/global configuration hooks; only configure this checkout.
myDevShell.shellHooks = lib.mkForce {
repository = ''
if [ -f scripts/setup-repository.py ]; then
${python}/bin/python3 scripts/setup-repository.py || return 1
fi
'';
};
checks.setup = setupCheck;
checks.rust = rustCheck;
formatter = pkgs.nixfmt;
};
}
);
}