diff --git a/flake.nix b/flake.nix index 762686e..98d8782 100644 --- a/flake.nix +++ b/flake.nix @@ -146,6 +146,7 @@ colors = ./home/modules/colors.nix; gpg = ./home/modules/programs/gpg; neovim-auto-clean-swapfiles = ./home/modules/programs/neovim/auto-clean-swapfiles.nix; + nix-index-auto-update-database = ./home/modules/programs/nix-index/auto-update-database.nix; }; homeConfigurations = { diff --git a/home/home.nix b/home/home.nix index 53e6938..0807eda 100644 --- a/home/home.nix +++ b/home/home.nix @@ -51,6 +51,7 @@ in { ./modules/uidGid.nix ./modules/programs/gpg ./modules/programs/neovim/auto-clean-swapfiles.nix + ./modules/programs/nix-index/auto-update-database.nix ] ++ (optionals graphics [ ./config/gtk.nix diff --git a/home/programs/nix-index/fetch-nix-index-database.nix b/home/modules/programs/nix-index/auto-update-database.nix similarity index 73% rename from home/programs/nix-index/fetch-nix-index-database.nix rename to home/modules/programs/nix-index/auto-update-database.nix index a192ba8..451f9c6 100644 --- a/home/programs/nix-index/fetch-nix-index-database.nix +++ b/home/modules/programs/nix-index/auto-update-database.nix @@ -1,12 +1,25 @@ { config, pkgs, lib, ... }: let - cfg = config.programs.nix-index; + cfg = config.programs.nix-index.autoUpdateDatabase; in { - options.programs.nix-index.enableDatabaseFetcher = lib.mkEnableOption "timed unit that fetches an updated database of nixpkgs outputs"; + options.programs.nix-index.autoUpdateDatabase = { + enable = lib.mkEnableOption "timed unit that fetches an updated database of nixpkgs outputs"; + + # TODO: let users specify forks and other sources + # url = ""; + + onCalendar = lib.mkOption { + type = lib.types.str; + default = "weekly"; + example = "montly"; + # TODO: link to systemd manpage for format. + description = "How often to update the database."; + }; + }; config = { - systemd.user.timers.fetch-nix-index-database = lib.mkIf cfg.enableDatabaseFetcher { + systemd.user.timers.fetch-nix-index-database = lib.mkIf cfg.enable { Unit = { Description = "Fetch nix-index database"; Documentation = [ "https://github.com/nix-community/nix-index-database" ]; @@ -14,7 +27,7 @@ in Timer = { Unit = "fetch-nix-index-database.service"; - OnCalendar = "weekly"; + OnCalendar = cfg.onCalendar; Persistent = true; }; @@ -23,7 +36,7 @@ in }; }; - systemd.user.services.fetch-nix-index-database = lib.mkIf cfg.enableDatabaseFetcher { + systemd.user.services.fetch-nix-index-database = lib.mkIf cfg.enable { Unit = { Description = "Fetch nix-index database"; Documentation = [ "https://github.com/nix-community/nix-index-database" ]; @@ -39,6 +52,8 @@ in wget ]; + # TODO: allow fetching with gh + github token + # Source: https://github.com/nix-community/nix-index-database?tab=readme-ov-file#ad-hoc-download # Slightly modified to satisfy shellcheck text = '' diff --git a/home/programs/nix-index/default.nix b/home/programs/nix-index/default.nix index 3b7192d..892ab5f 100644 --- a/home/programs/nix-index/default.nix +++ b/home/programs/nix-index/default.nix @@ -1,9 +1,7 @@ { ... }: { - imports = [ ./fetch-nix-index-database.nix ]; - programs.nix-index = { enable = true; - enableDatabaseFetcher = true; + autoUpdateDatabase.enable = true; }; -} \ No newline at end of file +}