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

nixos/hddtemp: add support for HDD/SSD temperature montoring #111383

Merged
merged 2 commits into from Feb 1, 2021

Conversation

peterhoeg
Copy link
Member

Motivation for this change

Basic module for temperature monitoring + some minor hddtemp cleanups while at it.

The module does a few things:

  1. enables you to add drive database entries
  2. resolves drive symlinks which is needed if you want to pass a drive by-path as hddtemp chokes on colons
  3. because we run this from a wrapper script, we can pass wildcards for the drives which is otherwise not possible directly using ExecStart.
  4. limits the permissions somewhat

Ideally we lock this down properly with DynamicUser = true; but the problem is permissions needed to fetch SMART data which doesn't seem doable with the existing capabilities.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

stdenv.mkDerivation rec {
pname = "hddtemp";
version = "0.3_beta15";

src = fetchurl {
url = "mirror://savannah/hddtemp/hddtemp-0.3-beta15.tar.bz2";
Copy link
Member

Choose a reason for hiding this comment

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

Minor thing: You could also tie this to version.

Suggested change
url = "mirror://savannah/hddtemp/hddtemp-0.3-beta15.tar.bz2";
url = "mirror://savannah/hddtemp/hddtemp-${builtins.replaceStrings [ "_" ] [ "-" ] version}.tar.bz2";

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. There's actually no reason why the version should have an underscore to begin with, so I fixed that up instead.

@peterhoeg
Copy link
Member Author

@GrahamcOfBorg build hddtemp

Copy link
Member

@sternenseemann sternenseemann left a comment

Choose a reason for hiding this comment

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

LGTM apart from a few escaping improvements.

cp ${pkgs.hddtemp}/share/hddtemp/hddtemp.db $file
${lib.concatMapStringsSep "\n" (e: "echo '${e}' >> $file") cfg.dbEntries}

exec ${pkgs.hddtemp}/bin/hddtemp ${lib.concatStringsSep " " cfg.extraArgs} \
Copy link
Member

Choose a reason for hiding this comment

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

Consider using lib.escapeShellArgs which would prevent users from accidentally messing up the command line. Idk if there may be a genuine use for variables or something here though.

Suggested change
exec ${pkgs.hddtemp}/bin/hddtemp ${lib.concatStringsSep " " cfg.extraArgs} \
exec ${pkgs.hddtemp}/bin/hddtemp ${lib.escapeShellArgs cfg.extraArgs} \

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point regd escaping - all sorted


options = {
hardware.sensor.hddtemp = {
enable = mkOption {
Copy link
Member

Choose a reason for hiding this comment

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

You could also use mkEnableOption here.


file=/var/lib/hddtemp/hddtemp.db

drives=(${toString (map (e: ''$(realpath "${e}") '') cfg.drives)})
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
drives=(${toString (map (e: ''$(realpath "${e}") '') cfg.drives)})
drives=(${toString (map (e: ''$(realpath ${lib.escapeShellArg e}) '') cfg.drives)})

drives=(${toString (map (e: ''$(realpath "${e}") '') cfg.drives)})

cp ${pkgs.hddtemp}/share/hddtemp/hddtemp.db $file
${lib.concatMapStringsSep "\n" (e: "echo '${e}' >> $file") cfg.dbEntries}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
${lib.concatMapStringsSep "\n" (e: "echo '${e}' >> $file") cfg.dbEntries}
${lib.concatMapStringsSep "\n" (e: "echo ${lib.escapeShellArg e} >> $file") cfg.dbEntries}

@SuperSandro2000
Copy link
Member

This is a semi-automatic executed nixpkgs-review with nixpkgs-review-checks extension. It is checked by a human on a best effort basis and does not build all packages (e.g. lumo, tensorflow or pytorch).
If you have any questions or problems please reach out to SuperSandro2000 on IRC.

Result of nixpkgs-review pr 111383 run on x86_64-linux 1

1 package blacklisted:
  • tests.nixos-functions.nixos-test
3 packages built:
  • glances
  • hddtemp
  • xfce.xfce4-sensors-plugin (xfce.xfce4_sensors_plugin)

Copy link
Member

@sternenseemann sternenseemann left a comment

Choose a reason for hiding this comment

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

LGTM

@peterhoeg peterhoeg merged commit 65211f5 into NixOS:master Feb 1, 2021
@peterhoeg peterhoeg deleted the m/hddtemp branch February 1, 2021 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants