Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide homeManagerModule as a flake output #662

Merged
merged 2 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
};

outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
{
homeManagerModule = import ./home-manager-module.nix;
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
project = import ./project.nix { inherit pkgs; };
Expand All @@ -21,9 +23,6 @@
packages = { neuron = project.neuron; };
defaultPackage = packages.neuron;

apps = { neuron = flake-utils.lib.mkApp { drv = packages.neuron; }; };
defaultApp = apps.neuron;

srid marked this conversation as resolved.
Show resolved Hide resolved
devShell = project.shell;
});
}
92 changes: 92 additions & 0 deletions home-manager-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{ config, lib, pkgs, ... }:

let
inherit (lib)
mkEnableOption
mkIf
mkOption
types
;

cfg = config.services.neuron;
in
{
options = {
services.neuron = {
enable = mkEnableOption ''
Future-proof note-taking and publishing based on Zettelkasten
'';

package = mkOption {
type = types.package;
default = pkgs.neuron-notes;
defaultText = "pkgs.neuron-notes";
description = "neuron derivation to use";
};

notesDirectory = mkOption {
type = types.nullOr types.path;
default = null;
example = "/home/\${name}/zettelkasten";
description = "Directory that holds the neuron notes";
};

host = mkOption {
type = types.str;
default = "127.0.0.1";
description = "The hostname or IP address the HTTP server should listen to";
};

port = mkOption {
type = types.port;
default = 8080;
description = "Port the HTTP server should listen to";
};

prettyUrls = mkOption {
type = types.bool;
default = false;
description = "If set, drops the .html at the end of Zettel URLs.";
};

systemdTarget = mkOption {
type = types.str;
default = "graphical-session.target";
description = "Systemd target to bind to";
};
};
};

config = mkIf cfg.enable {
assertions = [
{
assertion = cfg.notesDirectory != null;
message = "`services.neuron.notesDirectory' must be set.";
}
];

systemd.user.services.neuron = {
Unit = {
Description = "Neuron zettelkasten service";
PartOf = [ cfg.systemdTarget ];
After = [ cfg.systemdTarget ];
};

Service = {
Type = "exec";
ExecStart = ''
${cfg.package}/bin/neuron \
-d ${cfg.notesDirectory} \
gen \
--watch \
--serve ${cfg.host}:${toString cfg.port} \
${lib.optionalString cfg.prettyUrls "--pretty-urls"}
'';
};

Install = {
WantedBy = [ cfg.systemdTarget ];
};
};
};
}