1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 03:29:45 +01:00

go: add telemetry options

This commit is contained in:
Hoang Nguyen 2024-10-26 00:00:00 +07:00
parent 93435d27d2
commit 89ae191311
No known key found for this signature in database
GPG key ID: B0567C20730E9B11
4 changed files with 64 additions and 0 deletions

View file

@ -6,6 +6,8 @@ let
cfg = config.programs.go;
modeFileContent = "${cfg.telemetry.mode} ${cfg.telemetry.date}";
in {
meta.maintainers = [ maintainers.rvolosatovs ];
@ -71,6 +73,31 @@ in {
or checksum database.
'';
};
telemetry = mkOption {
type = types.submodule {
options = {
mode = mkOption {
type = with types; nullOr (enum [ "off" "local" "on" ]);
default = null;
description = "Go telemetry mode to be set.";
};
date = mkOption {
type = types.str;
default = "1970-01-01";
description = ''
The date indicating the date at which the modefile
was updated, in YYYY-MM-DD format. It's used to
reset the timeout before the next telemetry report
is uploaded when telemetry mode is set to "on".
'';
};
};
};
default = { };
description = "Options to configure Go telemetry mode.";
};
};
};
@ -98,5 +125,17 @@ in {
(mkIf (cfg.goPrivate != [ ]) {
home.sessionVariables.GOPRIVATE = concatStringsSep "," cfg.goPrivate;
})
(mkIf (cfg.telemetry.mode != null) {
home.file."Library/Application Support/go/telemetry/mode" = {
enable = pkgs.stdenv.hostPlatform.isDarwin;
text = modeFileContent;
};
xdg.configFile."go/telemetry/mode" = {
enable = !pkgs.stdenv.hostPlatform.isDarwin;
text = modeFileContent;
};
})
]);
}

View file

@ -81,6 +81,7 @@ in import nmtSrc {
./modules/programs/gh-dash
./modules/programs/git
./modules/programs/git-cliff
./modules/programs/go
./modules/programs/gpg
./modules/programs/gradle
./modules/programs/granted

View file

@ -0,0 +1 @@
{ go-telemetry = ./go-telemetry.nix; }

View file

@ -0,0 +1,23 @@
{ pkgs, ... }:
{
programs.go = {
enable = true;
telemetry = {
mode = "on";
date = "2006-01-02";
};
};
nm.script = let
modeFileDir = if !pkgs.stdenv.isDarwin then
".config/go/telemetry"
else
"Library/Application Support/go/telemetry";
in ''
assertFileExists "home-files/${modeFileDir}/mode"
assertFileContent \
"home-files/${modeFileDir}/mode" \
"on 2006-01-02"
'';
}