2021-01-02 00:00:31 +00:00
|
|
|
with import <stockholm/lib>;
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
let
|
2021-01-24 10:26:39 +00:00
|
|
|
cfg = config.krebs.bindfs;
|
2021-01-02 00:00:31 +00:00
|
|
|
in {
|
2021-01-24 10:26:39 +00:00
|
|
|
options.krebs.bindfs = mkOption {
|
2021-01-02 00:00:31 +00:00
|
|
|
type = types.attrsOf (types.submodule ({ config, ... }: {
|
|
|
|
options = {
|
|
|
|
target = mkOption {
|
|
|
|
description = ''
|
|
|
|
destination where bindfs mounts to.
|
|
|
|
second positional argument to bindfs.
|
|
|
|
'';
|
|
|
|
default = config._module.args.name;
|
|
|
|
type = types.absolute-pathname;
|
|
|
|
};
|
|
|
|
source = mkOption {
|
|
|
|
description = ''
|
|
|
|
source folder where the mounted directory is originally.
|
|
|
|
first positional argument to bindfs.
|
|
|
|
'';
|
|
|
|
type = types.absolute-pathname;
|
|
|
|
};
|
|
|
|
options = mkOption {
|
|
|
|
description = ''
|
|
|
|
additional arguments to bindfs
|
|
|
|
'';
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
};
|
2021-01-23 16:34:59 +00:00
|
|
|
clearTarget = mkOption {
|
|
|
|
description = ''
|
|
|
|
whether to clear the target folder before mounting
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2021-01-02 00:00:31 +00:00
|
|
|
};
|
|
|
|
}));
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg != {}) {
|
|
|
|
systemd.services = mapAttrs' (n: mount: let
|
|
|
|
name = replaceStrings [ "/" ] [ "_" ] n;
|
|
|
|
in nameValuePair "bindfs-${name}" {
|
|
|
|
wantedBy = [ "local-fs.target" ];
|
|
|
|
path = [ pkgs.coreutils ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStartPre = pkgs.writeDash "bindfs-init-${name}" ''
|
2021-01-23 16:34:59 +00:00
|
|
|
${optionalString mount.clearTarget ''
|
|
|
|
rm -rf '${mount.target}'
|
|
|
|
''}
|
2021-01-02 00:00:31 +00:00
|
|
|
mkdir -p '${mount.source}'
|
|
|
|
mkdir -p '${mount.target}'
|
|
|
|
'';
|
|
|
|
ExecStart = "${pkgs.bindfs}/bin/bindfs -f ${concatStringsSep " " mount.options} ${mount.source} ${mount.target}";
|
|
|
|
};
|
|
|
|
}) cfg;
|
|
|
|
};
|
|
|
|
}
|