From 2ef74e42fd443a03c35d450b1316a98479fef4c3 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 31 Mar 2017 17:04:11 +0200 Subject: Call all uucp hosts on network up --- custom/uucp.nix | 76 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/custom/uucp.nix b/custom/uucp.nix index 0b4b1306..822aa92f 100644 --- a/custom/uucp.nix +++ b/custom/uucp.nix @@ -6,7 +6,7 @@ let portSpec = name: '' port ${name} type pipe - protocol ${if builtins.hasAttr name config.services.uucp.protocols then config.services.uucp.protocols."${name}" else config.services.uucp.defaultProtocol} + protocol ${if builtins.hasAttr name cfg.protocols then cfg.protocols."${name}" else cfg.defaultProtocol} reliable true command ${pkgs.openssh}/bin/ssh -x -o batchmode=yes ${name} ''; @@ -15,10 +15,12 @@ let time Any port ${name} chat "" - protocol ${if builtins.hasAttr name config.services.uucp.protocols then config.services.uucp.protocols."${name}" else config.services.uucp.defaultProtocol} - command-path ${concatStringsSep " " config.services.uucp.commandPath} - commands ${concatStringsSep " " (if builtins.hasAttr name config.services.uucp.commands then config.services.uucp.commands."${name}" else config.services.uucp.defaultCommands)} + protocol ${if builtins.hasAttr name cfg.protocols then cfg.protocols."${name}" else cfg.defaultProtocol} + command-path ${concatStringsSep " " cfg.commandPath} + commands ${concatStringsSep " " (if builtins.hasAttr name cfg.commands then cfg.commands."${name}" else cfg.defaultCommands)} ''; + + cfg = config.services.uucp; in { options = { services.uucp = { @@ -134,6 +136,15 @@ in { ''; }; + nmDispatch = mkOption { + type = config.networking.networkmanager.enable; + default = false; + description = '' + Install a network-manager dispatcher script to automatically + call all remotes when networking is available + ''; + }; + extraConfig = mkOption { type = types.string; default = '' @@ -152,19 +163,19 @@ in { }; }; - config = mkIf config.services.uucp.enable { + config = mkIf cfg.enable { environment.etc."uucp/config" = { text = '' - hostname ${config.services.uucp.nodeName} + hostname ${cfg.nodeName} - spool ${config.services.uucp.spoolDir} - lockdir ${config.services.uucp.lockDir} - pubdir ${config.services.uucp.pubDir} - logfile ${config.services.uucp.logFile} - statfile ${config.services.uucp.statFile} - debugfile ${config.services.uucp.debugFile} + spool ${cfg.spoolDir} + lockdir ${cfg.lockDir} + pubdir ${cfg.pubDir} + logfile ${cfg.logFile} + statfile ${cfg.statFile} + debugfile ${cfg.debugFile} - ${config.services.uucp.extraConfig} + ${cfg.extraConfig} ''; }; @@ -173,28 +184,28 @@ in { isSystemUser = true; isNormalUser = false; createHome = true; - home = config.services.uucp.spoolDir; + home = cfg.spoolDir; description = "User for uucp over ssh"; useDefaultShell = true; - } // config.services.uucp.sshUser; + } // cfg.sshUser; system.activationScripts."uucp-sshconfig" = '' mkdir -p ${config.users.users."uucp".home}/.ssh chown ${config.users.users."uucp".name}:${config.users.users."uucp".group} ${config.users.users."uucp".home}/.ssh chmod 700 ${config.users.users."uucp".home}/.ssh - ln -fs ${builtins.toFile "ssh-config" config.services.uucp.sshConfig} ${config.users.users."uucp".home}/.ssh/config + ln -fs ${builtins.toFile "ssh-config" cfg.sshConfig} ${config.users.users."uucp".home}/.ssh/config ''; system.activationScripts."uucp-logs" = '' - touch ${config.services.uucp.logFile} - chown ${config.users.users."uucp".name}:${config.users.users."uucp".group} ${config.services.uucp.logFile} - chmod 644 ${config.services.uucp.logFile} - touch ${config.services.uucp.statFile} - chown ${config.users.users."uucp".name}:${config.users.users."uucp".group} ${config.services.uucp.statFile} - chmod 644 ${config.services.uucp.statFile} - touch ${config.services.uucp.debugFile} - chown ${config.users.users."uucp".name}:${config.users.users."uucp".group} ${config.services.uucp.debugFile} - chmod 644 ${config.services.uucp.debugFile} + touch ${cfg.logFile} + chown ${config.users.users."uucp".name}:${config.users.users."uucp".group} ${cfg.logFile} + chmod 644 ${cfg.logFile} + touch ${cfg.statFile} + chown ${config.users.users."uucp".name}:${config.users.users."uucp".group} ${cfg.statFile} + chmod 644 ${cfg.statFile} + touch ${cfg.debugFile} + chown ${config.users.users."uucp".name}:${config.users.users."uucp".group} ${cfg.debugFile} + chmod 644 ${cfg.debugFile} ''; environment.etc."uucp/port" = { @@ -202,10 +213,10 @@ in { port ssh type stdin protocol e - '' + concatStringsSep "\n" (map portSpec config.services.uucp.remoteNodes); + '' + concatStringsSep "\n" (map portSpec cfg.remoteNodes); }; environment.etc."uucp/sys" = { - text = config.services.uucp.extraSys + "\n" + concatStringsSep "\n" (map sysSpec config.services.uucp.remoteNodes); + text = cfg.extraSys + "\n" + concatStringsSep "\n" (map sysSpec cfg.remoteNodes); }; security.wrappers = let @@ -264,6 +275,15 @@ in { uucp ]; - services.cron.systemCronJobs = (map (name: "${config.services.uucp.interval} ${config.security.wrapperDir}/uucico -D -S ${name}") (if (config.services.uucp.interval != null) then config.services.uucp.remoteNodes else [])); + services.cron.systemCronJobs = (map (name: "${cfg.interval} ${config.security.wrapperDir}/uucico -D -S ${name}") (if (cfg.interval != null) then cfg.remoteNodes else [])); + + networking.networkmanager.dispatcherScripts = optional cfg.nmDispatch { + type = "basic"; + source = '' + #!${pkgs.stdenv.shell} + + ${map (name: "${config.security.wrapperDir}/uucico -D -S ${name}") cfg.remoteNodes} + ''; + }; }; } -- cgit v1.2.3