From 927ab18ee58f6fba7912597e5d8219e6d32dbf3d Mon Sep 17 00:00:00 2001 From: Xe Date: Sat, 19 Feb 2022 16:31:06 -0500 Subject: [PATCH] enable flakes Signed-off-by: Xe --- .envrc | 2 +- .gitignore | 4 ++- default.nix | 5 ++++ flake.lock | 42 +++++++++++++++++++++++++++++++ flake.nix | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 12 +++++---- 6 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc index 051d09d..3550a30 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -eval "$(lorri direnv)" +use flake diff --git a/.gitignore b/.gitignore index 90565d4..bc501d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -var/* \ No newline at end of file +var/* +result +.direnv diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..ce69724 --- /dev/null +++ b/default.nix @@ -0,0 +1,5 @@ +(import (fetchTarball { + url = + "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; +}) { src = ./.; }).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..67f3cdb --- /dev/null +++ b/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1644525281, + "narHash": "sha256-D3VuWLdnLmAXIkooWAtbTGSQI9Fc1lkvAr94wTxhnTU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "48d63e924a2666baf37f4f14a18f19347fbd54a2", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c2740b4 --- /dev/null +++ b/flake.nix @@ -0,0 +1,72 @@ +{ + 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 goimports 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 = pkgs.tulpa.dev.cadey.snoo2nebby; + in '' + exec ${pkg}/bin/snoo2nebby -webhook-file /srv/within/snoo2nebby/whurl.txt -subreddit "${cfg.subreddit}" + ''; + }; + }; + }; + }); +} diff --git a/shell.nix b/shell.nix index 51f655c..77db547 100644 --- a/shell.nix +++ b/shell.nix @@ -1,5 +1,7 @@ -{ pkgs ? import { } }: - -pkgs.mkShell { - buildInputs = with pkgs; [ go gopls goimports bashInteractive ]; -} +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).shellNix