feat: nixos module
All checks were successful
build / build (push) Successful in 1m4s

This commit is contained in:
2026-04-18 20:12:20 -06:00
parent 7e6fb22d03
commit b239b416d0
6 changed files with 135 additions and 18 deletions

View File

@@ -5,7 +5,7 @@
, doerg-temml-worker
, ibm-plex-web
, test-emacs ? callPackage ./test-emacs.nix {}
, fake-git
, fake-git ? null
, our-tex
, makeWrapper
, writeText
@@ -33,7 +33,7 @@ let
];
doerg-config = writeText "doerg-extra-config.edn" ''
#:net.deertopia.doerg
#:net.deertopia.doerg.config
{:ibm-plex-web "${ibm-plex-web}"
:latex "${lib.getExe' our-tex "xelatex"}"
:dvisvgm "${lib.getExe' our-tex "dvisvgm"}"
@@ -43,7 +43,15 @@ let
in mkCljBin' {
name = "net.deertopia/doerg";
version = "0.1.0";
projectSrc = lib.cleanSource ./.;
projectSrc = lib.cleanSourceWith {
filter = path: type:
lib.sources.cleanSourceFilter path type
|| lib.hasSuffix ".nix" path;
src = ./.;
};
# lib.sources.sourceFilesBySuffices
# [".nix"]
# (lib.cleanSource ./.);
lockfile = ./deps-lock.json;
main-ns = "net.deertopia.doerg.main";
nativeBuildInputs = [
@@ -74,4 +82,5 @@ in mkCljBin' {
clojure -M:test
'';
passthru = { inherit plex our-tex test-emacs; };
meta.mainProgram = "doerg";
}

View File

@@ -14,12 +14,15 @@
"x86_64-linux"
];
each-system = f: nixpkgs.lib.genAttrs supportedSystems (system: f rec {
pkgs = import nixpkgs {
inherit system;
overlays = [
inputs.sydpkgs.overlays.default
clj-nix.overlays.default
];
each-system = f: nixpkgs.lib.genAttrs supportedSystems (system: f rec {
pkgs = import nixpkgs {
inherit system;
overlays = overlays ++ [
self.overlays.default
];
};
@@ -36,13 +39,17 @@
});
overlays.default = final: prev:
let graal = x: final.mkGraalBin { cljDrv = x; };
let
# is this really the correct way to satisfy our
# dependencies? lmfao
final' = final.appendOverlays overlays;
graal = x: final'.mkGraalBin { cljDrv = x; };
in {
ibm-plex-web = final.callPackage ./ibm-plex-web.nix {};
doerg = final.callPackage ./. {};
doerg-parser = final.callPackage ./doerg-parser {};
doerg-temml-worker = final.callPackage ./doerg-temml-worker {};
our-tex = final.callPackage ./our-tex.nix {};
ibm-plex-web = final'.callPackage ./ibm-plex-web.nix {};
doerg = final'.callPackage ./. {};
doerg-parser = final'.callPackage ./doerg-parser {};
doerg-temml-worker = final'.callPackage ./doerg-temml-worker {};
our-tex = final'.callPackage ./our-tex.nix {};
};
checks = each-system ({ pkgs, system, ... }: {
@@ -52,6 +59,8 @@
(pkgs.lib.attrValues self.packages.${system});
});
nixosModules.default = import ./module.nix { inherit self; };
devShells = each-system ({ pkgs, system, ... }: {
default = pkgs.mkShell {
inputsFrom = [

97
module.nix Normal file
View File

@@ -0,0 +1,97 @@
{ self, ... }:
{ config, lib, pkgs, ... }:
let
cfg = config.services.doerg;
doerg-config = pkgs.writeText "doerg-config.edn" ''
#:net.deertopia.doerg.config
{:org-roam-db-path "${cfg.databasePath}"
:state-directory "${cfg.stateDir}"}
'';
inherit (lib) types;
org-roam-db-sync = pkgs.writeText "org-roam-db-sync.el" ''
#!/usr/bin/env -S emacs -Q -x
(require 'org-roam)
(setq org-roam-directory (expand-file-name (car command-line-args-left)))
(setq org-roam-db-location (expand-file-name (cadr command-line-args-left)))
(org-roam-db-sync)
'';
in {
options.services.doerg = {
enable = lib.mkEnableOption "Doerg";
org-roam-db-sync.enable = lib.mkEnableOption "Org-roam db sync";
port = lib.mkOption {
default = 21984;
type = lib.types.port;
description = ''
The port on which Doerg will listen.
'';
};
stateDir = lib.mkOption {
type = types.path;
default = "/var/lib/private/doerg";
description = "Daemon's state directory.";
};
orgDir = lib.mkOption {
type = types.path;
description = "Org roam directory.";
};
package = lib.mkPackageOption pkgs "doerg" {};
databasePath = lib.mkOption {
type = types.path;
description = "Org roam database path";
default = cfg.orgDir + "org-roam.db";
};
};
config = lib.mkIf cfg.enable {
nixpkgs.overlays = [ self.overlays.default ];
systemd.services.org-roam-db-sync = lib.mkIf cfg.org-roam-db-sync.enable {
script = lib.escapeShellArgs [
(lib.getExe cfg.package.test-emacs)
"-Q" "-x" org-roam-db-sync cfg.orgDir cfg.databasePath
];
serviceConfig = {
Type = "oneshot";
ReadOnlyBindPaths = [
cfg.orgDir
];
};
};
systemd.timers.org-roam-db-sync = lib.mkIf cfg.org-roam-db-sync.enable {
unitConfig.StopWhenUnneeded = true;
timerConfig = {
OnActiveSec = "1h";
RandomizedDelaySec = "30m";
Persistent = true;
};
};
systemd.services.doerg = {
after = [ "network-online.target" ];
wants = [ "network-online.target" "org-roam-db-sync.timer" ];
wantedBy = [ "multi-user.target" ];
environment.DOERG_CONFIG = doerg-config;
serviceConfig = {
# WorkingDirectory = cfg.stateDir;
StateDirectory = "doerg";
ExecStart = lib.getExe cfg.package;
DynamicUser = true;
ProtectSystem = "strict";
PrivateTmp = true;
BindReadOnlyPaths = [
cfg.orgDir
cfg.databasePath
"/nix"
];
};
};
};
}

View File

@@ -1,9 +1,8 @@
#:net.deertopia.doerg.config
{:ibm-plex-web #or [#xdg-data-dir "ibm-plex-web"
#env IBM_PLEX_WEB]
{:ibm-plex-web #or [#env IBM_PLEX_WEB
#xdg-data-dir "ibm-plex-web"]
:latex "xelatex"
:dvisvgm "dvisvgm"
:debug-unimplemented? #profile {:dev true :default false}
:doerg-temml-worker
#profile {:dev #file "../../../../doerg-temml-worker/index.js"
:default "doerg-temml-worker"}

View File

@@ -18,8 +18,10 @@
calling `compute` with no arguments only if stale? is logical true."
[& {:keys [file stale? compute]}]
(when (or (not *use-cache?*) stale?)
(let [r (compute)]
(let [r (compute)
dir (fs/parent file)]
(assert (string? r))
(fs/create-dirs (fs/parent file))
(when-not (fs/exists? dir)
(fs/create-dirs dir))
(spit file r)))
file)

View File

@@ -46,7 +46,8 @@
"Aero tag to search for a directory on $XDG_DATA_DIRS."
(some #(let [x (fs/path % value)]
(and (fs/exists? x) x))
(fs/split-paths (System/getenv "XDG_DATA_DIRS"))))
(some-> (System/getenv "XDG_DATA_DIRS")
fs/split-paths)))
(defmethod aero/reader 'file
[{:keys [source]} tag value]