diff --git a/modules/misc/news/2025/11/2025-11-26_06-33-49.nix b/modules/misc/news/2025/11/2025-11-26_06-33-49.nix new file mode 100644 index 00000000..ee5a3515 --- /dev/null +++ b/modules/misc/news/2025/11/2025-11-26_06-33-49.nix @@ -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. + ''; +} diff --git a/modules/programs/cargo.nix b/modules/programs/cargo.nix new file mode 100644 index 00000000..3b83b909 --- /dev/null +++ b/modules/programs/cargo.nix @@ -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; + }; + }; + }; + }; +} diff --git a/tests/modules/programs/cargo/default.nix b/tests/modules/programs/cargo/default.nix new file mode 100644 index 00000000..34280847 --- /dev/null +++ b/tests/modules/programs/cargo/default.nix @@ -0,0 +1,4 @@ +{ + cargo = ./example-config.nix; + cargo-empty-config = ./empty-config.nix; +} diff --git a/tests/modules/programs/cargo/empty-config.nix b/tests/modules/programs/cargo/empty-config.nix new file mode 100644 index 00000000..78aa00f8 --- /dev/null +++ b/tests/modules/programs/cargo/empty-config.nix @@ -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 + ''; +} diff --git a/tests/modules/programs/cargo/example-config.nix b/tests/modules/programs/cargo/example-config.nix new file mode 100644 index 00000000..7a14fc2a --- /dev/null +++ b/tests/modules/programs/cargo/example-config.nix @@ -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} + ''; +} diff --git a/tests/modules/programs/cargo/example-config.toml b/tests/modules/programs/cargo/example-config.toml new file mode 100644 index 00000000..c91c3f38 --- /dev/null +++ b/tests/modules/programs/cargo/example-config.toml @@ -0,0 +1,2 @@ +[net] +git-fetch-with-cli = true