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 = { services = {
pcscd.enable = true; pcscd.enable = true;
vnstat.enable = true; vnstat.enable = true;

View File

@ -23,7 +23,8 @@ in {
networking.interfaces.enp1s0.useDHCP = true; networking.interfaces.enp1s0.useDHCP = true;
networking.interfaces.enp2s0.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 ]; networking.firewall.allowedUDPPorts = [ 53 ];
users.users.root = userBase; 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, ... }: { config, lib, pkgs, ... }:
let let
cfg = config.muServer; cfg = config.muInit;
mu = "${pkgs.mu}/bin/mu"; mu = "${pkgs.mu}/bin/mu";
muInitScript = pkgs.writeScriptBin "mu-init-script" '' muInitScript = pkgs.writeScriptBin "mu-init-script" ''
#!${pkgs.runtimeShell} #!${pkgs.runtimeShell}
set -eu set -eu
while true; do MU_HOME=~/.cache/mu
if [ ! -d ${cfg.muHome} ]; then
${mu} init --muhome="${cfg.muHome}" --maildir="${cfg.mailDir}" --my-address="${cfg.emailAddress}" if [ "${cfg.muHome}" != "mudefault" ]; then
MU_HOME="${cfg.muHome}"
fi 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 done
''; '';
in { in {
options = with lib; { options = with lib; {
muServer = { muInit = {
enable = lib.mkEnableOption "Enable mu server"; enable = lib.mkEnableOption "Enable mu server";
muHome = lib.mkOption { muHome = lib.mkOption {
type = types.path; type = types.str;
default = "~/.mu"; default = "mudefault";
}; };
mailDir = lib.mkOption { mailDir = lib.mkOption {
type = types.path; type = types.str;
default = "~/Maildir"; default = "~/Maildir";
}; };
emailAddress = lib.mkOption { emailAddress = lib.mkOption {
type = types.string; type = types.str;
default = ""; default = "";
}; };
}; };
}; };
config = lib.mkIf config.muServer.enable { config = lib.mkIf config.muInit.enable {
environment.systemPackages = [ muInitScript ]; environment.systemPackages = [ muInitScript ];
systemd.user.services.mu-server = { systemd.user.services.mu-init = {
script = "${muInitScript}"; script = "${muInitScript}/bin/mu-init-script";
wantedBy = [ "graphical-session.target" ]; wantedBy = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ]; partOf = [ "graphical-session.target" ];
after = [ "graphical-session.target" ]; after = [ "graphical-session.target" ];