about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-05-12 23:24:03 +0200
committerAlan Pearce2024-05-13 00:46:18 +0200
commitad064dfb954a815f1e5175ab42033fc9e1fb6d02 (patch)
tree919fe8c9462acc9b663e556dc85c116035e9cee1
parent895a3b061bb4717955ffbceab3bf3c6ecebacd70 (diff)
downloadsearchix-ad064dfb954a815f1e5175ab42033fc9e1fb6d02.tar.lz
searchix-ad064dfb954a815f1e5175ab42033fc9e1fb6d02.tar.zst
searchix-ad064dfb954a815f1e5175ab42033fc9e1fb6d02.zip
build: export nixos module and overlay
-rw-r--r--flake.nix7
-rw-r--r--nix/modules/default.nix19
-rw-r--r--nix/modules/source-options.nix4
-rw-r--r--nix/package.nix2
4 files changed, 22 insertions, 10 deletions
diff --git a/flake.nix b/flake.nix
index 389c646..82d2bd0 100644
--- a/flake.nix
+++ b/flake.nix
@@ -22,7 +22,12 @@
   };
 
   outputs = { self, nixpkgs, flake-utils, gomod2nix, pre-commit-hooks, simple-css }:
-    (flake-utils.lib.eachDefaultSystem
+    {
+      nixosModules = {
+        default = import ./nix/modules self;
+      };
+      overlays.default = import ./nix/overlays;
+    } // (flake-utils.lib.eachDefaultSystem
       (system:
         let
           pkgs = import nixpkgs {
diff --git a/nix/modules/default.nix b/nix/modules/default.nix
index 6e2c86b..e0544a6 100644
--- a/nix/modules/default.nix
+++ b/nix/modules/default.nix
@@ -1,3 +1,4 @@
+flake:
 { config
 , lib
 , pkgs
@@ -7,7 +8,7 @@
 let
   cfg = config.services.searchix;
 
-  package = (import ../.. { inherit pkgs; }).searchix;
+  package = flake.packages.${pkgs.system}.default;
 
   settingsFormat = pkgs.formats.toml { };
 
@@ -133,7 +134,9 @@ in
             default = "${cfg.homeDir}/data";
           };
           sources = mkOption {
-            type = with types; attrsOf (submodule (import ./source-options.nix { inherit cfg; }));
+            type = with types; attrsOf (submodule (import ./source-options.nix {
+              inherit cfg settingsFormat;
+            }));
             default = {
               nixos.enable = true;
               darwin.enable = false;
@@ -149,17 +152,18 @@ in
   };
 
   config = mkIf cfg.enable {
-    nixpkgs.overlays = [
-      (import "${(import ../sources.nix).gomod2nix}/overlay.nix")
-    ];
-
     systemd.services.searchix-importer = {
       description = "Searchix option importer";
-      unitConfig.Conflicts = [ "searchix-web" ];
+      conflicts = [ "searchix-web.service" ];
+      before = [ "searchix-web.service" ];
       path = with pkgs; [ nix ];
       serviceConfig = defaultServiceConfig // {
         ExecStart = "${package}/bin/import";
         Type = "oneshot";
+
+        RestartSec = 10;
+        RestartSteps = 5;
+        RestartMaxDelaySec = "5 min";
       };
       environment = env;
       startAt = cfg.dates;
@@ -175,6 +179,7 @@ in
     systemd.services.searchix-web = {
       description = "Searchix Nix option search";
       after = [ "searchix-importer.service" ];
+      wants = [ "searchix-importer.service" ];
       wantedBy = [ "multi-user.target" ];
       environment = env;
       serviceConfig = defaultServiceConfig // {
diff --git a/nix/modules/source-options.nix b/nix/modules/source-options.nix
index 4757c89..d60d023 100644
--- a/nix/modules/source-options.nix
+++ b/nix/modules/source-options.nix
@@ -1,9 +1,11 @@
-{ cfg }:
+{ cfg, settingsFormat }:
 { config, lib, name, ... }:
 let
   inherit (lib) literalExpression mkOption mkEnableOption types;
 in
 {
+  freeformType = settingsFormat.type;
+
   options = {
     key = mkOption {
       type = types.strMatching "[a-z0-9_-]*";
diff --git a/nix/package.nix b/nix/package.nix
index 6c942b0..ffb0a16 100644
--- a/nix/package.nix
+++ b/nix/package.nix
@@ -1,7 +1,7 @@
 { pkgs ? (
     let
       inherit (builtins) fetchTree fromJSON readFile;
-      inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix;
+      inherit ((fromJSON (readFile ../flake.lock)).nodes) nixpkgs gomod2nix;
     in
     import (fetchTree nixpkgs.locked) {
       overlays = [