0

On NixOS 23.05 I'm unable to use sanoid --monitor-* commands (--monitor-health, --monitor-capacity, --monitor-snapshots) on the CLI and in scripts.

This because the configuration file sanoid relies on (by default /etc/sanoid/sanoid.conf) doesn't exist. I know that the actual config file used by the sanoid service it's the one generated by the sanoid derivation, if I do systemctl cat sanoid I can see:

...
ExecStart='/nix/store/mfhah82mjcffc9y7hvx60gpdk2f0183h-sanoid-2.1.0/bin/sanoid' '--cron' '--configdir' '/nix/store/gggb1m057i9x7zqif5sfpv54j8j2hbn4-sanoid.conf'
...

If I do sanoid --monitor-health --configdir /nix/store/gggb1m057i9x7zqif5sfpv54j8j2hbn4-sanoid.conf the command behave as expected**. But I have a health-monitoring script relying on the sanoid --monitor-health &co commands...For what I can understand the sanoid.conf path will change on the next sanoid update, so it's rather inconvenient hard-coding that path in the scrip or linking /etc/sanoid to it. I was wondering if there is a nice way to handle this situation...

**: actually, sometimes it works, sometimes I have another error: mkdir /var/cache/sanoid: File exists at /nix/store/s71k9hy54qq4xgjkx6w7rcgkf6b8yq3n-sanoid-2.1.0/bin/.sanoid-wrapped line 55.

Lan Quil
  • 13
  • 8

1 Answers1

0

A partial solution is to add the script to the nixos config, picking out the exec line from the service definition at build time so that it'll continue to work over time

{ pkgs, config }: {
  config.environment.systemPackages = [
    (pkgs.writeShellScriptBin "monitor-sanoid"
      ''
        ${config.systemd.services.sanoid.serviceConfig.ExecStart} --monitor-health
      '')
  ];
}

(thanks to the awesome people in https://matrix.to/#/#nixnerds:jupiterbroadcasting.com for suggesting this)

Lan Quil
  • 13
  • 8