1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00
home-manager/modules/programs/sftpman.nix
Austin Horstman 86402a17b6 treewide: flatten single file modules
Some files don't need nesting and can be root level again to reduce
conflicts with other PRs.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2025-06-23 16:20:26 -05:00

123 lines
3.1 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkOption types;
cfg = config.programs.sftpman;
jsonFormat = pkgs.formats.json { };
mountOpts = {
options = {
host = mkOption {
type = types.str;
description = "The host to connect to.";
};
port = mkOption {
type = types.port;
default = 22;
description = "The port to connect to.";
};
user = mkOption {
type = types.str;
description = "The username to authenticate with.";
};
mountOptions = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Options to pass to sshfs.";
};
mountPoint = mkOption {
type = types.str;
description = "The remote path to mount.";
};
authType = mkOption {
type = types.enum [
"password"
"publickey"
"hostbased"
"keyboard-interactive"
"gssapi-with-mic"
];
default = "publickey";
description = "The authentication method to use.";
};
sshKey = mkOption {
type = types.nullOr types.str;
default = cfg.defaultSshKey;
defaultText = lib.literalExpression "config.programs.sftpman.defaultSshKey";
description = ''
Path to the SSH key to use for authentication.
Only applies if authMethod is `publickey`.
'';
};
beforeMount = mkOption {
type = types.str;
default = "true";
description = "Command to run before mounting.";
};
};
};
in
{
meta.maintainers = with lib.maintainers; [ fugi ];
options.programs.sftpman = {
enable = lib.mkEnableOption "sftpman, an application that handles sshfs/sftp file systems mounting";
package = lib.mkPackageOption pkgs "sftpman" { nullable = true; };
defaultSshKey = mkOption {
type = types.nullOr types.str;
default = null;
description = "Path to the SSH key to be used by default. Can be overridden per host.";
};
mounts = mkOption {
type = types.attrsOf (types.submodule mountOpts);
default = { };
description = ''
The sshfs mount configurations written to
{file}`$XDG_CONFIG_HOME/sftpman/mounts/`.
'';
};
};
config = lib.mkIf cfg.enable {
assertions = [
(
let
hasMissingKey = _: mount: mount.authType == "publickey" && mount.sshKey == null;
mountsWithMissingKey = lib.attrNames (lib.filterAttrs hasMissingKey cfg.mounts);
mountsWithMissingKeyStr = lib.concatStringsSep ", " mountsWithMissingKey;
in
{
assertion = mountsWithMissingKey == [ ];
message = ''
sftpman mounts using authentication type "publickey" but missing 'sshKey': ${mountsWithMissingKeyStr}
'';
}
)
];
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
xdg.configFile = lib.mapAttrs' (
name: value:
lib.nameValuePair "sftpman/mounts/${name}.json" {
source = jsonFormat.generate "sftpman-${name}.json" (value // { id = name; });
}
) cfg.mounts;
};
}