diff --git a/flake.lock b/flake.lock index 66dd239..44b7dd9 100644 --- a/flake.lock +++ b/flake.lock @@ -172,23 +172,25 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1756256966, - "narHash": "sha256-sSVfAOlYIK01ptcDImwkyDVfhGPy/muVa4e7xxbhgho=", + "lastModified": 1757745802, + "narHash": "sha256-hLEO2TPj55KcUFUU1vgtHE9UEIOjRcH/4QbmfHNF820=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4c202d26483c5ccf3cb95e0053163facde9f047e", + "rev": "c23193b943c6c689d70ee98ce3128239ed9e32d1", "type": "github" }, "original": { "owner": "nixos", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { + "flake-utils": "flake-utils", "janet-fmt": "janet-fmt", - "zig2nix": "zig2nix" + "nixpkgs": "nixpkgs_4" } }, "systems": { @@ -241,25 +243,6 @@ "repo": "treefmt-nix", "type": "github" } - }, - "zig2nix": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs_4" - }, - "locked": { - "lastModified": 1756258936, - "narHash": "sha256-rpExIDs2BY97aRERH1Wv9VWke1Qe5wqGPqC3CRVCe8w=", - "owner": "Cloudef", - "repo": "zig2nix", - "rev": "96e9e4ab353d7617513bd33fef2b76102af322c2", - "type": "github" - }, - "original": { - "owner": "Cloudef", - "repo": "zig2nix", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 996c897..2b26a3c 100644 --- a/flake.nix +++ b/flake.nix @@ -2,85 +2,82 @@ description = "Yada yada modal text editor"; inputs = { - zig2nix.url = "github:Cloudef/zig2nix"; + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; janet-fmt.url = "github:haruki7049/janet-fmt"; }; - outputs = { zig2nix, janet-fmt, ... }: let - flake-utils = zig2nix.inputs.flake-utils; - in (flake-utils.lib.eachDefaultSystem (system: let - # Zig flake helper - # Check the flake.nix in zig2nix project for more options: - # - env = zig2nix.outputs.zig-env.${system} { zig = zig2nix.outputs.packages.${system}.zig-0_14_1; }; - in with builtins; with env.pkgs.lib; rec { - # Produces clean binaries meant to be ship'd outside of nix - # nix build .#foreign - packages.foreign = env.package { - src = cleanSource ./.; - - # Packages required for compiling - nativeBuildInputs = with env.pkgs; []; - - # Packages required for linking - buildInputs = with env.pkgs; []; - - # Smaller binaries and avoids shipping glibc. - zigPreferMusl = true; - }; - - # nix build . - packages.default = packages.foreign.override (attrs: { - # Prefer nix friendly settings. - zigPreferMusl = false; - - # Executables required for runtime - # These packages will be added to the PATH - zigWrapperBins = with env.pkgs; []; - - # Libraries required for runtime - # These packages will be added to the LD_LIBRARY_PATH - zigWrapperLibs = attrs.buildInputs or []; + outputs = { + self, + nixpkgs, + flake-utils, + janet-fmt, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs {inherit system;}; + toolchain = pkgs.rustPlatform; + cargoPackage = (pkgs.lib.importTOML "${self}/Cargo.toml").package; + in rec + { + # nix build + # TODO: presumably broken right now, YAGNI + packages.default = toolchain.buildRustPackage { + pname = cargoPackage.name; + version = cargoPackage.version; + src = pkgs.lib.cleanSource "${self}"; + cargoLock = { + lockFile = "${self}/Cargo.lock"; + allowBuiltinFetchGit = true; + }; + useNextest = true; + dontUseCargoParallelTests = true; + + nativeBuildInputs = with pkgs; [ ]; + buildInputs = with pkgs; [ + libclang + ]; + LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; + + meta = { + description = cargoPackage.description; + homepage = cargoPackage.repository; + license = pkgs.lib.licenses.gpl2Only; + maintainers = cargoPackage.authors; + }; + + # For other makeRustPlatform features see: + # https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md#cargo-features-cargo-features + }; + + # nix run + apps.default = flake-utils.lib.mkApp {drv = packages.default;}; + + # nix develop + devShells.default = pkgs.mkShell.override { + stdenv = pkgs.clangStdenv; + } { + buildInputs = with pkgs; [ + (with toolchain; [ + cargo + rustc + rustLibSrc + ]) + clippy + rustfmt + cargo-edit + cargo-nextest + rust-analyzer + libclang + janet + jpm + janet-fmt.outputs.packages."${system}".default + ]; + + # Many editors rely on this rust-src PATH variable + RUST_SRC_PATH = "${toolchain.rustLibSrc}"; + + LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; + }; }); - - # For bundling with nix bundle for running outside of nix - # example: https://github.com/ralismark/nix-appimage - apps.bundle = { - type = "app"; - program = "${packages.foreign}/bin/default"; - }; - - # nix run . - apps.default = env.app [] "zig build run -- \"$@\""; - - # nix run .#build - apps.build = env.app [] "zig build \"$@\""; - - # nix run .#test - apps.test = env.app [] "zig build test -- \"$@\""; - - # nix run .#docs - apps.docs = env.app [] "zig build docs -- \"$@\""; - - # nix run .#zig2nix - apps.zig2nix = env.app [] "zig2nix \"$@\""; - - # nix develop - devShells.default = env.mkShell { - buildInputs = with env.pkgs; [ - zls - janet - jpm - janet-fmt.outputs.packages."${system}".default - ]; - - # Packages required for compiling, linking and running - # Libraries added here will be automatically added to the LD_LIBRARY_PATH and PKG_CONFIG_PATH - nativeBuildInputs = [] - ++ packages.default.nativeBuildInputs - ++ packages.default.buildInputs - ++ packages.default.zigWrapperBins - ++ packages.default.zigWrapperLibs; - }; - })); }