Skip to content

Commit

Permalink
go: add telemetry options
Browse files Browse the repository at this point in the history
  • Loading branch information
folliehiyuki authored and sumnerevans committed Jan 8, 2025
1 parent fcc4259 commit 54b330a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
39 changes: 39 additions & 0 deletions modules/programs/go.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ let

cfg = config.programs.go;

modeFileContent = "${cfg.telemetry.mode} ${cfg.telemetry.date}";

in {
meta.maintainers = [ maintainers.rvolosatovs ];

Expand Down Expand Up @@ -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.";
};
};
};

Expand Down Expand Up @@ -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;
};
})
]);
}
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ in import nmtSrc {
./modules/programs/git
./modules/programs/git-cliff
./modules/programs/git-credential-oauth
./modules/programs/go
./modules/programs/gpg
./modules/programs/gradle
./modules/programs/granted
Expand Down
1 change: 1 addition & 0 deletions tests/modules/programs/go/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ go-telemetry = ./go-telemetry.nix; }
25 changes: 25 additions & 0 deletions tests/modules/programs/go/go-telemetry.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ pkgs, ... }:

{
programs.go = {
enable = true;
telemetry = {
mode = "on";
date = "2006-01-02";
};
};

test.stubs.go = { };

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"
'';
}

0 comments on commit 54b330a

Please sign in to comment.