autotier: init at 1.2.0

This commit is contained in:
Philip Wilk 2025-01-31 22:55:44 +00:00
parent 9c4822421b
commit eb40871602
No known key found for this signature in database
3 changed files with 98 additions and 0 deletions

View File

@ -95,6 +95,8 @@
- [Bat](https://github.com/sharkdp/bat), a {manpage}`cat(1)` clone with wings. Available as [programs.bat](options.html#opt-programs.bat).
- [Autotier](https://github.com/45Drives/autotier), a passthrough FUSE filesystem. Available as [services.autotierfs](options.html#opt-services.autotierfs.enable).
- [µStreamer](https://github.com/pikvm/ustreamer), a lightweight MJPEG-HTTP streamer. Available as [services.ustreamer](options.html#opt-services.ustreamer).
- [Whoogle Search](https://github.com/benbusby/whoogle-search), a self-hosted, ad-free, privacy-respecting metasearch engine. Available as [services.whoogle-search](options.html#opt-services.whoogle-search.enable).

View File

@ -417,6 +417,7 @@
./services/audio/squeezelite.nix
./services/audio/tts.nix
./services/audio/ympd.nix
./services/autotierfs.nix
./services/backup/automysqlbackup.nix
./services/backup/bacula.nix
./services/backup/borgbackup.nix

View File

@ -0,0 +1,95 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.autotierfs;
ini = pkgs.formats.ini { };
format = lib.types.attrsOf ini.type;
stateDir = "/var/lib/autotier";
generateConfigName =
name: builtins.replaceStrings [ "/" ] [ "-" ] (lib.strings.removePrefix "/" name);
configFiles = builtins.mapAttrs (
name: val: ini.generate "${generateConfigName name}.conf" val
) cfg.settings;
getMountDeps =
settings: builtins.concatStringsSep " " (builtins.catAttrs "Path" (builtins.attrValues settings));
mountPaths = builtins.attrNames cfg.settings;
in
{
options.services.autotierfs = {
enable = lib.mkEnableOption "the autotier passthrough tiering filesystem";
package = lib.mkPackageOption pkgs "autotier" { };
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = format;
};
default = { };
description = ''
The contents of the configuration file for autotier.
See the [autotier repo](https://github.com/45Drives/autotier#configuration) for supported values.
'';
example = lib.literalExpression ''
{
"/mnt/autotier" = {
Global = {
"Log Level" = 1;
"Tier Period" = 1000;
"Copy Buffer Size" = "1 MiB";
};
"Tier 1" = {
Path = "/mnt/tier1";
Quota = "30GiB";
};
"Tier 2" = {
Path = "/mnt/tier2";
Quota = "200GiB";
};
};
}
'';
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.settings != { };
message = "`services.autotierfs.settings` must be configured.";
}
];
system.fsPackages = [ cfg.package ];
# Not necessary for module to work but makes it easier to pass config into cli
environment.etc = lib.attrsets.mapAttrs' (
name: value:
lib.attrsets.nameValuePair "autotier/${(generateConfigName name)}.conf" { source = value; }
) configFiles;
systemd.tmpfiles.rules = (map (path: "d ${path} 0770 - autotier - -") mountPaths) ++ [
"d ${stateDir} 0774 - autotier - -"
];
users.groups.autotier = { };
systemd.services = lib.attrsets.mapAttrs' (
path: values:
lib.attrsets.nameValuePair (generateConfigName path) {
description = "Mount autotierfs virtual path ${path}";
unitConfig.RequiresMountsFor = getMountDeps values;
wantedBy = [ "local-fs.target" ];
serviceConfig = {
Type = "forking";
ExecStart = "${lib.getExe' cfg.package "autotierfs"} -c /etc/autotier/${generateConfigName path}.conf ${path} -o allow_other,default_permissions";
ExecStop = "umount ${path}";
};
}
) cfg.settings;
};
}