This commit is contained in:
2025-12-01 15:06:16 +09:00
parent 2b690df7cc
commit 53a3d40dd0
4 changed files with 115 additions and 2 deletions
+1
View File
@@ -86,6 +86,7 @@
in {
next-web = import ./shells/next-web.nix { inherit pkgs; };
jupyter = import ./shells/jupyter.nix { inherit pkgs; };
rust = import ./shells/rust/default.nix { inherit pkgs; };
};
};
};
+63 -2
View File
@@ -3,6 +3,18 @@ let
vsc = pkgs.vscode-extensions;
inherit (lib) recursiveUpdate;
rustLibclangPath = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
rustBindgenExtraClangArgs = lib.concatStringsSep " " (
(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/''
]
);
layers = rec {
common = {
extensions = (with vsc; [
@@ -103,6 +115,8 @@ let
extensions = (with vsc; [
vscjava.vscode-java-pack
sonarsource.sonarlint-vscode
vscjava.vscode-java-debug
redhat.java
]);
userSettings = {
@@ -115,8 +129,10 @@ let
}
];
"java.jdt.ls.vmargs" =
"-Xms256m -Xmx2G -XX:+UseG1GC -XX:+UseStringDeduplication";
"editor.codeLens" = true;
"java.debug.settings.enableRunDebugCodeLens" = true;
"java.jdt.ls.vmargs" = "-Xms256m -Xmx2G -XX:+UseG1GC -XX:+UseStringDeduplication";
"java.configuration.updateBuildConfiguration" = "interactive";
@@ -126,6 +142,49 @@ let
"maven.executable.path" = "${pkgs.maven}/bin/mvn";
};
};
rust = {
extensions = with vsc; [
rust-lang.rust-analyzer
vadimcn.vscode-lldb
serayuzgur.crates
tamasfe.even-better-toml
];
userSettings = {
"[rust]" = {
"editor.defaultFormatter" = "rust-lang.rust-analyzer";
"editor.formatOnSave" = true;
"editor.codeActionsOnSave" = {
"source.organizeImports" = true;
"source.fixAll" = true;
};
};
"rust-analyzer.checkOnSave" = true;
"rust-analyzer.check.command" = "clippy";
"rust-analyzer.cargo.buildScripts.enable" = true;
"rust-analyzer.procMacro.enable" = true;
"rust-analyzer.cargo.targetDir" = true;
"rust-analyzer.cargo.extraEnv" = {
"LIBCLANG_PATH" = rustLibclangPath;
"BINDGEN_EXTRA_CLANG_ARGS" = rustBindgenExtraClangArgs;
};
"rust-analyzer.lens.enable" = true;
"rust-analyzer.lens.implementations.enable" = true;
"rust-analyzer.lens.references.adt.enable" = true;
"rust-analyzer.lens.references.enumVariant.enable" = true;
"rust-analyzer.lens.references.method.enable" = true;
"rust-analyzer.lens.references.trait.enable" = true;
"files.watcherExclude" = { "**/target/**" = true; };
"search.exclude" = { "**/target/**" = true; };
};
};
};
combine = (ls:
@@ -159,6 +218,8 @@ in {
jupyter = mkProfile [ layers.common layers.jupyter ] { };
java = mkProfile [ layers.common layers.java ] { };
rust = mkProfile [ layers.common layers.rust ] { };
};
};
+49
View File
@@ -0,0 +1,49 @@
# ref: https://nixos.wiki/wiki/Rust
{ pkgs ? import <nixpkgs> {} }:
let
overrides = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml));
libPath = with pkgs; lib.makeLibraryPath [
# load external libraries that you need in your rust project here
];
in
pkgs.mkShell rec {
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = with pkgs; [
clang
# Replace llvmPackages with llvmPackages_X, where X is the latest LLVM version (at the time of writing, 16)
llvmPackages.bintools
rustup
];
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)
]);
LD_LIBRARY_PATH = libPath;
# 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/''
];
}
+2
View File
@@ -0,0 +1,2 @@
[toolchain]
channel = "stable"