From b0951b680501baebb9604e0ac496b748b6f10b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sat, 20 Jan 2024 16:24:08 +0100 Subject: [PATCH 1/4] feat: use mold linker through crane --- templates/rust/.cargo/config.toml | 2 -- templates/rust/flake.nix | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) delete mode 100644 templates/rust/.cargo/config.toml diff --git a/templates/rust/.cargo/config.toml b/templates/rust/.cargo/config.toml deleted file mode 100644 index 4b929fe..0000000 --- a/templates/rust/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.x86_64-unknown-linux-gnu] -linker = "clang" diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix index 3c67202..fc15b39 100644 --- a/templates/rust/flake.nix +++ b/templates/rust/flake.nix @@ -23,28 +23,36 @@ }; toolchain = fenix.packages.${system}.stable; craneLib = crane.lib.${system}.overrideToolchain toolchain.toolchain; + stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv; in { - packages.default = + packages = let inherit (pkgs.lib) fileset; - in - craneLib.buildPackage { + without = fs: fileset.difference ./. fs; + nixFiles = fileset.unions [ ./flake.nix ./flake.lock ./.envrc ]; + gitFiles = fileset.gitTracked ./.; src = fileset.toSource { root = ./.; - fileset = fileset.intersection - (fileset.difference ./. - (fileset.unions [ ./.cargo ./flake.nix ./flake.lock ./.envrc ])) - (fileset.gitTracked ./.); + fileset = fileset.intersection (without nixFiles) gitFiles; }; + in + { + default = + craneLib.buildPackage { + inherit src stdenv; + }; }; devShell = pkgs.mkShell.override { - stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv; + inherit stdenv; } { - nativeBuildInputs = with toolchain; [ rustc cargo rust-analyzer clippy ]; + nativeBuildInputs = with toolchain; + [ rustc cargo rust-analyzer clippy ] ++ (with pkgs; + [ ] + ); }; }); } From 45a1190af7116b0e10fd62589ad50625988ff95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 21 Jan 2024 14:53:56 +0100 Subject: [PATCH 2/4] feat: improve rust template --- templates/rust/flake.nix | 85 ++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix index fc15b39..317e679 100644 --- a/templates/rust/flake.nix +++ b/templates/rust/flake.nix @@ -1,58 +1,59 @@ { inputs = { - crane = { - url = "github:ipetkov/crane"; - inputs = { - flake-utils.follows = "flake-utils"; - nixpkgs.follows = "nixpkgs"; - }; - }; - fenix = { - url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; + crane.url = "github:ipetkov/crane"; + crane.inputs.nixpkgs.follows = "nixpkgs"; + fenix.url = "github:nix-community/fenix"; + fenix.inputs.nixpkgs.follows = "nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "nixpkgs/nixos-unstable"; }; - outputs = { self, crane, fenix, flake-utils, nixpkgs }: + outputs = { self, crane, flake-utils, nixpkgs, ... }@inputs: flake-utils.lib.eachDefaultSystem (system: let - pkgs = (import nixpkgs) { - inherit system; - }; - toolchain = fenix.packages.${system}.stable; + inherit (pkgs) lib; + pkgs = import nixpkgs { inherit system; }; + fenix = inputs.fenix.packages.${system}; craneLib = crane.lib.${system}.overrideToolchain toolchain.toolchain; + mkSrc = extraPaths: with lib.fileset; let + root = ./.; + rustFiles = fromSource (craneLib.cleanCargoSource root); + fileset = union rustFiles (unions extraPaths); + in + toSource { inherit root fileset; }; + + ## Customize here ## + toolchain = fenix.complete; # or fenix.stable; stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv; in { - packages = - let - inherit (pkgs.lib) fileset; - without = fs: fileset.difference ./. fs; - nixFiles = fileset.unions [ ./flake.nix ./flake.lock ./.envrc ]; - gitFiles = fileset.gitTracked ./.; - src = fileset.toSource { - root = ./.; - fileset = fileset.intersection (without nixFiles) gitFiles; - }; - in - { - default = - craneLib.buildPackage { - inherit src stdenv; - }; - }; + packages.default = craneLib.buildPackage { + inherit stdenv; + src = mkSrc [ ]; + strictDeps = true; + buildInputs = [ + # Add additional build inputs here + ] ++ lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv + ]; + # Additional environment variables can be set directly + # MY_CUSTOM_VAR = "some value"; + }; - devShell = pkgs.mkShell.override + devShells.default = pkgs.mkShell.override { inherit stdenv; } { - inherit stdenv; - } - { - nativeBuildInputs = with toolchain; - [ rustc cargo rust-analyzer clippy ] ++ (with pkgs; - [ ] - ); + nativeBuildInputs = with pkgs; [ + # Add additional build inputs here + ] ++ (with toolchain; [ + cargo + clippy + rustfmt + rustc + fenix.rust-analyzer + ]); + RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library"; }; - }); + } + ); } From 0a0c6755525ff60f41341b46ee7eae13e465e498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 21 Jan 2024 14:54:19 +0100 Subject: [PATCH 3/4] feat: ignore statix for templates --- statix.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 statix.toml diff --git a/statix.toml b/statix.toml new file mode 100644 index 0000000..daefa4c --- /dev/null +++ b/statix.toml @@ -0,0 +1,3 @@ +disabled = [] +nix_version = '2.4' +ignore = ['.direnv' 'templates'] From a9e0b92d819102050736addae12648d5b0b9a78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Mon, 22 Jan 2024 15:25:47 +0100 Subject: [PATCH 4/4] fix(nvim): toggle of inlay hints --- modules/programs/nvim/plugins/lua/nvim-lspconfig.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/programs/nvim/plugins/lua/nvim-lspconfig.lua b/modules/programs/nvim/plugins/lua/nvim-lspconfig.lua index c936012..3bf386c 100644 --- a/modules/programs/nvim/plugins/lua/nvim-lspconfig.lua +++ b/modules/programs/nvim/plugins/lua/nvim-lspconfig.lua @@ -64,7 +64,7 @@ local on_attach_def = function(client, bufnr) }, i = { function() - vim.lsp.inlay_hint(bufnr, nil) + vim.lsp.inlay_hint.enable(bufnr, not vim.lsp.inlay_hint.is_enabled(bufnr)) end, "LSP inlay hints", },