mirror of
https://github.com/nix-community/home-manager
synced 2024-11-30 06:59:45 +01:00
sftpman: add module
This commit is contained in:
parent
c24c298562
commit
6e2afa5c3b
10 changed files with 231 additions and 0 deletions
|
@ -1356,6 +1356,13 @@ in
|
||||||
A new module is available: 'services.osmscout-server'.
|
A new module is available: 'services.osmscout-server'.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
time = "2023-12-28T13:01:15+00:00";
|
||||||
|
message = ''
|
||||||
|
A new module is available: 'programs.sftpman'.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,6 +198,7 @@ let
|
||||||
./programs/scmpuff.nix
|
./programs/scmpuff.nix
|
||||||
./programs/script-directory.nix
|
./programs/script-directory.nix
|
||||||
./programs/senpai.nix
|
./programs/senpai.nix
|
||||||
|
./programs/sftpman.nix
|
||||||
./programs/sioyek.nix
|
./programs/sioyek.nix
|
||||||
./programs/skim.nix
|
./programs/skim.nix
|
||||||
./programs/sm64ex.nix
|
./programs/sm64ex.nix
|
||||||
|
|
118
modules/programs/sftpman.nix
Normal file
118
modules/programs/sftpman.nix
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.programs.sftpman;
|
||||||
|
|
||||||
|
jsonFormat = pkgs.formats.json { };
|
||||||
|
|
||||||
|
mountOpts = { config, name, ... }: {
|
||||||
|
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 maintainers; [ fugi ];
|
||||||
|
|
||||||
|
options.programs.sftpman = {
|
||||||
|
enable = mkEnableOption
|
||||||
|
"sftpman, an application that handles sshfs/sftp file systems mounting";
|
||||||
|
|
||||||
|
package = mkPackageOption pkgs "sftpman" { };
|
||||||
|
|
||||||
|
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 = mkIf cfg.enable {
|
||||||
|
assertions = [
|
||||||
|
(let
|
||||||
|
hasMissingKey = _: mount:
|
||||||
|
mount.authType == "publickey" && mount.sshKey == null;
|
||||||
|
mountsWithMissingKey = attrNames (filterAttrs hasMissingKey cfg.mounts);
|
||||||
|
mountsWithMissingKeyStr = concatStringsSep ", " mountsWithMissingKey;
|
||||||
|
in {
|
||||||
|
assertion = mountsWithMissingKey == [ ];
|
||||||
|
message = ''
|
||||||
|
sftpman mounts using authentication type "publickey" but missing 'sshKey': ${mountsWithMissingKeyStr}
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
home.packages = [ cfg.package ];
|
||||||
|
|
||||||
|
xdg.configFile = mapAttrs' (name: value:
|
||||||
|
nameValuePair "sftpman/mounts/${name}.json" {
|
||||||
|
source =
|
||||||
|
jsonFormat.generate "sftpman-${name}.json" (value // { id = name; });
|
||||||
|
}) cfg.mounts;
|
||||||
|
};
|
||||||
|
}
|
|
@ -139,6 +139,7 @@ import nmt {
|
||||||
./modules/programs/sapling
|
./modules/programs/sapling
|
||||||
./modules/programs/sbt
|
./modules/programs/sbt
|
||||||
./modules/programs/scmpuff
|
./modules/programs/scmpuff
|
||||||
|
./modules/programs/sftpman
|
||||||
./modules/programs/sioyek
|
./modules/programs/sioyek
|
||||||
./modules/programs/sm64ex
|
./modules/programs/sm64ex
|
||||||
./modules/programs/ssh
|
./modules/programs/ssh
|
||||||
|
|
21
tests/modules/programs/sftpman/assert-on-no-sshkey.nix
Normal file
21
tests/modules/programs/sftpman/assert-on-no-sshkey.nix
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
programs.sftpman = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
mounts = {
|
||||||
|
mount1 = {
|
||||||
|
host = "host1.example.com";
|
||||||
|
mountPoint = "/path/to/somewhere";
|
||||||
|
user = "root";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
test.stubs.sftpman = { };
|
||||||
|
|
||||||
|
test.asserts.assertions.expected = [''
|
||||||
|
sftpman mounts using authentication type "publickey" but missing 'sshKey': mount1
|
||||||
|
''];
|
||||||
|
};
|
||||||
|
}
|
4
tests/modules/programs/sftpman/default.nix
Normal file
4
tests/modules/programs/sftpman/default.nix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
sftpman-example-settings = ./example-settings.nix;
|
||||||
|
sftpman-assert-on-no-sshkey = ./assert-on-no-sshkey.nix;
|
||||||
|
}
|
44
tests/modules/programs/sftpman/example-settings.nix
Normal file
44
tests/modules/programs/sftpman/example-settings.nix
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
programs.sftpman = {
|
||||||
|
enable = true;
|
||||||
|
defaultSshKey = "/home/user/.ssh/id_ed25519";
|
||||||
|
|
||||||
|
mounts = {
|
||||||
|
mount1 = {
|
||||||
|
host = "host1.example.com";
|
||||||
|
mountPoint = "/path/to/somewhere";
|
||||||
|
user = "root";
|
||||||
|
mountOptions = [ "idmap=user" ];
|
||||||
|
};
|
||||||
|
mount2 = {
|
||||||
|
host = "host2.example.com";
|
||||||
|
mountPoint = "/another/path";
|
||||||
|
user = "someuser";
|
||||||
|
authType = "password";
|
||||||
|
sshKey = null;
|
||||||
|
};
|
||||||
|
mount3 = {
|
||||||
|
host = "host3.example.com";
|
||||||
|
mountPoint = "/yet/another/path";
|
||||||
|
user = "user";
|
||||||
|
sshKey = "/home/user/.ssh/id_rsa";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
test.stubs.sftpman = { };
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileContent \
|
||||||
|
home-files/.config/sftpman/mounts/mount1.json \
|
||||||
|
${./expected-mount1.json}
|
||||||
|
assertFileContent \
|
||||||
|
home-files/.config/sftpman/mounts/mount2.json \
|
||||||
|
${./expected-mount2.json}
|
||||||
|
assertFileContent \
|
||||||
|
home-files/.config/sftpman/mounts/mount3.json \
|
||||||
|
${./expected-mount3.json}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
13
tests/modules/programs/sftpman/expected-mount1.json
Normal file
13
tests/modules/programs/sftpman/expected-mount1.json
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"authType": "publickey",
|
||||||
|
"beforeMount": "true",
|
||||||
|
"host": "host1.example.com",
|
||||||
|
"id": "mount1",
|
||||||
|
"mountOptions": [
|
||||||
|
"idmap=user"
|
||||||
|
],
|
||||||
|
"mountPoint": "/path/to/somewhere",
|
||||||
|
"port": 22,
|
||||||
|
"sshKey": "/home/user/.ssh/id_ed25519",
|
||||||
|
"user": "root"
|
||||||
|
}
|
11
tests/modules/programs/sftpman/expected-mount2.json
Normal file
11
tests/modules/programs/sftpman/expected-mount2.json
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"authType": "password",
|
||||||
|
"beforeMount": "true",
|
||||||
|
"host": "host2.example.com",
|
||||||
|
"id": "mount2",
|
||||||
|
"mountOptions": [],
|
||||||
|
"mountPoint": "/another/path",
|
||||||
|
"port": 22,
|
||||||
|
"sshKey": null,
|
||||||
|
"user": "someuser"
|
||||||
|
}
|
11
tests/modules/programs/sftpman/expected-mount3.json
Normal file
11
tests/modules/programs/sftpman/expected-mount3.json
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"authType": "publickey",
|
||||||
|
"beforeMount": "true",
|
||||||
|
"host": "host3.example.com",
|
||||||
|
"id": "mount3",
|
||||||
|
"mountOptions": [],
|
||||||
|
"mountPoint": "/yet/another/path",
|
||||||
|
"port": 22,
|
||||||
|
"sshKey": "/home/user/.ssh/id_rsa",
|
||||||
|
"user": "user"
|
||||||
|
}
|
Loading…
Reference in a new issue