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
9 changes: 9 additions & 0 deletions modules/misc/news/2025/11/2025-11-26_06-33-49.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
time = "2025-11-26T05:33:49+00:00";
condition = true;
message = ''
A new module is available: 'programs.cargo'.

cargo is the build system and package manager of Rust.
'';
}
43 changes: 43 additions & 0 deletions modules/programs/cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib) mkEnableOption;

tomlFormat = pkgs.formats.toml { };

cfg = config.programs.cargo;
in
{
meta.maintainers = [ lib.maintainers.friedrichaltheide ];

options = {
programs = {
cargo = {
enable = mkEnableOption "management of cargo config";

settings = lib.mkOption {
inherit (tomlFormat) type;
default = { };
description = ''
Available configuration options for the .cargo/config see:
https://doc.rust-lang.org/cargo/reference/config.html
'';
};
};
};
};

config = lib.mkIf cfg.enable {
home = {
file = {
".cargo/config.toml" = {
source = tomlFormat.generate "config.toml" cfg.settings;
};
};
};
};
}
4 changes: 4 additions & 0 deletions tests/modules/programs/cargo/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
cargo = ./example-config.nix;
cargo-empty-config = ./empty-config.nix;
}
14 changes: 14 additions & 0 deletions tests/modules/programs/cargo/empty-config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
programs.docker-cli = {
settings = {
net = {
git-fetch-with-cli = true;
};
};
};

nmt.script = ''
assertPathNotExists home-files/.cargo/config
assertPathNotExists home-files/.cargo/config.toml
'';
}
22 changes: 22 additions & 0 deletions tests/modules/programs/cargo/example-config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
programs.cargo = {
enable = true;

settings = {
net = {
git-fetch-with-cli = true;
};
};
};

nmt.script =
let
configTestPath = "home-files/.cargo/config.toml";
in
''
assertPathNotExists home-files/.cargo/config
assertFileExists ${configTestPath}
assertFileContent ${configTestPath} \
${./example-config.toml}
'';
}
2 changes: 2 additions & 0 deletions tests/modules/programs/cargo/example-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[net]
git-fetch-with-cli = true