This repository has been archived on 2022-03-09. You can view files and clone it, but cannot push or open issues or pull requests.
snoo2nebby/flake.nix

73 lines
2.4 KiB
Nix

{
description = "Reddit -> Discord replicator";
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
inputs.utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, utils }:
utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system:
let
pkgs = nixpkgs.legacyPackages."${system}";
version = builtins.substring 0 8 self.lastModifiedDate;
in {
packages.snoo2nebby = pkgs.buildGoModule {
pname = "rhea";
inherit version;
src = ./.;
vendorSha256 = null;
};
defaultPackage = self.packages.${system}.snoo2nebby;
devShell = with pkgs;
mkShell { buildInputs = [ go gopls gotools bashInteractive ]; };
nixosModule = { config, lib, pkgs, ... }:
let cfg = config.within.services.snoo2nebby;
in with lib; {
options.within.services.snoo2nebby = {
enable = mkEnableOption
"enables snoo2nebby for crossposting from reddit to Discord";
subreddit = mkOption {
type = types.str;
default = "tulpas";
description =
"the subreddit name to monitor (the foo of /r/foo)";
};
};
config = mkIf cfg.enable {
users.groups.within = mkDefault {};
users.users.snoo2nebby = {
createHome = true;
description = "tulpa.dev/cadey/snoo2nebby";
isSystemUser = true;
group = "within";
home = "/srv/within/snoo2nebby";
};
systemd.services.snoo2nebby = {
wantedBy = [ "multi-user.target" ];
after = [ "snoo2nebby-key.service" ];
wants = [ "snoo2nebby-key.service" ];
unitConfig.ConditionPathExists = "/srv/within/snoo2nebby/whurl.txt";
serviceConfig = {
User = "snoo2nebby";
Group = "within";
Restart = "on-failure";
WorkingDirectory = "/srv/within/snoo2nebby";
RestartSec = "30s";
};
script = let pkg = self.defaultPackage.${system};
in ''
exec ${pkg}/bin/snoo2nebby -webhook-file /srv/within/snoo2nebby/whurl.txt -subreddit "${cfg.subreddit}"
'';
};
};
};
});
}