Rust Development Shell #rust
{
inputs = {
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "nixpkgs/nixos-unstable";
};
outputs = {
self,
fenix,
nixpkgs,
}: let
# Define supported systems
supportedSystems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin"];
# Helper function to generate outputs for each system
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Define the Rust toolchain components
rustToolchainComponents = [
"cargo"
"clippy"
"rust-src"
"rustc"
"rustfmt"
];
in {
# Development shells for each supported system
devShells = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
rustToolchain = fenix.packages.${system}.complete.withComponents rustToolchainComponents;
in {
default = pkgs.mkShell {
name = "rust-dev-shell";
packages = [
rustToolchain
# pkgs.rust-analyzer # Or fenix.packages.${system}.rust-analyzer for fenix provided one
# Add other development tools specific to the shell here
# e.g., pkgs.openssl pkgs.pkg-config
];
# You can set environment variables here if needed
# RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
};
});
};
}
Go Development Shell #golang
{
description = "A Go development environment";
# Define the inputs for this flake.
# 'nixpkgs' provides the packages and functions we'll use.
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; # Or your preferred channel
};
# Define the outputs of this flake.
# 'self' refers to this flake, and 'nixpkgs' refers to the input defined above.
outputs = { self, nixpkgs, ... }@inputs:
let
# Helper function to generate a devShell for a specific system.
mkGoShell = pkgs:
pkgs.mkShell {
# Name of the development shell
name = "go-dev-shell";
# Packages to include in the development environment.
packages = with pkgs; [
# Go compiler and core tools
go
# gopls
# delve
# Optional: Additional Go tools
# goimports # For formatting imports
# golangci-lint # A popular Go linter
# gotools # A collection of tools like eg, guru, etc.
];
# Environment variables to set (optional)
shellHook = ''
export GOPATH=$(pwd)/.go
export GOBIN=$(pwd)/.go/bin
export PATH=$PATH:$(pwd)/.go/bin
# echo "Go development environment activated."
# echo "GOPATH set to $(pwd)/.go"
'';
};
# Iterate over common systems and create a devShell for each.
# You can add or remove systems as needed.
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = nixpkgs.lib.genAttrs systems;
in
{
# Development shells for different systems
devShells = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
default = mkGoShell pkgs;
}
);
# You can also expose packages or apps here if needed
# packages = forAllSystems (system: ...);
# apps = forAllSystems (system: ...);
};
}