feat: Rust templates

This commit is contained in:
Kiana Sheibani 2025-11-26 17:45:12 -05:00
parent 50a0f0abc2
commit e5faf58ba8
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
33 changed files with 630 additions and 1 deletions

View file

@ -12,6 +12,7 @@
bash = "bash_script_nixpkgs";
fish = "fish_script_nixpkgs";
python = "python_pyproject_nixpkgs_basic";
rust = "rust_cargo-nightly_crane+fenix";
};
# Get all subdirectories of the given path
@ -35,7 +36,7 @@
${concatStringsSep "_" subds} = {
description = generateDesc subds;
path = filterSource
(p: _: baseNameOf p != "flake.lock")
(p: _: !(elem (baseNameOf p) [ "flake.lock" "Cargo.lock" ]))
(foldl' (dir: subd: /${dir}/${subd}) ./. subds);
};
}) (flakeSubdirs ./.) // mapAttrs (from: to:

View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
use flake

View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "hello"
version = "0.1.0"

View file

@ -0,0 +1,6 @@
[package]
name = "hello"
version = "0.1.0"
edition = "2024"
[dependencies]

View file

@ -0,0 +1,98 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1763938834,
"narHash": "sha256-j8iB0Yr4zAvQLueCZ5abxfk6fnG/SJ5JnGUziETjwfg=",
"owner": "ipetkov",
"repo": "crane",
"rev": "d9e753122e51cee64eb8d2dddfe11148f339f5a2",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1764226020,
"narHash": "sha256-FzUCFwXNjLnnZmVqYj/FjlBhUpat59SExflEaIGT62s=",
"owner": "nix-community",
"repo": "fenix",
"rev": "2d8176c02f7be6d13578d24d5fd5049f1b46a4c5",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1764138170,
"narHash": "sha256-2bCmfCUZyi2yj9FFXYKwsDiaZmizN75cLhI/eWmf3tk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "bb813de6d2241bcb1b5af2d3059f560c66329967",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"crane": "crane",
"fenix": "fenix",
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1764175386,
"narHash": "sha256-LfgFqvPz3C80VjaffSjy8lLyRWfbThhB7gE7IWXHjYU=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "71ddf07c1c75046df3bb496cf824de5c053d99ad",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"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",
"version": 7
}

View file

@ -0,0 +1,59 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
crane.url = "github:ipetkov/crane";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, systems, crane, fenix, ... }:
let
eachSystem = nixpkgs.lib.genAttrs (import systems);
fenixToolchain = "default";
in {
packages = eachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
toolchain = fenix.packages.${system}.${fenixToolchain}.toolchain;
in {
hello = pkgs.callPackage ./package.nix {
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
};
default = self.packages.${system}.hello;
});
devShells = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
default = import ./shell.nix { inherit pkgs crane fenix fenixToolchain; };
});
checks = eachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
toolchain = fenix.packages.${system}.${fenixToolchain}.toolchain;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
crate = self.packages.${system}.default;
in {
inherit crate;
clippy = craneLib.cargoClippy (
crate.commonArgs
// {
inherit (crate) cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
doc = craneLib.cargoDoc (
crate.commonArgs
// {
inherit (crate) cargoArtifacts;
env.RUSTDOCFLAGS = "--deny warnings";
}
);
});
};
}

View file

@ -0,0 +1,19 @@
{
craneLib,
}:
let
commonArgs = {
src = craneLib.cleanCargoSource ./.;
strictDeps = true;
buildInputs = [
# Additional runtime dependencies
];
passthru.commonArgs = commonArgs;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
crate = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; });
in crate

View file

@ -0,0 +1,12 @@
{ pkgs ? import <nixpkgs> {},
crane ? builtins.getFlake "github:ipetkov/crane",
fenix ? builtins.getFlake "github:nix-community/fenix",
fenixToolchain ? "default"
}:
let
fenixPkgs = fenix.packages.${pkgs.system};
toolchain = fenixPkgs.${fenixToolchain}.toolchain;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
in craneLib.devShell {
packages = [ fenixPkgs.rust-analyzer ];
}

View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, World!");
}

View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
use flake

View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "hello"
version = "0.1.0"

View file

@ -0,0 +1,6 @@
[package]
name = "hello"
version = "0.1.0"
edition = "2024"
[dependencies]

View file

@ -0,0 +1,82 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1764226020,
"narHash": "sha256-FzUCFwXNjLnnZmVqYj/FjlBhUpat59SExflEaIGT62s=",
"owner": "nix-community",
"repo": "fenix",
"rev": "2d8176c02f7be6d13578d24d5fd5049f1b46a4c5",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1764138170,
"narHash": "sha256-2bCmfCUZyi2yj9FFXYKwsDiaZmizN75cLhI/eWmf3tk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "bb813de6d2241bcb1b5af2d3059f560c66329967",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"fenix": "fenix",
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1764175386,
"narHash": "sha256-LfgFqvPz3C80VjaffSjy8lLyRWfbThhB7gE7IWXHjYU=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "71ddf07c1c75046df3bb496cf824de5c053d99ad",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"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",
"version": 7
}

View file

@ -0,0 +1,35 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, systems, fenix, ... }:
let
eachSystem = nixpkgs.lib.genAttrs (import systems);
fenixToolchain = "default";
in {
packages = eachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
toolchain = fenix.packages.${system}.${fenixToolchain}.toolchain;
in {
hello = pkgs.callPackage ./package.nix {
rustPlatform = pkgs.makeRustPlatform {
rustc = toolchain;
cargo = toolchain;
};
};
default = self.packages.${system}.hello;
});
devShells = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
default = import ./shell.nix { inherit pkgs fenix fenixToolchain; };
});
};
}

View file

@ -0,0 +1,12 @@
{
lib,
rustPlatform,
}:
rustPlatform.buildRustPackage {
pname = "hello";
version = "0.1";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
}

View file

@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> {},
fenix ? builtins.getFlake "github:nix-community/fenix",
fenixToolchain ? "default"
}:
let
inherit (pkgs) mkShellNoCC;
fenixPkgs = fenix.packages.${pkgs.system};
toolchain = fenixPkgs.${fenixToolchain}.toolchain;
in mkShellNoCC {
packages = [ toolchain fenixPkgs.rust-analyzer ];
}

View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, World!");
}

View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
use flake

7
rust/cargo-stable/crane/Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "hello"
version = "0.1.0"

View file

@ -0,0 +1,6 @@
[package]
name = "hello"
version = "0.1.0"
edition = "2024"
[dependencies]

59
rust/cargo-stable/crane/flake.lock generated Normal file
View file

@ -0,0 +1,59 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1763938834,
"narHash": "sha256-j8iB0Yr4zAvQLueCZ5abxfk6fnG/SJ5JnGUziETjwfg=",
"owner": "ipetkov",
"repo": "crane",
"rev": "d9e753122e51cee64eb8d2dddfe11148f339f5a2",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1764138170,
"narHash": "sha256-2bCmfCUZyi2yj9FFXYKwsDiaZmizN75cLhI/eWmf3tk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "bb813de6d2241bcb1b5af2d3059f560c66329967",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"crane": "crane",
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"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",
"version": 7
}

View file

@ -0,0 +1,52 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
crane.url = "github:ipetkov/crane";
};
outputs = { self, nixpkgs, systems, crane, ... }:
let eachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
hello = pkgs.callPackage ./package.nix {
craneLib = crane.mkLib pkgs;
};
default = self.packages.${system}.hello;
});
devShells = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
default = import ./shell.nix { inherit pkgs crane; };
});
checks = eachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
craneLib = crane.mkLib pkgs;
crate = self.packages.${system}.default;
in {
inherit crate;
clippy = craneLib.cargoClippy (
crate.commonArgs
// {
inherit (crate) cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
doc = craneLib.cargoDoc (
crate.commonArgs
// {
inherit (crate) cargoArtifacts;
env.RUSTDOCFLAGS = "--deny warnings";
}
);
});
};
}

View file

@ -0,0 +1,19 @@
{
craneLib,
}:
let
commonArgs = {
src = craneLib.cleanCargoSource ./.;
strictDeps = true;
buildInputs = [
# Additional runtime dependencies
];
passthru.commonArgs = commonArgs;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
crate = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; });
in crate

View file

@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> {},
crane ? builtins.getFlake "github:ipetkov/crane"
}:
let
inherit (pkgs)
rust-analyzer
;
in (crane.mkLib pkgs).devShell {
packages = [ rust-analyzer ];
}

View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, World!");
}

View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
use flake

7
rust/cargo-stable/nixpkgs/Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "hello"
version = "0.1.0"

View file

@ -0,0 +1,6 @@
[package]
name = "hello"
version = "0.1.0"
edition = "2024"
[dependencies]

43
rust/cargo-stable/nixpkgs/flake.lock generated Normal file
View file

@ -0,0 +1,43 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1764138170,
"narHash": "sha256-2bCmfCUZyi2yj9FFXYKwsDiaZmizN75cLhI/eWmf3tk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "bb813de6d2241bcb1b5af2d3059f560c66329967",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"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",
"version": 7
}

View file

@ -0,0 +1,23 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
};
outputs = { self, nixpkgs, systems, ... }:
let eachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
hello = pkgs.callPackage ./package.nix {};
default = self.packages.${system}.hello;
});
devShells = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
default = import ./shell.nix { inherit pkgs; };
});
};
}

View file

@ -0,0 +1,12 @@
{
lib,
rustPlatform,
}:
rustPlatform.buildRustPackage {
pname = "hello";
version = "0.1";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
}

View file

@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> {} }:
let inherit (pkgs)
mkShellNoCC
rustc
cargo
rust-analyzer
;
in mkShellNoCC {
packages = [ rustc cargo rust-analyzer ];
}

View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, World!");
}