Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nist-feed: init at 0-unstable-2024-01-20 #284812

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
4 changes: 4 additions & 0 deletions nixos/doc/manual/release-notes/rl-2405.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m

- [TuxClocker](https://github.com/Lurkki14/tuxclocker), a hardware control and monitoring program. Available as [programs.tuxclocker](#opt-programs.tuxclocker.enable).

<<<<<<< HEAD
- [NIST-Feed](https://github.com/d3vil0p3r/nist-feed), notifies you about the newest published CVEs from NIST. Available as [programs.nist-feed](#opt-programs.nist-feed.enable).
=======
- [ALVR](https://github.com/alvr-org/alvr), a VR desktop streamer. Available as [programs.alvr](#opt-programs.alvr.enable)
>>>>>>> master
Comment on lines +74 to +78
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a conflict left over here


- [RustDesk](https://rustdesk.com), a full-featured open source remote control alternative for self-hosting and security with minimal configuration. Alternative to TeamViewer.

Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
./programs/neovim.nix
./programs/nethoscope.nix
./programs/nexttrace.nix
./programs/nist-feed.nix
./programs/nix-index.nix
./programs/nix-ld.nix
./programs/nm-applet.nix
Expand Down
54 changes: 54 additions & 0 deletions nixos/modules/programs/nist-feed.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{ config, lib, pkgs, ... }:

with lib;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with lib;

Bad practice that's now discouraged in nixpkgs.
Tracking issue: #208242


let
cfg = config.programs.nist-feed;
in
{
options = {
programs.nist-feed = {
enable = mkEnableOption (mdDoc "NIST Feed, which notifies you about the newest published CVEs");
package = mkPackageOption pkgs "nist-feed" { };
extraArgs = mkOption {
type = with types; listOf str;
default = [ "-l" "-s" "CRITICAL" ];
description = mdDoc ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = mdDoc ''
description = ''

lib.mdDoc is no longer present in nixpkgs; please remove all usages.

Arguments to provide to NIST-Feed, see a full list at
<https://github.com/D3vil0p3r/NIST-Feed/blob/main/README.md#nist-feed>
'';
};

onCalendar = mkOption {
type = types.str;
default = "*:0/30";
description = mdDoc ''
How often NIST-Feed executes.
'';
};
};
};

config = mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
systemd.user.services.nist-feed = {
wantedBy = [ "default.target" ];
description = "A notification daemon for CVEs";
serviceConfig = {
Type = "oneshot";
ExecStart = "${cfg.package}/bin/nist-feed ${escapeShellArgs cfg.extraArgs}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ExecStart = "${cfg.package}/bin/nist-feed ${escapeShellArgs cfg.extraArgs}";
ExecStart = "${lib.getExe cfg.package} ${escapeShellArgs cfg.extraArgs}";

};
};

systemd.user.timers.nist-feed = {
wantedBy = [ "default.target" ];
timerConfig = {
Unit = "nist-feed.service";
OnCalendar = cfg.onCalendar;
Persistent = "true";
};
};
};

meta.maintainers = with maintainers; [octodi];
}
56 changes: 56 additions & 0 deletions pkgs/by-name/ni/nist-feed/cron.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--- a/nist-feed 2024-01-28 19:03:44.721621784 +0530
+++ b/nist-feed 2024-01-29 18:58:25.981732803 +0530
@@ -1,7 +1,5 @@
#!/bin/sh

-pkill -f "/usr/bin/gjs /usr/share/gnome-shell/org.gnome.Shell.Notifications"
-
############################################################
# Colors #
############################################################
@@ -67,7 +65,7 @@
echo "-i Filter by integrity metric (NONE='I:N', LOW='I:L' or HIGH='I:H')."
echo "-l Retrieve the latest CVE according to the filters."
echo "-m Filter by the specified CVSSv3 metric codes. It is used mainly for managing all filters selected by the user when the notification popup must be created."
- echo "-n Enable desktop notification for the latest CVE according the applied filters by crontab."
+ echo "-n Notification option has been removed for nix, to enable notifications use programs.nist-feed.enable = true; "
echo "-P Filter by privileges required metric (NONE='PR:N', LOW='PR:L' or HIGH='PR:H')."
echo "-r Specify the maximum number of results that are returned based on the request parameters. The default value is 20. For network considerations, maximum allowable limit is 2,000."
echo "-S Filter by scope metric (UNCHANGED='S:U' or CHANGED='S:C')."
@@ -237,7 +235,6 @@

if [ "$end" ]; then
echo "Disabling NIST NVD feed popup notification..."
- crontab -l | sed '/nist-feed/d' | crontab
rm -rf $last_cve_file
rm -rf $cve_json_file
exit 0
@@ -336,27 +333,13 @@
fi
fi

-if [[ "$id" != "$LAST_CVE" ]] || [ $(crontab -l | wc -c) -eq 0 ];then #if the previous CVE is different from the current one, OR the crontab is empty, popup notification
+if [[ "$id" != "$LAST_CVE" ]];then #if the previous CVE is different from the current one, OR the crontab is empty, popup notification
if [[ ! "$notify" ]]; then #LAST_CVE must be set only if the user does not set the notification parameters, otherwise when crontab will call the 1st time nist-feed, $id is already = to $LAST_CVE
echo "$id" > $last_cve_file
#Generate the popup notification
killall dunst;notify-send -u normal "$id" "$description\n\n<b>$nvdURL</b>"
fi

- if [[ "$notify" -eq 1 ]] && [ ! "$severity" ] && [ ! "$metric" ]; then
- crontab -l | sed '/nist-feed/d' | crontab
- (crontab -l 2>/dev/null; echo "*/30 * * * * ( killall dunst ; XDG_RUNTIME_DIR=/run/user/$(id -u) /usr/local/bin/nist-feed -l)") | crontab -
- elif [[ "$notify" -eq 1 ]] && [ "$severity" ] && [ ! "$metric" ]; then
- crontab -l | sed '/nist-feed/d' | crontab
- (crontab -l 2>/dev/null; echo "*/30 * * * * ( killall dunst ; XDG_RUNTIME_DIR=/run/user/$(id -u) /usr/local/bin/nist-feed -l -s $severity)") | crontab -
- elif [[ "$notify" -eq 1 ]] && [ ! "$severity" ] && [ "$metric" ]; then
- crontab -l | sed '/nist-feed/d' | crontab
- (crontab -l 2>/dev/null; echo "*/30 * * * * ( killall dunst ; XDG_RUNTIME_DIR=/run/user/$(id -u) /usr/local/bin/nist-feed -l -m $metric)") | crontab -
- elif [[ "$notify" -eq 1 ]] && [ "$severity" ] && [ "$metric" ]; then
- crontab -l | sed '/nist-feed/d' | crontab
- (crontab -l 2>/dev/null; echo "*/30 * * * * ( killall dunst ; XDG_RUNTIME_DIR=/run/user/$(id -u) /usr/local/bin/nist-feed -l -s $severity -m $metric)") | crontab -
- fi
-
fi

rm -rf $cve_json_file
50 changes: 50 additions & 0 deletions pkgs/by-name/ni/nist-feed/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{ stdenvNoCC
, lib
, fetchFromGitHub
, makeWrapper
, bash
, jq
, killall
, libnotify
, curl
, busybox
}:

stdenvNoCC.mkDerivation {
pname = "nist-feed";
version = "0-unstable-2024-01-20";

src = fetchFromGitHub {
owner = "D3vil0p3r";
repo = "NIST-Feed";
rev = "775bd871490b680784a1855cdc1d4958a83a7866";
hash = "sha256-OcVf766q7vELYkGOEzQMLS6zH8Nn96ibGP+6kizHN28=";
};

patches = [
./cron.patch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the name of this patch could be a bit more descriptive?

remove-cronjob-instantiation-feature.patch or something along those lines?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should definitely have a comment explaining why it's needed and/or why it couldn't be upstreamed

];

nativeBuildInputs = [ makeWrapper ];

postPatch = ''
substituteInPlace nist-feed \
--replace "/usr/local/bin/nist-feed" $out/bin/nist-feed
'';

installPhase = ''
runHook preInstall
install -Dm555 nist-feed $out/bin/nist-feed
wrapProgram "$out/bin/nist-feed" \
--prefix PATH : "$out/bin:${lib.makeBinPath [ jq killall libnotify curl busybox ]}"
runHook postInstall
'';

meta = with lib; {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
meta = with lib; {
meta = {

Tracking issue: #292468

description = "Notification daemon for CVEs from the NIST National Vulnerability Database";
homepage = "https://github.com/D3vil0p3r/NIST-Feed/";
license = licenses.gpl3Plus;
maintainers = with maintainers; [ octodi ];
Comment on lines +46 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
license = licenses.gpl3Plus;
maintainers = with maintainers; [ octodi ];
license = lib.licenses.gpl3Plus;
maintainers = with lib.maintainers; [ octodi ];

mainProgram = "nist-feed";
};
}
Loading