Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ jobs:

- name: Check NixOS template
run: |
echo "Building NixOS toplevel ❄️"
nix build --no-link ./nixos#nixosConfigurations.my-system.config.system.build.toplevel
echo "NixOS template OK ✅"

- name: Check Rust template
run: |
system=$(nix eval --raw --impure --expr 'builtins.currentSystem')
echo "Build Rust dev shell 🦀"
nix build "./rust#devShells.${system}.default"
echo "Building Rust package 🦀"
nix build './rust'
echo "Rust template OK ✅"
2 changes: 1 addition & 1 deletion default/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "An empty flake template that you can adapt to your own environment";

# Flake inputs
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0"; # Stable Nixpkgs
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0"; # Stable Nixpkgs (use 0.1 for unstable)

# Flake outputs
outputs =
Expand Down
18 changes: 18 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@
https://search.nixos.org/options
'';
};

rust = {
description = "A flake template for Rust";
path = ./rust;
welcomeText = ''
# Welcome to your new NixOS configuration flake ❄️🦀

To activate your new flake's development environment, run `nix develop` or `direnv allow` if you use direnv.

To run the Rust program in this template (you should a warm greeting):

nix develop --command cargo run

To build the Rust program using Nix:

nix build
'';
};
};
};
}
6 changes: 3 additions & 3 deletions nix-darwin/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

# Flake inputs
inputs = {
# Stable Nixpkgs
# Stable Nixpkgs (use 0.1 for unstable)
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0";
# Stable nix-darwin
# Stable nix-darwin (use 0.1 for unstable)
nix-darwin = {
url = "https://flakehub.com/f/nix-darwin/nix-darwin/0";
inputs.nixpkgs.follows = "nixpkgs";
};
# Determinate module
# Determinate 3.* module
determinate = {
url = "https://flakehub.com/f/DeterminateSystems/determinate/3";
inputs.nixpkgs.follows = "nixpkgs";
Expand Down
2 changes: 1 addition & 1 deletion nixos/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Flake inputs
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0"; # Stable Nixpkgs
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0"; # Stable Nixpkgs (use 0.1 for unstable)
determinate = {
url = "https://flakehub.com/f/DeterminateSystems/determinate/3"; # Determinate 3.*
inputs.nixpkgs.follows = "nixpkgs";
Expand Down
1 change: 1 addition & 0 deletions rust/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
5 changes: 5 additions & 0 deletions rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Rust artifacts
/target/

# Nix artifacts
result*
7 changes: 7 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "rust-flake-template"
version = "0.1.0"
edition = "2024"
103 changes: 103 additions & 0 deletions rust/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
description = "A Rust flake template that you can adapt to your own environment";

# Flake inputs
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0"; # Stable Nixpkgs (use 0.1 for unstable)

# Flake outputs
outputs =
{ self, ... }@inputs:
let
# The systems supported for this flake's outputs
supportedSystems = [
"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
];

# Helper for providing system-specific attributes
forEachSupportedSystem =
f:
inputs.nixpkgs.lib.genAttrs supportedSystems (
system:
f {
# Provides a system-specific, configured Nixpkgs
pkgs = import inputs.nixpkgs {
inherit system;
# Enable using unfree packages
config.allowUnfree = true;
};
}
);
in
{
# Development environments output by this flake
devShells = forEachSupportedSystem (
{ pkgs }:
{
# Run `nix develop` to activate this environment or `direnv allow` if you have direnv installed
default = pkgs.mkShell {
# The Nix packages provided in the environment
packages = with pkgs; [
cargo
rustc
clippy
rustfmt
rust-analyzer # Rust language server for IDEs
# Uncomment the lines below for some helpful tools:
# cargo-edit # Commands like `cargo add` and `cargo rm`
# bacon # For iterative development
# cargo-nextest # Rust testing tool
# cargo-audit # Check dependencies for vulnerabilities
# cargo-outdated # Show which dependencies have updates available
# cargo-deny # Lint your dependency graph
# cargo-expand # Show macro expansions
];

# Set any environment variables for your development environment
env = {
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};

# Add any shell logic you want executed when the environment is activated
shellHook = ''
echo "Rust toolchain 🦀"
cargo --version
'';
};
}
);

# Package outputs
packages = forEachSupportedSystem (
{ pkgs }:
{
# Build the package using Nixpkgs' built-in Rust helpers
default =
let
# Get information about the package from Cargo.toml
meta = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package;
in
pkgs.rustPlatform.buildRustPackage {
inherit (meta) name version;
src = builtins.path {
path = ./.;
};
cargoLock.lockFile = ./Cargo.lock;
};
}
);

# Nix formatter

# This applies the formatter that follows RFC 166, which defines a standard format:
# https://github.com/NixOS/rfcs/pull/166

# To format all Nix files:
# git ls-files -z '*.nix' | xargs -0 -r nix fmt
# To check formatting:
# git ls-files -z '*.nix' | xargs -0 -r nix develop --command nixfmt --check
formatter = forEachSupportedSystem ({ pkgs, ... }: pkgs.nixfmt-rfc-style);
};
}
3 changes: 3 additions & 0 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello from the Rust template!");
}
Loading