From 29b42bd7310ff6a7f33bdd98944dfcf52fa7b0cc Mon Sep 17 00:00:00 2001 From: bstanderline <153822813+bstanderline@users.noreply.github.com> Date: Wed, 1 Jan 2025 15:46:11 +0000 Subject: [PATCH 1/3] nixos/osquery: fix database_path + logger_path opts per systemd docs nixos/osquery: Update tests with option changes --- nixos/modules/services/monitoring/osquery.nix | 12 ++++++------ nixos/tests/osquery.nix | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/monitoring/osquery.nix b/nixos/modules/services/monitoring/osquery.nix index fbe6f45b9d8e..2b14c2dd89fb 100644 --- a/nixos/modules/services/monitoring/osquery.nix +++ b/nixos/modules/services/monitoring/osquery.nix @@ -63,16 +63,16 @@ in freeformType = attrsOf str; options = { database_path = lib.mkOption { - default = "/var/lib/osquery/osquery.db"; + default = "osquery/osquery.db"; readOnly = true; - description = "Path used for the database file."; - type = path; + description = "Path used for the database file, relative to /var/lib/."; + type = nonEmptyStr; }; logger_path = lib.mkOption { - default = "/var/log/osquery"; + default = "osquery"; readOnly = true; - description = "Base directory used for logging."; - type = path; + description = "Base directory used for logging, relative to /var/log/."; + type = nonEmptyStr; }; pidfile = lib.mkOption { default = "/run/osquery/osqueryd.pid"; diff --git a/nixos/tests/osquery.nix b/nixos/tests/osquery.nix index 5faf2f343740..0943284d7854 100644 --- a/nixos/tests/osquery.nix +++ b/nixos/tests/osquery.nix @@ -53,7 +53,7 @@ import ./make-test-python.nix ( machine.succeed("echo 'SELECT value FROM osquery_flags WHERE name = \"nullvalue\";' | osqueryi | tee /dev/console | grep -q ${nullvalue}") # Module creates directories for default database_path and pidfile flag values. - machine.succeed("test -d $(dirname ${cfg.flags.database_path})") + machine.succeed("test -d $(dirname /var/lib/${cfg.flags.database_path})") machine.succeed("test -d $(dirname ${cfg.flags.pidfile})") ''; } From d784db18f2df77b415912a4eb4dc003ba3dafbf2 Mon Sep 17 00:00:00 2001 From: bstanderline <153822813+bstanderline@users.noreply.github.com> Date: Tue, 4 Mar 2025 09:40:31 +0000 Subject: [PATCH 2/3] nixos/osquery: set default database_path and logger_path --- nixos/modules/services/monitoring/osquery.nix | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/nixos/modules/services/monitoring/osquery.nix b/nixos/modules/services/monitoring/osquery.nix index 2b14c2dd89fb..003407626c8a 100644 --- a/nixos/modules/services/monitoring/osquery.nix +++ b/nixos/modules/services/monitoring/osquery.nix @@ -63,16 +63,30 @@ in freeformType = attrsOf str; options = { database_path = lib.mkOption { - default = "osquery/osquery.db"; + default = "/var/lib/osquery/osquery.db"; readOnly = true; - description = "Path used for the database file, relative to /var/lib/."; - type = nonEmptyStr; + description = '' + Path used for the database file. + + ::: {.note} + If left as the default value, this directory will be automatically created before the + service starts, otherwise you are responsible for ensuring the directory exists with + the appropriate ownership and permissions. + ''; + type = path; }; logger_path = lib.mkOption { - default = "osquery"; + default = "/var/log/osquery"; readOnly = true; - description = "Base directory used for logging, relative to /var/log/."; - type = nonEmptyStr; + description = '' + Base directory used for logging. + + ::: {.note} + If left as the default value, this directory will be automatically created before the + service starts, otherwise you are responsible for ensuring the directory exists with + the appropriate ownership and permissions. + ''; + type = path; }; pidfile = lib.mkOption { default = "/run/osquery/osqueryd.pid"; @@ -96,8 +110,8 @@ in serviceConfig = { ExecStart = "${pkgs.osquery}/bin/osqueryd --flagfile ${flagfile}"; PIDFile = cfg.flags.pidfile; - LogsDirectory = cfg.flags.logger_path; - StateDirectory = dirname cfg.flags.database_path; + LogsDirectory = lib.mkIf (cfg.flags.logger_path == "/var/log/osquery") [ "osquery" ]; + StateDirectory = lib.mkIf (cfg.flags.database_path == "/var/lib/osquery/osquery.db") [ "osquery" ]; Restart = "always"; }; wantedBy = [ "multi-user.target" ]; From e0ac5194ab67c0b7230957d67ecdd6b3e64fadf6 Mon Sep 17 00:00:00 2001 From: bstanderline <153822813+bstanderline@users.noreply.github.com> Date: Tue, 4 Mar 2025 11:45:23 +0000 Subject: [PATCH 3/3] nixos/osquery: revert test for database_path --- nixos/tests/osquery.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/tests/osquery.nix b/nixos/tests/osquery.nix index 0943284d7854..5faf2f343740 100644 --- a/nixos/tests/osquery.nix +++ b/nixos/tests/osquery.nix @@ -53,7 +53,7 @@ import ./make-test-python.nix ( machine.succeed("echo 'SELECT value FROM osquery_flags WHERE name = \"nullvalue\";' | osqueryi | tee /dev/console | grep -q ${nullvalue}") # Module creates directories for default database_path and pidfile flag values. - machine.succeed("test -d $(dirname /var/lib/${cfg.flags.database_path})") + machine.succeed("test -d $(dirname ${cfg.flags.database_path})") machine.succeed("test -d $(dirname ${cfg.flags.pidfile})") ''; }