1{ config, pkgs, lib, ... }: 2 3let 4 inherit (lib) mkOption mkIf; 5 6 cfg = config.services.openafsClient; 7 8 cellServDB = pkgs.fetchurl { 9 url = http://dl.central.org/dl/cellservdb/CellServDB.2009-06-29; 10 sha256 = "be566f850e88130333ab8bc3462872ad90c9482e025c60a92f728b5bac1b4fa9"; 11 }; 12 13 afsConfig = pkgs.runCommand "afsconfig" {} '' 14 mkdir -p $out 15 echo ${cfg.cellName} > $out/ThisCell 16 cp ${cellServDB} $out/CellServDB 17 echo "/afs:${cfg.cacheDirectory}:${cfg.cacheSize}" > $out/cacheinfo 18 ''; 19 20 openafsPkgs = config.boot.kernelPackages.openafsClient; 21in 22{ 23 ###### interface 24 25 options = { 26 27 services.openafsClient = { 28 29 enable = mkOption { 30 default = false; 31 description = "Whether to enable the OpenAFS client."; 32 }; 33 34 cellName = mkOption { 35 default = "grand.central.org"; 36 description = "Cell name."; 37 }; 38 39 cacheSize = mkOption { 40 default = "100000"; 41 description = "Cache size."; 42 }; 43 44 cacheDirectory = mkOption { 45 default = "/var/cache/openafs"; 46 description = "Cache directory."; 47 }; 48 49 crypt = mkOption { 50 default = false; 51 description = "Whether to enable (weak) protocol encryption."; 52 }; 53 54 sparse = mkOption { 55 default = false; 56 description = "Minimal cell list in /afs."; 57 }; 58 59 }; 60 }; 61 62 63 ###### implementation 64 65 config = mkIf cfg.enable { 66 67 environment.systemPackages = [ openafsPkgs ]; 68 69 environment.etc = [ 70 { source = afsConfig; 71 target = "openafs"; 72 } 73 ]; 74 75 jobs.openafsClient = 76 { name = "afsd"; 77 78 description = "AFS client"; 79 80 startOn = "started network-interfaces"; 81 stopOn = "stopping network-interfaces"; 82 83 preStart = '' 84 mkdir -p -m 0755 /afs 85 mkdir -m 0700 -p ${cfg.cacheDirectory} 86 ${pkgs.module_init_tools}/sbin/insmod ${openafsPkgs}/lib/openafs/libafs-*.ko || true 87 ${openafsPkgs}/sbin/afsd -confdir ${afsConfig} -cachedir ${cfg.cacheDirectory} ${if cfg.sparse then "-dynroot-sparse" else "-dynroot"} -fakestat -afsdb 88 ${openafsPkgs}/bin/fs setcrypt ${if cfg.crypt then "on" else "off"} 89 ''; 90 91 # Doing this in preStop, because after these commands AFS is basically 92 # stopped, so systemd has nothing to do, just noticing it. If done in 93 # postStop, then we get a hang + kernel oops, because AFS can't be 94 # stopped simply by sending signals to processes. 95 preStop = '' 96 ${pkgs.utillinux}/bin/umount /afs 97 ${openafsPkgs}/sbin/afsd -shutdown 98 ${pkgs.module_init_tools}/sbin/rmmod libafs 99 ''; 100 101 }; 102 103 }; 104 105}