refactor: put storagebox code in module
Signed-off-by: Lander Van den Bulcke <landervandenbulcke@gmail.com>
This commit is contained in:
parent
fc2d98e503
commit
9e0ebbdafb
4 changed files with 95 additions and 38 deletions
|
|
@ -1,6 +1,5 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
|
|
@ -26,43 +25,13 @@
|
|||
privateKeyFile = config.sops.secrets.wireguardKey.path;
|
||||
};
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
gocryptfs
|
||||
sshfs
|
||||
];
|
||||
|
||||
programs.ssh.knownHosts.storageBox = {
|
||||
hostNames = [ "u491729.your-storagebox.de" ];
|
||||
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIICf9svRenC/PLKIL9nk6K/pxQgoiFC41wTNvoIncOxs";
|
||||
};
|
||||
|
||||
fileSystems."/mnt/box" = {
|
||||
device = "u491729@u491729.your-storagebox.de:/home";
|
||||
fsType = "fuse.sshfs";
|
||||
options = [
|
||||
"defaults"
|
||||
"_netdev"
|
||||
"allow_other"
|
||||
"default_permissions"
|
||||
"port=23"
|
||||
"compression=no"
|
||||
"reconnect"
|
||||
"ServerAliveInterval=15"
|
||||
"IdentityFile=${config.sops.secrets.storageboxKey.path}"
|
||||
];
|
||||
};
|
||||
|
||||
fileSystems."/data" = {
|
||||
depends = [
|
||||
"/mnt/box"
|
||||
];
|
||||
device = "/mnt/box/crypt";
|
||||
fsType = "fuse.gocryptfs";
|
||||
options = [
|
||||
"rw"
|
||||
"allow_other"
|
||||
"passfile=${config.sops.secrets.storageboxCryptKey.path}"
|
||||
];
|
||||
services.storagebox = {
|
||||
enable = true;
|
||||
hostname = "u491729.your-storagebox.de";
|
||||
hostKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIICf9svRenC/PLKIL9nk6K/pxQgoiFC41wTNvoIncOxs";
|
||||
user = "u491729";
|
||||
sshKeyFile = config.sops.secrets.storageboxKey.path;
|
||||
passFile = config.sops.secrets.storageboxCryptKey.path;
|
||||
};
|
||||
|
||||
sops = {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
inputs.disko.nixosModules.disko
|
||||
inputs.sops-nix.nixosModules.sops
|
||||
inputs.self.nixosModules.namespaced-vpn
|
||||
inputs.self.nixosModules.storagebox
|
||||
|
||||
diskConfig
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
# my-module = import ./my-module.nix
|
||||
namespaced-vpn = import ./namespaced-vpn.nix;
|
||||
storagebox = import ./storagebox.nix;
|
||||
}
|
||||
|
|
|
|||
86
modules/nixos/storagebox.nix
Normal file
86
modules/nixos/storagebox.nix
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.services.storagebox;
|
||||
in
|
||||
{
|
||||
options.services.storagebox = {
|
||||
enable = mkEnableOption "storagebox";
|
||||
|
||||
hostname = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
hostKey = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
sshKeyFile = mkOption {
|
||||
type = types.path;
|
||||
};
|
||||
|
||||
plainMountPoint = mkOption {
|
||||
type = types.str;
|
||||
default = "/mnt/box";
|
||||
};
|
||||
|
||||
cryptMountPoint = mkOption {
|
||||
type = types.str;
|
||||
default = "/data";
|
||||
};
|
||||
|
||||
passFile = mkOption {
|
||||
type = types.path;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
environment.systemPackages = with pkgs; [
|
||||
gocryptfs
|
||||
sshfs
|
||||
];
|
||||
|
||||
programs.ssh.knownHosts.storageBox = {
|
||||
hostNames = [ cfg.hostname ];
|
||||
publicKey = cfg.hostKey;
|
||||
};
|
||||
|
||||
fileSystems."${cfg.plainMountPoint}" = {
|
||||
device = "${cfg.user}@${cfg.hostname}:/home";
|
||||
fsType = "fuse.sshfs";
|
||||
options = [
|
||||
"defaults"
|
||||
"_netdev"
|
||||
"allow_other"
|
||||
"default_permissions"
|
||||
"port=23"
|
||||
"compression=no"
|
||||
"reconnect"
|
||||
"ServerAliveInterval=15"
|
||||
"IdentityFile=${cfg.sshKeyFile}"
|
||||
];
|
||||
};
|
||||
|
||||
fileSystems."${cfg.cryptMountPoint}" = {
|
||||
depends = [
|
||||
"${cfg.plainMountPoint}"
|
||||
];
|
||||
device = "${cfg.plainMountPoint}/crypt";
|
||||
fsType = "fuse.gocryptfs";
|
||||
options = [
|
||||
"rw"
|
||||
"allow_other"
|
||||
"passfile=${cfg.passFile}"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue