nixos-config/modules/wg-home.nix

31 lines
673 B
Nix
Raw Normal View History

2022-05-11 15:50:52 +00:00
{ config, lib, pkgs, ... }:
2022-10-09 19:02:53 +00:00
let
cfg = config.sconfig.wg-home;
in
2022-05-11 15:50:52 +00:00
{
2022-10-09 19:02:53 +00:00
options.sconfig.wg-home = {
2022-05-11 15:50:52 +00:00
2022-10-09 19:02:53 +00:00
enable = lib.mkEnableOption "set up home VPN";
path = lib.mkOption {
type = lib.types.path;
default = "/var/lib/nixos/wireguard_home.conf";
};
};
config = lib.mkIf cfg.enable {
2022-05-11 15:50:52 +00:00
systemd.services.wg-home = {
2022-10-09 19:02:53 +00:00
script = "wg-quick up ${cfg.path}";
preStop = "wg-quick down ${cfg.path}";
2022-05-11 15:50:52 +00:00
path = [ pkgs.wireguard-tools ];
serviceConfig = {
type = "oneshot";
RemainAfterExit = true;
};
};
boot.kernelModules = [ "wireguard" ];
environment.systemPackages = [ pkgs.wireguard-tools ];
};
}