From 0852ee25bbdca42e47a92bfd1dfe4476483b8c3f Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 31 Dec 2022 05:54:23 -0700 Subject: [PATCH] modules: add a module to init mu --- hosts/europa/default.nix | 4 ++++ hosts/faf/default.nix | 3 ++- modules/default.nix | 2 +- modules/mu.nix | 37 ++++++++++++++++++++++++++----------- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/hosts/europa/default.nix b/hosts/europa/default.nix index 1166d3e..7ad0599 100644 --- a/hosts/europa/default.nix +++ b/hosts/europa/default.nix @@ -113,6 +113,10 @@ in { }; }; + muInit = { + enable = true; + }; + services = { pcscd.enable = true; vnstat.enable = true; diff --git a/hosts/faf/default.nix b/hosts/faf/default.nix index de667e2..327d34d 100644 --- a/hosts/faf/default.nix +++ b/hosts/faf/default.nix @@ -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; diff --git a/modules/default.nix b/modules/default.nix index a82cc3c..c12ef22 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,2 +1,2 @@ -{ config, lib, pkgs, ... }: with lib; { imports = [ ./ssh-fido-agent.nix ]; } +{ config, lib, pkgs, ... }: { imports = [ ./ssh-fido-agent.nix ./mu.nix ]; } diff --git a/modules/mu.nix b/modules/mu.nix index 0cccb29..83b0dd7 100644 --- a/modules/mu.nix +++ b/modules/mu.nix @@ -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 + MU_HOME=~/.cache/mu + + if [ "${cfg.muHome}" != "mudefault" ]; then + MU_HOME="${cfg.muHome}" + fi + while true; do - if [ ! -d ${cfg.muHome} ]; then - ${mu} init --muhome="${cfg.muHome}" --maildir="${cfg.mailDir}" --my-address="${cfg.emailAddress}" + 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" ];