diff --git a/flake.lock b/flake.lock index 503ff2a..d8c38ed 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,26 @@ { "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1779612045, + "narHash": "sha256-+7lfNVnmXJDkiRYHd5NoNwYoyUcc0LcXPaIJqjO7VWM=", + "owner": "nix-community", + "repo": "fenix", + "rev": "d7be747f0a65af378de515fc3cee131bf99a008f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -20,11 +41,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1779357205, - "narHash": "sha256-cCO8aTqss5x9Ky8GWkpY0Hy5fyTZEbtifSUV8QjSzic=", + "lastModified": 1779508470, + "narHash": "sha256-Ap9KJX+5xHIn3bPIpfNgT6MEXdAECECwo4/rmlQD74M=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f83fc3c307e74bc5fd5adb7eb6b8b13ffd2a36e1", + "rev": "29916453413845e54a65b8a1cf996842300cd299", "type": "github" }, "original": { @@ -36,10 +57,28 @@ }, "root": { "inputs": { + "fenix": "fenix", "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1779569060, + "narHash": "sha256-NSnk5D+3KEfRdbgPijs33N2RAKSG6A74SwfnynLcouo=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "987ea33645ab1c709b1df6823038abcb2fe8973e", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, "systems": { "locked": { "lastModified": 1681028828, diff --git a/flake.nix b/flake.nix index cdf0479..0af558c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,59 +1,41 @@ { description = "Rust development environment"; - inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - - outputs = { self, nixpkgs, flake-utils }: + outputs = { self, nixpkgs, flake-utils, fenix }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - # Read the file relative to the flake's root - overrides = (builtins.fromTOML (builtins.readFile (self + "/rust-toolchain.toml"))); + toolchain = fenix.packages.${system}.fromToolchainFile { + file = ./rust-toolchain.toml; + sha256 = sha256-gh/xTkxKHL4eiRXzWv8KP7vfjSk61Iq48x47BEDFgfk=; + }; in { devShells.default = pkgs.mkShell rec { nativeBuildInputs = [ pkgs.pkg-config ]; buildInputs = with pkgs; [ + toolchain clang llvmPackages.bintools - rustup typst ]; - - RUSTC_VERSION = overrides.toolchain.channel; - - # https://github.com/rust-lang/rust-bindgen#environment-variables LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ]; - - shellHook = '' - export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin - export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/ - ''; - - # Add precompiled library to rustc search path - RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [ - # add libraries here (e.g. pkgs.libvmi) - ]); - + RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') []); LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (buildInputs ++ nativeBuildInputs); - - - # Add glibc, clang, glib, and other headers to bindgen search path BINDGEN_EXTRA_CLANG_ARGS = - # Includes normal include path - (builtins.map (a: ''-I"${a}/include"'') [ - # add dev libraries here (e.g. pkgs.libvmi.dev) - pkgs.glibc.dev - ]) - # Includes with special directory paths - ++ [ - ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"'' - ''-I"${pkgs.glib.dev}/include/glib-2.0"'' - ''-I${pkgs.glib.out}/lib/glib-2.0/include/'' - ]; + (builtins.map (a: ''-I"${a}/include"'') [ pkgs.glibc.dev ]) + ++ [ + ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"'' + ''-I"${pkgs.glib.dev}/include/glib-2.0"'' + ''-I${pkgs.glib.out}/lib/glib-2.0/include/'' + ]; }; } );