From fe6231475bcb30f851f6b73b4ac3fb1de0718cb2 Mon Sep 17 00:00:00 2001 From: ilkecan Date: Sat, 25 Sep 2021 22:51:11 +0300 Subject: [PATCH 1/2] Remove unnecessary app outputs --- flake.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/flake.nix b/flake.nix index fc4bbe3b..0ce9f209 100644 --- a/flake.nix +++ b/flake.nix @@ -21,9 +21,6 @@ packages = { neuron = project.neuron; }; defaultPackage = packages.neuron; - apps = { neuron = flake-utils.lib.mkApp { drv = packages.neuron; }; }; - defaultApp = apps.neuron; - devShell = project.shell; }); } From c13547f7c5d74085819115ddf611c16ab6951c3e Mon Sep 17 00:00:00 2001 From: ilkecan Date: Thu, 30 Sep 2021 18:59:57 +0300 Subject: [PATCH 2/2] Provide homeManagerModule as a flake output --- flake.nix | 4 +- home-manager-module.nix | 92 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 home-manager-module.nix diff --git a/flake.nix b/flake.nix index 0ce9f209..39ef4287 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; diff --git a/home-manager-module.nix b/home-manager-module.nix new file mode 100644 index 00000000..8c0f12bc --- /dev/null +++ b/home-manager-module.nix @@ -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 ]; + }; + }; + }; +}