2014-05-05 18:58:51 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2009-11-10 15:22:57 +00:00
|
|
|
|
|
|
|
let
|
2014-05-05 18:58:51 +00:00
|
|
|
inherit (lib) mkOption mkIf;
|
2009-11-18 13:28:16 +00:00
|
|
|
|
2009-11-10 15:22:57 +00:00
|
|
|
cfg = config.services.openafsClient;
|
2009-11-18 13:28:16 +00:00
|
|
|
|
|
|
|
cellServDB = pkgs.fetchurl {
|
|
|
|
url = http://dl.central.org/dl/cellservdb/CellServDB.2009-06-29;
|
|
|
|
sha256 = "be566f850e88130333ab8bc3462872ad90c9482e025c60a92f728b5bac1b4fa9";
|
|
|
|
};
|
|
|
|
|
2009-11-10 15:22:57 +00:00
|
|
|
afsConfig = pkgs.runCommand "afsconfig" {} ''
|
2014-06-30 12:56:10 +00:00
|
|
|
mkdir -p $out
|
2009-11-10 15:22:57 +00:00
|
|
|
echo ${cfg.cellName} > $out/ThisCell
|
|
|
|
cp ${cellServDB} $out/CellServDB
|
|
|
|
echo "/afs:${cfg.cacheDirectory}:${cfg.cacheSize}" > $out/cacheinfo
|
|
|
|
'';
|
2010-02-01 16:29:15 +00:00
|
|
|
|
|
|
|
openafsPkgs = config.boot.kernelPackages.openafsClient;
|
2009-11-10 15:22:57 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.openafsClient = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the OpenAFS client.";
|
|
|
|
};
|
|
|
|
|
|
|
|
cellName = mkOption {
|
|
|
|
default = "grand.central.org";
|
|
|
|
description = "Cell name.";
|
|
|
|
};
|
|
|
|
|
|
|
|
cacheSize = mkOption {
|
|
|
|
default = "100000";
|
|
|
|
description = "Cache size.";
|
|
|
|
};
|
|
|
|
|
|
|
|
cacheDirectory = mkOption {
|
|
|
|
default = "/var/cache/openafs";
|
|
|
|
description = "Cache directory.";
|
|
|
|
};
|
|
|
|
|
2014-03-14 13:39:21 +00:00
|
|
|
crypt = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable (weak) protocol encryption.";
|
|
|
|
};
|
|
|
|
|
|
|
|
sparse = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Minimal cell list in /afs.";
|
|
|
|
};
|
|
|
|
|
2009-11-10 15:22:57 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2010-02-01 16:29:15 +00:00
|
|
|
environment.systemPackages = [ openafsPkgs ];
|
2009-11-10 15:22:57 +00:00
|
|
|
|
|
|
|
environment.etc = [
|
|
|
|
{ source = afsConfig;
|
|
|
|
target = "openafs";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.afsd = {
|
|
|
|
description = "AFS client";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 18:13:56 +00:00
|
|
|
after = [ "network.target" ];
|
2016-01-06 06:50:18 +00:00
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p -m 0755 /afs
|
|
|
|
mkdir -m 0700 -p ${cfg.cacheDirectory}
|
2016-08-14 09:57:45 +00:00
|
|
|
${pkgs.kmod}/bin/insmod ${openafsPkgs}/lib/openafs/libafs-*.ko || true
|
2016-01-06 06:50:18 +00:00
|
|
|
${openafsPkgs}/sbin/afsd -confdir ${afsConfig} -cachedir ${cfg.cacheDirectory} ${if cfg.sparse then "-dynroot-sparse" else "-dynroot"} -fakestat -afsdb
|
|
|
|
${openafsPkgs}/bin/fs setcrypt ${if cfg.crypt then "on" else "off"}
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Doing this in preStop, because after these commands AFS is basically
|
|
|
|
# stopped, so systemd has nothing to do, just noticing it. If done in
|
|
|
|
# postStop, then we get a hang + kernel oops, because AFS can't be
|
|
|
|
# stopped simply by sending signals to processes.
|
|
|
|
preStop = ''
|
|
|
|
${pkgs.utillinux}/bin/umount /afs
|
|
|
|
${openafsPkgs}/sbin/afsd -shutdown
|
2016-04-22 07:40:57 +00:00
|
|
|
${pkgs.kmod}/sbin/rmmod libafs
|
2016-01-06 06:50:18 +00:00
|
|
|
'';
|
|
|
|
};
|
2009-11-10 15:22:57 +00:00
|
|
|
};
|
|
|
|
}
|