ma 3 snapraid: init, configuration for omo
This commit is contained in:
parent
d73c8df6e4
commit
719b8fb7a8
@ -8,6 +8,10 @@ let
|
|||||||
keyFile = "/dev/disk/by-id/usb-Verbatim_STORE_N_GO_070B3CEE0B223954-0:0";
|
keyFile = "/dev/disk/by-id/usb-Verbatim_STORE_N_GO_070B3CEE0B223954-0:0";
|
||||||
rootDisk = byid "ata-INTEL_SSDSA2M080G2GC_CVPO003402PB080BGN";
|
rootDisk = byid "ata-INTEL_SSDSA2M080G2GC_CVPO003402PB080BGN";
|
||||||
homePartition = byid "ata-INTEL_SSDSA2M080G2GC_CVPO003402PB080BGN-part3";
|
homePartition = byid "ata-INTEL_SSDSA2M080G2GC_CVPO003402PB080BGN-part3";
|
||||||
|
# cryptsetup luksFormat $dev --cipher aes-xts-plain64 -s 512 -h sha512
|
||||||
|
# cryptsetup luksAddKey $dev tmpkey
|
||||||
|
# cryptsetup luksOpen $dev crypt0
|
||||||
|
# mkfs.xfs /dev/mapper/crypt0 -L crypt0
|
||||||
cryptDisk0 = byid "ata-ST2000DM001-1CH164_Z240XTT6";
|
cryptDisk0 = byid "ata-ST2000DM001-1CH164_Z240XTT6";
|
||||||
cryptDisk1 = byid "ata-TP02000GB_TPW151006050068";
|
cryptDisk1 = byid "ata-TP02000GB_TPW151006050068";
|
||||||
cryptDisk2 = byid "ata-WDC_WD20EARS-00MVWB0_WD-WCAZA5548487";
|
cryptDisk2 = byid "ata-WDC_WD20EARS-00MVWB0_WD-WCAZA5548487";
|
||||||
@ -23,15 +27,30 @@ in {
|
|||||||
../2configs/exim-retiolum.nix
|
../2configs/exim-retiolum.nix
|
||||||
../2configs/smart-monitor.nix
|
../2configs/smart-monitor.nix
|
||||||
../2configs/mail-client.nix
|
../2configs/mail-client.nix
|
||||||
|
../3modules
|
||||||
];
|
];
|
||||||
krebs.build.host = config.krebs.hosts.omo;
|
krebs.build.host = config.krebs.hosts.omo;
|
||||||
services.smartd.devices = builtins.map (x: { device = x; }) allDisks;
|
services.smartd.devices = builtins.map (x: { device = x; }) allDisks;
|
||||||
|
makefu.snapraid = let
|
||||||
# AMD E350
|
toMapper = id: "/media/crypt${builtins.toString id}";
|
||||||
fileSystems."/home" = {
|
in {
|
||||||
device = "/dev/mapper/home";
|
enable = true;
|
||||||
fsType = "ext4";
|
disks = map toMapper [ 0 1 ];
|
||||||
|
parity = toMapper 2;
|
||||||
};
|
};
|
||||||
|
# AMD E350
|
||||||
|
fileSystems = let
|
||||||
|
cryptMount = name:
|
||||||
|
{ "/media/${name}" = { device = "/dev/mapper/${name}"; fsType = "xfs"; };};
|
||||||
|
in {
|
||||||
|
"/home" = {
|
||||||
|
device = "/dev/mapper/home";
|
||||||
|
fsType = "ext4";
|
||||||
|
};
|
||||||
|
} // cryptMount "crypt0"
|
||||||
|
// cryptMount "crypt1"
|
||||||
|
// cryptMount "crypt2";
|
||||||
|
|
||||||
powerManagement.powerUpCommands = lib.concatStrings (map (disk: ''
|
powerManagement.powerUpCommands = lib.concatStrings (map (disk: ''
|
||||||
${pkgs.hdparm}/sbin/hdparm -S 100 ${disk}
|
${pkgs.hdparm}/sbin/hdparm -S 100 ${disk}
|
||||||
${pkgs.hdparm}/sbin/hdparm -B 127 ${disk}
|
${pkgs.hdparm}/sbin/hdparm -B 127 ${disk}
|
||||||
|
@ -2,6 +2,7 @@ _:
|
|||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
|
./snapraid.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
125
makefu/3modules/snapraid.nix
Normal file
125
makefu/3modules/snapraid.nix
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
# returns dirname without / , used as disk name
|
||||||
|
dname = dir: replaceChars ["/"] [""] (head (reverseList (splitString "/" dir)));
|
||||||
|
snapraid-conf = ''
|
||||||
|
# Disks
|
||||||
|
${concatMapStringsSep "\n" (d: "disk ${dname d} ${d}") cfg.disks}
|
||||||
|
# Parity
|
||||||
|
${optionalString (cfg.parity != "") "parity ${cfg.parity}/snapraid.parity"}
|
||||||
|
|
||||||
|
# content on Disks
|
||||||
|
${optionalString cfg.contentOnDisks
|
||||||
|
concatMapStringsSep "\n" (d: "content ${d}/snapraid.content") cfg.disks}
|
||||||
|
|
||||||
|
# content on Parity
|
||||||
|
${optionalString (cfg.contentOnParity && cfg.parity != "")
|
||||||
|
"content ${cfg.parity}/snapraid.content"}
|
||||||
|
# Default content file
|
||||||
|
content ${cfg.defaultContentFile}
|
||||||
|
|
||||||
|
# Extra Configuration
|
||||||
|
${cfg.extraConfig}
|
||||||
|
'';
|
||||||
|
cfg = config.makefu.snapraid;
|
||||||
|
|
||||||
|
out = {
|
||||||
|
options.makefu.snapraid = api;
|
||||||
|
config = mkIf cfg.enable imp;
|
||||||
|
};
|
||||||
|
|
||||||
|
api = {
|
||||||
|
enable = mkEnableOption "snapraid";
|
||||||
|
|
||||||
|
timerConfig = mkOption {
|
||||||
|
type = types.unspecified;
|
||||||
|
description = ''
|
||||||
|
Start snapraid service
|
||||||
|
'';
|
||||||
|
default = {
|
||||||
|
OnCalendar = "daily";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
disks = mkOption {
|
||||||
|
type = with types;listOf str;
|
||||||
|
description = ''
|
||||||
|
Disks to protect. Each disk is a path to the mounted directory of the
|
||||||
|
disk.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
parity = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Folder to store parity file.
|
||||||
|
Set to empty string if you want to configure the parity yourself in
|
||||||
|
extraConfig.
|
||||||
|
|
||||||
|
All extra parity files (2,3,z, etc...) should be configured via
|
||||||
|
extraConfig.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
contentOnDisks = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = ''
|
||||||
|
Store Content file on each Disk to protect.
|
||||||
|
Set this to false if you do not want this behavior to apply.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
contentOnParity = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = ''
|
||||||
|
Store Content file on parity Disk.
|
||||||
|
Set this to false if you do not want this behavior to apply.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
defaultContentFile = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "/var/cache/snapraid.content";
|
||||||
|
description = ''
|
||||||
|
Path to default content file
|
||||||
|
Set to empty string if this content file should be written.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
extraConfig = mkOption {
|
||||||
|
type = types.string;
|
||||||
|
default = "";
|
||||||
|
description = ''
|
||||||
|
Extra configuration to be appended to the snapraid conf file.
|
||||||
|
You can configure extra Parity files as well as extra content files.
|
||||||
|
See `man snapraid` for additional configuration
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
imp = {
|
||||||
|
environment.systemPackages = [
|
||||||
|
# for scrubbing,fixing
|
||||||
|
pkgs.snapraid
|
||||||
|
];
|
||||||
|
environment.etc."snapraid.conf".text = snapraid-conf;
|
||||||
|
systemd.timers.snapraid-sync = {
|
||||||
|
description = "snapraid sync timer";
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = cfg.timerConfig;
|
||||||
|
};
|
||||||
|
systemd.services.snapraid-sync = {
|
||||||
|
description = "Snapraid sync service";
|
||||||
|
after = [ "network.target" "local-fs.target" ];
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "simple";
|
||||||
|
ExecStartPre = pkgs.writeScript "Snapraid-sync-init" ''
|
||||||
|
#! /bin/sh
|
||||||
|
${optionalString (cfg.defaultContentFile != "")
|
||||||
|
"mkdir -p $(dirname ${cfg.defaultContentFile})"}
|
||||||
|
'';
|
||||||
|
ExecStart = "${pkgs.snapraid}/bin/snapraid sync";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in out
|
Loading…
Reference in New Issue
Block a user