From 89ae1913110ef5fcd41584c529a3ed13584c3538 Mon Sep 17 00:00:00 2001 From: Hoang Nguyen Date: Sat, 26 Oct 2024 00:00:00 +0700 Subject: [PATCH] go: add telemetry options --- modules/programs/go.nix | 39 ++++++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/go/default.nix | 1 + tests/modules/programs/go/go-telemetry.nix | 23 +++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 tests/modules/programs/go/default.nix create mode 100644 tests/modules/programs/go/go-telemetry.nix diff --git a/modules/programs/go.nix b/modules/programs/go.nix index 5d150036b..19b63eae3 100644 --- a/modules/programs/go.nix +++ b/modules/programs/go.nix @@ -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; + }; + }) ]); } diff --git a/tests/default.nix b/tests/default.nix index f4b03275b..d2c1a4390 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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 diff --git a/tests/modules/programs/go/default.nix b/tests/modules/programs/go/default.nix new file mode 100644 index 000000000..cbf58092d --- /dev/null +++ b/tests/modules/programs/go/default.nix @@ -0,0 +1 @@ +{ go-telemetry = ./go-telemetry.nix; } diff --git a/tests/modules/programs/go/go-telemetry.nix b/tests/modules/programs/go/go-telemetry.nix new file mode 100644 index 000000000..b5fda3d3a --- /dev/null +++ b/tests/modules/programs/go/go-telemetry.nix @@ -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" + ''; +}