feat(nix): improves flake to work with vs code
This commit is contained in:
parent
9c3394e7c0
commit
4fd67f932b
57
flake.lock
generated
57
flake.lock
generated
@ -1,6 +1,40 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1710146030,
|
||||||
|
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1724748588,
|
||||||
|
"narHash": "sha256-NlpGA4+AIf1dKNq76ps90rxowlFXUsV9x7vK/mN37JM=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "a6292e34000dc93d43bccf78338770c1c5ec8a99",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1718428119,
|
"lastModified": 1718428119,
|
||||||
"narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=",
|
"narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=",
|
||||||
@ -18,16 +52,14 @@
|
|||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"flake-utils": "flake-utils",
|
||||||
"rust-overlay",
|
"nixpkgs": "nixpkgs",
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"rust-overlay": "rust-overlay"
|
"rust-overlay": "rust-overlay"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rust-overlay": {
|
"rust-overlay": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1724811750,
|
"lastModified": 1724811750,
|
||||||
@ -42,6 +74,21 @@
|
|||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"type": "github"
|
"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",
|
"root": "root",
|
||||||
|
85
flake.nix
85
flake.nix
@ -1,67 +1,42 @@
|
|||||||
{
|
{
|
||||||
description = "Example Rust development environment for Zero to Nix";
|
description = "Example Rust development environment for Zero to Nix";
|
||||||
|
|
||||||
# Flake inputs
|
|
||||||
inputs = {
|
inputs = {
|
||||||
# nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
rust-overlay.url = "github:oxalica/rust-overlay"; # A helper for Rust + Nix
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||||
# cargo2nix.url = "github:cargo2nix/cargo2nix/";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
nixpkgs.follows = "rust-overlay/nixpkgs";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Flake outputs
|
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
|
||||||
outputs = { self, nixpkgs, rust-overlay}:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
# Overlays enable you to customize the Nixpkgs attribute set
|
overlays = [ (import rust-overlay) ];
|
||||||
overlays = [
|
pkgs = import nixpkgs {
|
||||||
# Makes a `rust-bin` attribute available in Nixpkgs
|
inherit system overlays;
|
||||||
(import rust-overlay)
|
};
|
||||||
# Provides a `rustToolchain` attribute for Nixpkgs that we can use to
|
rustToolchain = pkgs.rust-bin.nightly.latest.default.override {
|
||||||
# create a Rust environment
|
extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ];
|
||||||
(self: super: {
|
targets = [ "x86_64-unknown-linux-gnu" "wasm32-unknown-unknown" ];
|
||||||
rustToolchain = super.rust-bin.stable.latest.default;
|
};
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
# Systems supported
|
|
||||||
allSystems = [
|
|
||||||
"x86_64-linux" # 64-bit Intel/AMD Linux
|
|
||||||
"aarch64-linux" # 64-bit ARM Linux
|
|
||||||
"x86_64-darwin" # 64-bit Intel macOS
|
|
||||||
"aarch64-darwin" # 64-bit ARM macOS
|
|
||||||
];
|
|
||||||
|
|
||||||
# rustTarget = nixpkgs.pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
|
|
||||||
# extensions = [ "rust-src" "rustup" "rust-analyzer" "rust-std" ];
|
|
||||||
# targets = [ "x86_64-unknown-linux-gnu" "wasm32-unknown-unknown" ];
|
|
||||||
# });
|
|
||||||
|
|
||||||
# Helper to provide system-specific attributes
|
|
||||||
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
|
|
||||||
pkgs = import nixpkgs { inherit overlays system; };
|
|
||||||
});
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Development environment output
|
devShells.default = pkgs.mkShell {
|
||||||
devShells = forAllSystems ({ pkgs }: {
|
buildInputs = with pkgs; [
|
||||||
default = pkgs.mkShell {
|
|
||||||
buildInputs = [
|
|
||||||
pkgs.cargo-shuttle
|
|
||||||
];
|
|
||||||
# shellHook = ''
|
|
||||||
# rustup target add wasm32-unknown-unknown
|
|
||||||
# '';
|
|
||||||
# The Nix packages provided in the environment
|
|
||||||
packages = (with pkgs; [
|
|
||||||
# The package provided by our custom overlay. Includes cargo, Clippy, cargo-fmt,
|
|
||||||
# rustdoc, rustfmt, and other tools.
|
|
||||||
rust-analyzer
|
|
||||||
clippy
|
|
||||||
trunk
|
|
||||||
tailwindcss
|
|
||||||
rustToolchain
|
rustToolchain
|
||||||
]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]);
|
trunk
|
||||||
};
|
clippy
|
||||||
});
|
tailwindcss
|
||||||
|
cargo-shuttle
|
||||||
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
export PATH=${rustToolchain}/bin:$PATH
|
||||||
|
export RUSTC_VERSION=$(rustc --version)
|
||||||
|
export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library"
|
||||||
|
'';
|
||||||
|
|
||||||
|
packages = pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user