Files
thor/flake.nix
T
2026-07-23 16:12:03 -04:00

167 lines
4.5 KiB
Nix

{
description = "A dev environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
# process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
inputs@{
self,
flake-parts,
nixpkgs,
nixpkgs-unstable,
# , process-compose-flake
treefmt-nix,
}:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.treefmt-nix.flakeModule
# inputs.process-compose-flake.flakeModule
];
systems = [ "x86_64-linux" ];
perSystem =
{
pkgs,
system,
inputs',
...
}:
let
mkGrammarStaticLib = name: src: pkgs.stdenv.mkDerivation {
inherit name src;
dontConfigure = true;
buildPhase = ''
runHook preBuild
if [ -f src/scanner.cc ]; then
$CXX -fPIC -c src/scanner.cc -o scanner.o
elif [ -f src/scanner.c ]; then
$CC -fPIC -c src/scanner.c -o scanner.o
fi
$CC -fPIC -c src/parser.c -o parser.o
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/lib
ar rcs $out/lib/lib${name}.a *.o
runHook postInstall
'';
};
html-grammar = mkGrammarStaticLib "tree-sitter-html"
pkgs.tree-sitter-grammars.tree-sitter-html.src;
css-grammar = mkGrammarStaticLib "tree-sitter-css"
pkgs.tree-sitter-grammars.tree-sitter-css.src;
odin = pkgs.unstable.odin;
ols = pkgs.unstable.ols;
in
{
_module.args.pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = [
(final: prev: { unstable = inputs'.nixpkgs-unstable.legacyPackages; })
];
};
treefmt = {
# Used to find the project root
projectRootFile = "flake.nix";
settings.global.excludes = [
".direnv/**"
".jj/**"
".env"
".envrc"
".env.local"
];
# Format nix files
programs.nixpkgs-fmt.enable = true;
programs.deadnix.enable = true;
# Format js, json, and yaml files
programs.prettier.enable = true;
settings.formatter.prettier = {
excludes = [
"public/**"
"resources/js/modernizr.js"
"storage/app/caniuse.json"
"*.md"
];
};
};
#process-compose.default.settings.processes = { };
packages.default = pkgs.stdenv.mkDerivation rec {
pname = "thor";
version = nixpkgs.lib.trim (builtins.readFile ./version.txt);
src = ./.;
nativeBuildInputs = [
odin
pkgs.pkg-config
];
buildInputs = [
pkgs.git
pkgs.cmark
pkgs.tree-sitter
html-grammar
css-grammar
];
LIBRARY_PATH = "${html-grammar}/lib:${css-grammar}/lib";
doCheck = true;
checkPhase = ''
runHook preCheck
odin test . -all-packages
runHook postCheck
'';
buildPhase = ''
runHook preBuild
odin build . -o:speed -out:${pname}-keep
runHook postBuild
'';
installPhase = ''
runHook preInstall
install -Dm755 ${pname}-keep $out/bin/${pname}
runHook postInstall
'';
};
devShells.default = pkgs.mkShell {
buildInputs = [odin ols ] ++ (with pkgs; [
cmark
tree-sitter
gdb
# IDE
unstable.helix
typescript-language-server
vscode-langservers-extracted
]);
shellHook = ''
export LIBRARY_PATH="${html-grammar}/lib:${css-grammar}/lib:$LIBRARY_PATH"
'';
};
};
};
}