modules: add a module to init mu

This commit is contained in:
Aaron Bieber 2022-12-31 05:54:23 -07:00
parent 5b61f1d7f6
commit 0852ee25bb
No known key found for this signature in database
4 changed files with 33 additions and 13 deletions

View File

@ -113,6 +113,10 @@ in {
};
};
muInit = {
enable = true;
};
services = {
pcscd.enable = true;
vnstat.enable = true;

View File

@ -23,7 +23,8 @@ in {
networking.interfaces.enp1s0.useDHCP = true;
networking.interfaces.enp2s0.useDHCP = true;
networking.firewall.allowedTCPPorts = [ 22 53 config.services.prometheus.exporters.node.port ];
networking.firewall.allowedTCPPorts =
[ 22 53 config.services.prometheus.exporters.node.port ];
networking.firewall.allowedUDPPorts = [ 53 ];
users.users.root = userBase;

View File

@ -1,2 +1,2 @@
{ config, lib, pkgs, ... }: with lib; { imports = [ ./ssh-fido-agent.nix ]; }
{ config, lib, pkgs, ... }: { imports = [ ./ssh-fido-agent.nix ./mu.nix ]; }

View File

@ -1,41 +1,56 @@
{ config, lib, pkgs, ... }:
let
cfg = config.muServer;
cfg = config.muInit;
mu = "${pkgs.mu}/bin/mu";
muInitScript = pkgs.writeScriptBin "mu-init-script" ''
#!${pkgs.runtimeShell}
set -eu
while true; do
if [ ! -d ${cfg.muHome} ]; then
${mu} init --muhome="${cfg.muHome}" --maildir="${cfg.mailDir}" --my-address="${cfg.emailAddress}"
MU_HOME=~/.cache/mu
if [ "${cfg.muHome}" != "mudefault" ]; then
MU_HOME="${cfg.muHome}"
fi
while true; do
if [ ! -d $MU_HOME ]; then
echo "MU home directory missing: $MU_HOME. Creating it."
${mu} init ${
if cfg.muHome != "mudefault" then "--muhome=${cfg.muHome}" else ""
} ${if cfg.mailDir != "" then "--maildir=${cfg.mailDir}" else ""} ${
if cfg.emailAddress != "" then
"--my-address=${cfg.emailAddress}"
else
""
}
fi
sleep 5;
done
'';
in {
options = with lib; {
muServer = {
muInit = {
enable = lib.mkEnableOption "Enable mu server";
muHome = lib.mkOption {
type = types.path;
default = "~/.mu";
type = types.str;
default = "mudefault";
};
mailDir = lib.mkOption {
type = types.path;
type = types.str;
default = "~/Maildir";
};
emailAddress = lib.mkOption {
type = types.string;
type = types.str;
default = "";
};
};
};
config = lib.mkIf config.muServer.enable {
config = lib.mkIf config.muInit.enable {
environment.systemPackages = [ muInitScript ];
systemd.user.services.mu-server = {
script = "${muInitScript}";
systemd.user.services.mu-init = {
script = "${muInitScript}/bin/mu-init-script";
wantedBy = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
after = [ "graphical-session.target" ];