storage-box.nix (1972B)
1 { 2 config, 3 lib, 4 pkgs, 5 ... 6 }: let 7 cfg = config.services.haravara.storage-box; 8 in { 9 options.services.haravara.storage-box = { 10 enable = lib.mkEnableOption "Hetzner Storage Box mount"; 11 12 username = lib.mkOption { 13 type = lib.types.str; 14 description = "Hetzner Storage Box username"; 15 }; 16 17 hostname = lib.mkOption { 18 type = lib.types.str; 19 description = "Hetzner Storage Box hostname (e.g. <user>.your-storagebox.de)"; 20 }; 21 22 passwordFile = lib.mkOption { 23 type = lib.types.path; 24 description = "Path to a file containing CIFS credentials (formatted as username=... and password=...)"; 25 }; 26 27 mountPoint = lib.mkOption { 28 type = lib.types.str; 29 description = "Local mount point for the storage box"; 30 }; 31 32 share = lib.mkOption { 33 type = lib.types.str; 34 default = 35 if lib.hasInfix "-sub" cfg.username 36 then cfg.username 37 else "backup"; 38 description = "Remote share name (defaults to username for sub-accounts, otherwise 'backup')"; 39 }; 40 41 uid = lib.mkOption { 42 type = lib.types.int; 43 default = 0; 44 description = "Owner UID of the mount"; 45 }; 46 47 gid = lib.mkOption { 48 type = lib.types.int; 49 default = 0; 50 description = "Owner GID of the mount"; 51 }; 52 }; 53 54 config = lib.mkIf cfg.enable { 55 environment.systemPackages = [pkgs.cifs-utils]; 56 57 systemd.tmpfiles.rules = [ 58 "d ${cfg.mountPoint} - - - -" 59 ]; 60 61 fileSystems."${cfg.mountPoint}" = { 62 device = "//${cfg.hostname}/${cfg.share}"; 63 fsType = "cifs"; 64 options = [ 65 "credentials=${cfg.passwordFile}" 66 "iocharset=utf8" 67 "rw" 68 "file_mode=0770" 69 "dir_mode=0770" 70 "uid=${toString cfg.uid}" 71 "gid=${toString cfg.gid}" 72 "noperm" 73 "vers=3.0" 74 "mfsymlinks" 75 "_netdev" 76 "seal" 77 "nofail" 78 "x-systemd.automount" 79 "noauto" 80 ]; 81 }; 82 }; 83 }