Skip to content

Commit

Permalink
Add removeScripts option to module
Browse files Browse the repository at this point in the history
  • Loading branch information
SFrijters committed Dec 12, 2024
1 parent 71c3ebe commit 72257f4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 39 deletions.
7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@
environment.systemPackages = [ pkgs.mailutils ];

services = {
logwatch.enable = true;
postfix.enable = true;
logwatch = {
enable = true;
removeScripts = [ "zz-network" ];
};
};

virtualisation.diskSize = 128; # MB
Expand Down Expand Up @@ -79,6 +82,8 @@
raise Exception("Missing text 'Logwatch ${
self.packages.${pkgs.system}.logwatch.src.rev
} in output of 'mail -p'")
if "Network statistics" in mail:
raise Exception("Network statistics should have been removed by removeScripts")
'';
};
});
Expand Down
9 changes: 8 additions & 1 deletion modules/logwatch.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ let
cfg = config.services.logwatch;
types = lib.types;

logwatch = pkgs.callPackage ../packages/logwatch.nix { journalCtlEntries = cfg.journalCtlEntries; };
logwatch = pkgs.callPackage ../packages/logwatch.nix {
inherit (cfg) journalCtlEntries removeScripts;
};

logwatchWithTemp = pkgs.writeShellApplication {
name = "logwatch";
Expand Down Expand Up @@ -69,6 +71,11 @@ in
type = types.listOf types.attrs;
description = "What to watch";
};
removeScripts = lib.mkOption {
default = [ ];
type = types.listOf types.str;
description = "Which default scripts to remove";
};
};

config = lib.mkIf cfg.enable {
Expand Down
83 changes: 46 additions & 37 deletions packages/logwatch.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
bzip2,
xz,
journalCtlEntries ? [ ],
removeScripts ? [ ],
}:
let
mkJournalCtlEntry =
Expand Down Expand Up @@ -92,48 +93,56 @@ stdenvNoCC.mkDerivation {
# Null log necessary to be able to use journalctl
echo -e "LogFile = logwatch-null.log" > $out/etc/logwatch/conf/logfiles/logwatch-null.conf
''
+ (lib.concatMapStrings mkJournalCtlEntry journalCtlEntries);

postFixup = ''
substituteInPlace $out/bin/logwatch \
--replace-fail "/usr/share" "$out/usr/share" \
--replace-fail "/etc/logwatch" "$out/etc/logwatch" \
--replace-fail "/usr/bin/perl" "${lib.getExe perl}" \
--replace-fail "/var/cache" "/tmp"
postFixup =
''
substituteInPlace $out/bin/logwatch \
--replace-fail "/usr/share" "$out/usr/share" \
--replace-fail "/etc/logwatch" "$out/etc/logwatch" \
--replace-fail "/usr/bin/perl" "${lib.getExe perl}" \
--replace-fail "/var/cache" "/tmp"
{
echo "TmpDir = /tmp/logwatch";
echo "mailer = \"${lib.getExe' postfix "sendmail"} -t\"";
echo "MailFrom = Logwatch"
} >> $out/usr/share/logwatch/default.conf/logwatch.conf
{
echo "TmpDir = /tmp/logwatch";
echo "mailer = \"${lib.getExe' postfix "sendmail"} -t\"";
echo "MailFrom = Logwatch"
} >> $out/usr/share/logwatch/default.conf/logwatch.conf
# Enable runtime stats
substituteInPlace $out/usr/share/logwatch/default.conf/services/zz-runtime.conf \
--replace-fail '#$show_uptime = 0' '$show_uptime = 1'
# Enable runtime stats
substituteInPlace $out/usr/share/logwatch/default.conf/services/zz-runtime.conf \
--replace-fail '#$show_uptime = 0' '$show_uptime = 1'
# Do not show unmatched entries; getting all messages from journalctl unit 'session*' contains a lot more stuff than only sudo
substituteInPlace $out/usr/share/logwatch/scripts/services/sudo \
--replace-fail "if (keys %OtherList) {" "if (0) {"
# Do not show unmatched entries; getting all messages from journalctl unit 'session*' contains a lot more stuff than only sudo
substituteInPlace $out/usr/share/logwatch/scripts/services/sudo \
--replace-fail "if (keys %OtherList) {" "if (0) {"
wrapProgram $out/bin/logwatch \
--prefix PERL5LIB : "${
with perlPackages;
makePerlPath [
DateManip
HTMLParser
SysCPU
SysMemInfo
]
}" \
--prefix PATH : "${
lib.makeBinPath [
nettools
gzip
bzip2
xz
]
}" \
--set pathto_ifconfig "${lib.getExe' nettools "ifconfig"}"
'';
''
+ (lib.concatMapStrings (
f: "rm $out/usr/share/logwatch/default.conf/services/${f}.conf;"
) removeScripts)
+ ''
wrapProgram $out/bin/logwatch \
--prefix PERL5LIB : "${
with perlPackages;
makePerlPath [
DateManip
HTMLParser
SysCPU
SysMemInfo
]
}" \
--prefix PATH : "${
lib.makeBinPath [
nettools
gzip
bzip2
xz
]
}" \
--set pathto_ifconfig "${lib.getExe' nettools "ifconfig"}"
'';
}

0 comments on commit 72257f4

Please sign in to comment.