virittaa

Log | Files | Refs | README | LICENSE

commit 6865860ceb6cf4ae5248b35632f9568f241415bb
parent 328ffa576ef9923de7a0229535e50ec0bf9685ec
Author: mtmn <miro@haravara.org>
Date:   Wed,  6 May 2026 21:15:28 +0200

feat: add nix flake with cross-platform builds

Diffstat:
Aflake.lock | 176+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aflake.nix | 158+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aprek.toml | 41+++++++++++++++++++++++++++++++++++++++++
3 files changed, 375 insertions(+), 0 deletions(-)

diff --git a/flake.lock b/flake.lock @@ -0,0 +1,176 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1777830388, + "narHash": "sha256-2uoQAqUk2H0ijQtGiWAyNeQYGYc6yfAcRRLlJAz4Gp8=", + "owner": "ipetkov", + "repo": "crane", + "rev": "d459c1350e96ce1a7e3859c513ef5e9869d67d6f", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1777969788, + "narHash": "sha256-8sr3w0KyQ0K7TEd8pYwYrxiDk0GZ4A7iIcl1lsxlzVM=", + "owner": "nix-community", + "repo": "fenix", + "rev": "3abc2d5559f4dc30c710ab152abcb4cb60b561ba", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "fenix_2": { + "inputs": { + "nixpkgs": [ + "naersk", + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src_2" + }, + "locked": { + "lastModified": 1752475459, + "narHash": "sha256-z6QEu4ZFuHiqdOPbYss4/Q8B0BFhacR8ts6jO/F/aOU=", + "owner": "nix-community", + "repo": "fenix", + "rev": "bf0d6f70f4c9a9cf8845f992105652173f4b617f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "fenix": "fenix_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1777031541, + "narHash": "sha256-KZ4s1kolHXFQrRGlnB503gDcTrVQMhiczO+LvvwKEPg=", + "owner": "nix-community", + "repo": "naersk", + "rev": "5e73301621274c44798bf6c6211ed27fc2ced201", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1777954456, + "narHash": "sha256-hGdgeU2Nk87RAuZyYjyDjFL6LK7dAZN5RE9+hrDTkDU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "549bd84d6279f9852cae6225e372cc67fb91a4c1", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "crane": "crane", + "fenix": "fenix", + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1777924689, + "narHash": "sha256-9Z0puLyCSYvtYhP1IZMxC05DSgwA+5rE99jsv1KErc4=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "91c7c2c4ca6a0520cfbf97e369e4fb7bf0b63b7a", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "rust-analyzer-src_2": { + "flake": false, + "locked": { + "lastModified": 1752428706, + "narHash": "sha256-EJcdxw3aXfP8Ex1Nm3s0awyH9egQvB2Gu+QEnJn2Sfg=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "591e3b7624be97e4443ea7b5542c191311aa141d", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix @@ -0,0 +1,158 @@ +{ + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + crane = { + url = "github:ipetkov/crane"; + }; + + naersk = { + url = "github:nix-community/naersk"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + nixpkgs, + flake-utils, + fenix, + crane, + naersk, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = nixpkgs.legacyPackages.${system}; + fenixPkgs = fenix.packages.${system}; + stableToolchain = fenixPkgs.stable.toolchain; + craneLib = (crane.mkLib pkgs).overrideToolchain stableToolchain; + src = craneLib.cleanCargoSource ./.; + + baseNativeBuildInputs = with pkgs; [ + pkg-config + cmake + llvmPackages.libclang + ]; + + commonArgs = { + inherit src; + pname = "virittaa"; + version = "0.1.0"; + strictDeps = true; + LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; + BINDGEN_EXTRA_CLANG_ARGS = "-isystem ${pkgs.glibc.dev}/include -isystem ${pkgs.llvmPackages.libclang.lib}/lib/clang/${pkgs.llvmPackages.libclang.version}/include"; + + nativeBuildInputs = baseNativeBuildInputs ++ [pkgs.glibc.dev]; + + buildInputs = with pkgs; + [ + ffmpeg + ] + ++ lib.optionals stdenv.isDarwin [libiconv]; + }; + + virittaa = craneLib.buildPackage (commonArgs + // { + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + nativeBuildInputs = commonArgs.nativeBuildInputs ++ [pkgs.makeWrapper]; + postInstall = '' + wrapProgram $out/bin/virittaa --prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath [pkgs.ffmpeg]}" + ''; + }); + + mkCross = { + target, + pkgsCrossName, + }: let + crossPkgs = pkgs.pkgsCross.${pkgsCrossName}; + toolchain = with fenixPkgs; + combine [ + minimal.cargo + minimal.rustc + targets.${target}.latest.rust-std + ]; + naerskLib = naersk.lib.${system}.override { + cargo = toolchain; + rustc = toolchain; + }; + linkerEnv = "CARGO_TARGET_${pkgs.lib.toUpper (builtins.replaceStrings ["-"] ["_"] target)}_LINKER"; + targetEnv = pkgs.lib.toUpper (builtins.replaceStrings ["-"] ["_"] target); + inherit (crossPkgs.stdenv) cc; + bintools = cc.bintools.bintools or cc.bintools; + libc = cc.libc or crossPkgs.glibc or crossPkgs.musl; + in + naerskLib.buildPackage { + inherit src; + pname = "virittaa"; + version = "0.1.0"; + CARGO_BUILD_TARGET = target; + ${linkerEnv} = "${cc}/bin/${cc.targetPrefix}cc"; + + "CC_${targetEnv}" = "${cc}/bin/${cc.targetPrefix}cc"; + "AR_${targetEnv}" = "${bintools}/bin/${cc.targetPrefix}ar"; + + PKG_CONFIG_ALLOW_CROSS = "1"; + PKG_CONFIG_PATH = pkgs.lib.concatStringsSep ":" ( + pkgs.lib.filter (x: x != "") + [ + (pkgs.lib.optionalString (crossPkgs ? ffmpeg) "${crossPkgs.ffmpeg.dev}/lib/pkgconfig") + "${libc.dev}/lib/pkgconfig" + ] + ); + + nativeBuildInputs = baseNativeBuildInputs ++ [libc.dev]; + + buildInputs = + pkgs.lib.optional (crossPkgs ? ffmpeg) crossPkgs.ffmpeg + ++ pkgs.lib.optional (crossPkgs.stdenv.isDarwin && (crossPkgs ? libiconv)) crossPkgs.libiconv; + + inherit (commonArgs) LIBCLANG_PATH; + BINDGEN_EXTRA_CLANG_ARGS = "-isystem ${libc.dev}/include -isystem ${pkgs.llvmPackages.libclang.lib}/lib/clang/${pkgs.llvmPackages.libclang.version}/include --target=${target}"; + }; + + virittaa-aarch64-linux = mkCross { + target = "aarch64-unknown-linux-gnu"; + pkgsCrossName = "aarch64-multiplatform"; + }; + virittaa-x86_64-windows = mkCross { + target = "x86_64-pc-windows-gnu"; + pkgsCrossName = "mingwW64"; + }; + virittaa-x86_64-darwin = mkCross { + target = "x86_64-apple-darwin"; + pkgsCrossName = "x86_64-darwin"; + }; + virittaa-aarch64-darwin = mkCross { + target = "aarch64-apple-darwin"; + pkgsCrossName = "aarch64-darwin"; + }; + in { + packages = { + default = virittaa; + inherit + virittaa + virittaa-aarch64-linux + virittaa-x86_64-windows + virittaa-x86_64-darwin + virittaa-aarch64-darwin + ; + }; + + devShells.default = pkgs.mkShell { + nativeBuildInputs = + [ + stableToolchain + fenixPkgs.rust-analyzer + ] + ++ commonArgs.nativeBuildInputs; + inherit (commonArgs) buildInputs; + }; + } + ); +} diff --git a/prek.toml b/prek.toml @@ -0,0 +1,41 @@ +[[repos]] +repo = "https://github.com/pre-commit/pre-commit-hooks" +rev = "v6.0.0" +hooks = [ + { id = "trailing-whitespace" }, + { id = "end-of-file-fixer" }, + { id = "double-quote-string-fixer" } +] + +[[repos]] +repo = "https://github.com/biomejs/pre-commit" +rev = "v2.4.10" +hooks = [ + { id = "biome-format" } +] + +[[repos]] +repo = "https://github.com/gitleaks/gitleaks" +rev = "v8.30.1" +hooks = [ + { id = "gitleaks" } +] + +[[repos]] +repo = "https://github.com/astro/deadnix" +rev = "v1.3.1" +hooks = [ + { id = "deadnix" } +] + +[[repos]] +repo = "local" +hooks = [ + { + id = "alejandra", + name = "alejandra", + language = "system", + entry = "alejandra", + files = '\.nix$' + }, +]