diff --git a/flake.nix b/flake.nix index 44a32d8..9b912f9 100644 --- a/flake.nix +++ b/flake.nix @@ -34,5 +34,32 @@ shellHook = '' ''; }; + + nixosModule = { options, lib, config, pkgs, ... }: + let + serviceConfig = config.services.mossnet.dhyan; + options.enable = lib.mkEnableOption "Muneem weekly runner"; + in + { + # TODO This won't work either because secrets aren't passed + options.services.mossnet.dhyan = options; + config = lib.mkIf serviceConfig.enable { + systemd.services."dhyan" = { + description = '' + My personal Accountant + ''; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { Type = "oneshot"; }; + startAt = "*08:00:00"; + path = with pkgs; [ babashka jdk11 self.packages.x86_64-linux.muneem ]; + script = '' + set -ex + cd ${self.packages.x86_64-linux.muneem} + bb -m muneem.main + ''; + }; + }; + }; + }; } diff --git a/src/muneem/import.clj b/src/muneem/import.clj index 4292e5e..d701748 100644 --- a/src/muneem/import.clj +++ b/src/muneem/import.clj @@ -50,7 +50,7 @@ reverse) parse-year (-> (trans-date trans) (jt/parse (pt/of-pattern "dd MMM uu")) - (jt/format (pt/of-pattern "YYYY-MM-dd")))] + (jt/format (pt/of-pattern "yyyy-MM-dd")))] (if (and (not (nil? real-date)) (re-matches #"../.." real-date)) (conj statement (clojure.string/join "-" with-year)) (conj statement parse-year)))) @@ -376,7 +376,7 @@ date (-> (sh "date" "+%Y-%m-%d") :out (string/trim-newline))] - (write-statement (str date " balance " account " " b " AUD")))) + (write-statement (vector (str date " balance " account " " b " AUD"))))) (defn main [csv checking? & _args] diff --git a/src/muneem/main.clj b/src/muneem/main.clj index f194636..ec5f874 100644 --- a/src/muneem/main.clj +++ b/src/muneem/main.clj @@ -10,10 +10,13 @@ (import/main "./documents/savings.csv" false) (import/move-beancount-file)) -(comment +(defn bootstrap + [] (import/main "./documents/checking-last-year.csv" true) (import/main "./documents/checking-this-year.csv" true) (import/main "./documents/savings-last-year.csv" false) - (import/main "./documents/savings-this-year.csv" false) + (import/main "./documents/savings-this-year.csv" false)) - (-main)) +(comment + (-main) + (bootstrap))