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 systemd.services.afsd = { 76 description = "AFS client"; 77 wantedBy = [ "multi-user.target" ]; 78 after = [ "network-interfaces.target" ]; 79 80 preStart = '' 81 mkdir -p -m 0755 /afs 82 mkdir -m 0700 -p ${cfg.cacheDirectory} 83 ${pkgs.module_init_tools}/sbin/insmod ${openafsPkgs}/lib/openafs/libafs-*.ko || true 84 ${openafsPkgs}/sbin/afsd -confdir ${afsConfig} -cachedir ${cfg.cacheDirectory} ${if cfg.sparse then "-dynroot-sparse" else "-dynroot"} -fakestat -afsdb 85 ${openafsPkgs}/bin/fs setcrypt ${if cfg.crypt then "on" else "off"} 86 ''; 87 88 # Doing this in preStop, because after these commands AFS is basically 89 # stopped, so systemd has nothing to do, just noticing it. If done in 90 # postStop, then we get a hang + kernel oops, because AFS can't be 91 # stopped simply by sending signals to processes. 92 preStop = '' 93 ${pkgs.utillinux}/bin/umount /afs 94 ${openafsPkgs}/sbin/afsd -shutdown 95 ${pkgs.module_init_tools}/sbin/rmmod libafs 96 ''; 97 }; 98 }; 99}