diff --git a/flake.nix b/flake.nix index 36daa89..fa804dc 100755 --- a/flake.nix +++ b/flake.nix @@ -75,16 +75,7 @@ # Home manager home-manager.nixosModules.home-manager ./home-manager - { - ty-home-manager-options = { - plasma.enable = true; - beets.enable = true; - firefox.enable = true; - thunderbird.enable = true; - rescrobbled.enable = true; - vscode.enable = true; - }; - } + { meta.home-manager.preset = "plasma-desktop"; } ]; specialArgs = { @@ -105,16 +96,7 @@ # Home manager home-manager.nixosModules.home-manager ./home-manager - { - ty-home-manager-options = { - plasma.enable = false; - beets.enable = false; - firefox.enable = false; - thunderbird.enable = false; - rescrobbled.enable = false; - vscode.enable = false; - }; - } + { meta.home-manager.preset = "cli"; } # VSCode server support vscode-server.nixosModules.default diff --git a/home-manager/modules/accounts/default.nix b/home-manager/config/accounts/default.nix similarity index 100% rename from home-manager/modules/accounts/default.nix rename to home-manager/config/accounts/default.nix diff --git a/home-manager/modules/accounts/email.nix b/home-manager/config/accounts/email.nix similarity index 88% rename from home-manager/modules/accounts/email.nix rename to home-manager/config/accounts/email.nix index 09f5b91..925b4ff 100755 --- a/home-manager/modules/accounts/email.nix +++ b/home-manager/config/accounts/email.nix @@ -1,6 +1,6 @@ -{ lib, ty-home-manager-options, ... }: +{ lib, config, ... }: { - accounts.email.accounts = lib.mkIf ty-home-manager-options.thunderbird.enable { + accounts.email.accounts = lib.mkIf config.meta.home-manager.email.enable { PurelyMail = rec { realName = "Tyler Beckman"; address = "ty@myriation.xyz"; @@ -38,7 +38,7 @@ }; }; - thunderbird.enable = true; + thunderbird.enable = config.meta.home-manager.email.thunderbird.enable; }; Gmail = rec { @@ -62,7 +62,7 @@ smtp.tls.useStartTls = false; - thunderbird.enable = true; + thunderbird.enable = config.meta.home-manager.email.thunderbird.enable; }; School = rec { diff --git a/home-manager/modules/accounts/ssh.nix b/home-manager/config/accounts/ssh.nix similarity index 100% rename from home-manager/modules/accounts/ssh.nix rename to home-manager/config/accounts/ssh.nix diff --git a/home-manager/modules/beets.nix b/home-manager/config/beets.nix similarity index 85% rename from home-manager/modules/beets.nix rename to home-manager/config/beets.nix index 687790c..18f4767 100644 --- a/home-manager/modules/beets.nix +++ b/home-manager/config/beets.nix @@ -1,6 +1,6 @@ -{ lib, secrets, ty-home-manager-options, ... }: +{ lib, secrets, config, ... }: { - programs.beets = lib.mkIf ty-home-manager-options.beets.enable { + programs.beets = lib.mkIf config.meta.home-manager.beets.enable { enable = true; settings = { diff --git a/home-manager/config/default.nix b/home-manager/config/default.nix new file mode 100644 index 0000000..d252ab8 --- /dev/null +++ b/home-manager/config/default.nix @@ -0,0 +1,20 @@ +{ ... }: +{ + imports = [ + # Directories + ./accounts + ./shell + ./vcs + # Individual files + ./beets.nix + ./desktop.nix + ./firefox.nix + ./gpg.nix + ./gtk.nix + ./packages.nix + ./plasma.nix + ./rescrobbled.nix + ./thunderbird.nix + ./vscode.nix + ]; +} \ No newline at end of file diff --git a/home-manager/modules/desktop.nix b/home-manager/config/desktop.nix similarity index 77% rename from home-manager/modules/desktop.nix rename to home-manager/config/desktop.nix index ccc3957..450d004 100644 --- a/home-manager/modules/desktop.nix +++ b/home-manager/config/desktop.nix @@ -1,6 +1,6 @@ -{ lib, ty-home-manager-options, ... }: +{ lib, config, ... }: { - xdg.desktopEntries = lib.mkIf ty-home-manager-options.plasma.enable { + xdg.desktopEntries = lib.mkIf config.meta.home-manager.desktop.enable { # Override vesktop for matching icon in beautyline (make it generic discord icon) vesktop = { categories = [ "Network" "InstantMessaging" "Chat" ]; diff --git a/home-manager/modules/firefox.nix b/home-manager/config/firefox.nix similarity index 98% rename from home-manager/modules/firefox.nix rename to home-manager/config/firefox.nix index 45f3357..569b8d6 100755 --- a/home-manager/modules/firefox.nix +++ b/home-manager/config/firefox.nix @@ -1,6 +1,6 @@ -{ pkgs, inputs, system, lib, ty-home-manager-options, ... }: +{ pkgs, inputs, system, lib, config, ... }: { - programs.firefox = lib.mkIf ty-home-manager-options.firefox.enable { + programs.firefox = lib.mkIf config.meta.home-manager.firefox.enable { enable = true; policies = { ExtensionSettings = { diff --git a/home-manager/modules/gpg.nix b/home-manager/config/gpg.nix similarity index 100% rename from home-manager/modules/gpg.nix rename to home-manager/config/gpg.nix diff --git a/home-manager/modules/gtk.nix b/home-manager/config/gtk.nix similarity index 81% rename from home-manager/modules/gtk.nix rename to home-manager/config/gtk.nix index 62e3fa2..43286f0 100644 --- a/home-manager/modules/gtk.nix +++ b/home-manager/config/gtk.nix @@ -1,12 +1,12 @@ -{ pkgs, lib, config, ty-home-manager-options, ... }: +{ pkgs, lib, config, ... }: { - config = lib.mkIf ty-home-manager-options.plasma.enable { + config = lib.mkIf config.meta.home-manager.desktop.enable { gtk = { enable = true; gtk2.configLocation = "${config.xdg.configHome}/gtk-2.0/gtkrc"; - theme = { + theme = lib.mkIf config.meta.home-manager.desktop.plasma.enable { name = "Breeze-Dark"; package = pkgs.kdePackages.breeze-gtk; }; diff --git a/home-manager/config/packages.nix b/home-manager/config/packages.nix new file mode 100755 index 0000000..9a1a0b4 --- /dev/null +++ b/home-manager/config/packages.nix @@ -0,0 +1,73 @@ +{ pkgs, inputs, system, lib, config, ... }: +{ + home.packages = + ## Packages that are always installed, no matter what + (with pkgs; [ + # :3 + fastfetch # Modern & faster neofetch alternative + + # CLI Tools + ripgrep # Text searching and manipulation + jq # JSON filtering + eza # Directory lister + bat # File reading + doggo # DNS Requests + nmap # Network scanning + glow # Markdown rendering + tealdeer # TLDR + usbutils # `lsusb` + pciutils # `lspci` + unzip # Extract zip files + + # Process tools + btop # Process monitor + nvtopPackages.full # GPU monitor + ]) + ## Packages that are only installed when a desktop environment is desired + ++ (lib.optionals config.meta.home-manager.desktop.enable (with pkgs; [ + # Documents + logseq # Outliner + libreoffice-qt6-fresh # Office-style editing + hunspell + hunspellDicts.en_US-large + + # Video + jellyfin-media-player # Jellyfin electron client w/ MPV + vlc # Video file player + + # Chat + element-desktop # Matrix client + vesktop # Discord client + signal-desktop # Signal client + + # KDE Themes + vimix-cursors # Cursors + (pkgs.callPackage ../../packages/beautyline {}) # Icons + (pkgs.callPackage ../../packages/magna-splash-6 {}) # Splash + + # Programming + jetbrains.idea-ultimate # Jetbrains IntelliJ Idea Ultimate IDE + nixd # LSP for .nix files + gcc # GNU C++ Compiler + (lib.meta.hiPrio clang) # LLVM C++ Compiler (better than g++) + clang-tools # Clang language server + cling # C++ REPL + deno # Typescript & Javascript runtime + gnumake # Makefile support + + # UI Tools + qalculate-qt # Calculator + ])) + ## Packages that are only installed if plasma is used as the desktop environment + ++ (lib.optionals config.meta.home-manager.desktop.plasma.enable (with pkgs.kdePackages; [ + kate # IDE + elisa # Music + kdeconnect-kde # Phone sync + polkit-kde-agent-1 # Polkit authentication popup support + ])) + ## Firefox is only installed when requested + ++ (lib.optionals config.meta.home-manager.firefox.enable [ + # Firefox nightly + inputs.firefox-nightly.packages.${system}.firefox-nightly-bin + ]); +} diff --git a/home-manager/modules/plasma.nix b/home-manager/config/plasma.nix similarity index 97% rename from home-manager/modules/plasma.nix rename to home-manager/config/plasma.nix index f94511f..3dc40d3 100755 --- a/home-manager/modules/plasma.nix +++ b/home-manager/config/plasma.nix @@ -1,6 +1,6 @@ -{ pkgs, lib, ty-home-manager-options, ... }: +{ pkgs, lib, config, ... }: { - programs.plasma = lib.mkIf ty-home-manager-options.plasma.enable { + programs.plasma = lib.mkIf config.meta.home-manager.desktop.plasma.enable { enable = true; workspace = { diff --git a/home-manager/config/rescrobbled.nix b/home-manager/config/rescrobbled.nix new file mode 100644 index 0000000..f314e0f --- /dev/null +++ b/home-manager/config/rescrobbled.nix @@ -0,0 +1,23 @@ +{ secrets, lib, config, ... }: +{ + config = lib.mkIf config.meta.home-manager.rescrobbled.enable { + services.custom.rescrobbled = let s = secrets.programs.rescrobbled; in lib.mkIf s.enable { + enable = true; + + session = s.lastfm.session; + + settings = { + player-whitelist = [ "elisa" ]; + + listenbrainz = lib.mkIf (s.listenbrainz.token != null) [ + { + token = s.listenbrainz.token; + } + ]; + + lastfm-key = lib.mkIf (s.lastfm.key != null && s.lastfm.secret != null) s.lastfm.key; + lastfm-secret = lib.mkIf (s.lastfm.key != null && s.lastfm.secret != null) s.lastfm.secret; + }; + }; + }; +} \ No newline at end of file diff --git a/home-manager/modules/shell/btop.nix b/home-manager/config/shell/btop.nix similarity index 100% rename from home-manager/modules/shell/btop.nix rename to home-manager/config/shell/btop.nix diff --git a/home-manager/modules/shell/default.nix b/home-manager/config/shell/default.nix similarity index 100% rename from home-manager/modules/shell/default.nix rename to home-manager/config/shell/default.nix diff --git a/home-manager/modules/shell/direnv.nix b/home-manager/config/shell/direnv.nix similarity index 100% rename from home-manager/modules/shell/direnv.nix rename to home-manager/config/shell/direnv.nix diff --git a/home-manager/modules/shell/konsole.nix b/home-manager/config/shell/konsole.nix similarity index 82% rename from home-manager/modules/shell/konsole.nix rename to home-manager/config/shell/konsole.nix index 17ec13c..f294b3d 100644 --- a/home-manager/modules/shell/konsole.nix +++ b/home-manager/config/shell/konsole.nix @@ -1,6 +1,6 @@ -{ pkgs, lib, ty-home-manager-options, ... }: +{ pkgs, lib, config, ... }: { - programs.konsole = lib.mkIf ty-home-manager-options.plasma.enable { + programs.konsole = lib.mkIf config.meta.home-manager.desktop.plasma.enable { enable = true; defaultProfile = "Primary"; profiles = { diff --git a/home-manager/modules/shell/starship.nix b/home-manager/config/shell/starship.nix similarity index 100% rename from home-manager/modules/shell/starship.nix rename to home-manager/config/shell/starship.nix diff --git a/home-manager/modules/shell/zsh.nix b/home-manager/config/shell/zsh.nix similarity index 100% rename from home-manager/modules/shell/zsh.nix rename to home-manager/config/shell/zsh.nix diff --git a/home-manager/modules/thunderbird.nix b/home-manager/config/thunderbird.nix similarity index 70% rename from home-manager/modules/thunderbird.nix rename to home-manager/config/thunderbird.nix index f865b47..5409868 100755 --- a/home-manager/modules/thunderbird.nix +++ b/home-manager/config/thunderbird.nix @@ -1,6 +1,6 @@ -{ pkgs, lib, ty-home-manager-options, ... }: +{ pkgs, lib, config, ... }: { - programs.thunderbird = lib.mkIf ty-home-manager-options.thunderbird.enable { + programs.thunderbird = lib.mkIf config.meta.home-manager.email.thunderbird.enable { enable = true; package = pkgs.thunderbird-latest; profiles = { diff --git a/home-manager/modules/vcs/default.nix b/home-manager/config/vcs/default.nix similarity index 100% rename from home-manager/modules/vcs/default.nix rename to home-manager/config/vcs/default.nix diff --git a/home-manager/modules/vcs/git.nix b/home-manager/config/vcs/git.nix similarity index 100% rename from home-manager/modules/vcs/git.nix rename to home-manager/config/vcs/git.nix diff --git a/home-manager/modules/vcs/jj.nix b/home-manager/config/vcs/jj.nix similarity index 100% rename from home-manager/modules/vcs/jj.nix rename to home-manager/config/vcs/jj.nix diff --git a/home-manager/modules/vscode.nix b/home-manager/config/vscode.nix similarity index 97% rename from home-manager/modules/vscode.nix rename to home-manager/config/vscode.nix index 7ce274f..f8170cd 100644 --- a/home-manager/modules/vscode.nix +++ b/home-manager/config/vscode.nix @@ -1,6 +1,6 @@ -{ pkgs, inputs, system, lib, ty-home-manager-options, ... }: +{ pkgs, inputs, system, lib, config, ... }: { - programs.vscode = lib.mkIf ty-home-manager-options.vscode.enable ( + programs.vscode = lib.mkIf config.meta.home-manager.vscode.enable ( let vscode-package = pkgs.vscodium; in { enable = true; package = vscode-package; diff --git a/home-manager/custom-modules/rescrobbled.nix b/home-manager/custom-modules/rescrobbled.nix deleted file mode 100644 index 9f0edf3..0000000 --- a/home-manager/custom-modules/rescrobbled.nix +++ /dev/null @@ -1,85 +0,0 @@ -{ pkgs, lib, config, ... }: -let tomlFormat = pkgs.formats.toml { }; in { - options = { - services.custom.rescrobbled = { - enable = lib.mkEnableOption "rescrobbled"; - - package = lib.mkOption { - type = lib.types.package; - default = (pkgs.callPackage ../../packages/rescrobbled {}); - defaultText = lib.literalExpression "pkgs.rescrobbled"; - description = "The package to use for rescrobbled"; - }; - - session = lib.mkOption { - type = lib.types.str; - description = '' - The session token to use for last.fm. - This can be found by setting a last.fm API key & secret, - and then manually running the daemon. Then, the session token - will be located at {file}`$XDG_CONFIG_HOME/rescrobbled/session`. - ''; - default = null; - }; - - settings = lib.mkOption { - type = tomlFormat.type; - default = {}; - example = lib.literalExpression '' - lastfm-key = "Last.fm API key" - lastfm-secret = "Last.fm API secret" - min-play-time = 0 - player-whitelist = [ "Player MPRIS identity or bus name" ] - filter-script = "path/to/script" - - [[listenbrainz]] - url = "Custom API URL" - token = "User token" - ''; - description = '' - Configuration written to - {file}`$XDG_CONFIG_HOME/rescrobbled/config.toml`. - - See for the full list - of options. - ''; - }; - }; - }; - - config = let cfg = config.services.custom.rescrobbled; in lib.mkIf cfg.enable { - home.packages = [ cfg.package ]; - - xdg.configFile ={ - "rescrobbled/config.toml" = lib.mkIf (cfg.settings != { }) { - enable = true; - - source = tomlFormat.generate "rescrobbled-config" cfg.settings; - }; - - "rescrobbled/session" = lib.mkIf (cfg.settings != { }) { - enable = true; - # Force makes it easy to generate the session file, then add it to nix cfg without issues - force = true; - - text = cfg.session; - }; - }; - - systemd.user.services.rescrobbled = { - Unit = { - Description = "An MPRIS scrobbler"; - Documentation = "https://github.com/InputUsername/rescrobbled"; - Wants = "network-online.target"; - After = "network-online.target"; - }; - - Service = { - ExecStartPre = "${pkgs.coreutils}/bin/sleep 15"; # Avoid listenbrainz errors by adding delay till network is connected - ExecStart = "${cfg.package}/bin/rescrobbled"; - }; - - Install.WantedBy = [ "default.target" ]; - }; - }; -} diff --git a/home-manager/default.nix b/home-manager/default.nix index 28eac10..cb37770 100755 --- a/home-manager/default.nix +++ b/home-manager/default.nix @@ -1,31 +1,36 @@ { inputs, system, secrets, lib, config, ... }: { - options.ty-home-manager-options = { - plasma.enable = lib.mkEnableOption "plasma configuration"; - firefox.enable = lib.mkEnableOption "firefox configuration"; - thunderbird.enable = lib.mkEnableOption "thunderbird configuration"; - vscode.enable = lib.mkEnableOption "vscode configuration"; - beets.enable = lib.mkEnableOption "beets configuration"; - rescrobbled.enable = lib.mkEnableOption "rescrobbled configuration"; - }; + imports = [ ./meta.nix ]; config = { + # Allow user installation of packages home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; home-manager.sharedModules = [ + # Import plasma manager and all of my custom modules for use inputs.plasma-manager.homeManagerModules.plasma-manager - ./custom-modules + ./modules ]; + # Inherit all of my nixos config custom arguments home-manager.extraSpecialArgs = { inherit inputs system secrets; - inherit (config) ty-home-manager-options; }; + + # Hopefully avoid file conflicts home-manager.backupFileExtension = "backup"; home-manager.users.ty = { imports = [ - ./home.nix + # Import meta options for configuring the configuration + ./meta.nix + # Import all of my config + ./config ]; + + home.stateVersion = "24.05"; + + # Inherit my home manager config options + meta.home-manager = config.meta.home-manager; }; }; } \ No newline at end of file diff --git a/home-manager/home.nix b/home-manager/home.nix deleted file mode 100755 index df4f9d7..0000000 --- a/home-manager/home.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ lib, config, ... }: -{ - home.stateVersion = "24.05"; - home.username = "ty"; - home.homeDirectory = "/home/ty"; - - imports = [ - ./modules/packages.nix - ./modules/plasma.nix - ./modules/vcs - ./modules/firefox.nix - ./modules/thunderbird.nix - ./modules/accounts - ./modules/gpg.nix - ./modules/shell - ./modules/vscode.nix - ./modules/desktop.nix - ./modules/gtk.nix - ./modules/beets.nix - ./modules/rescrobbled.nix - ]; -} \ No newline at end of file diff --git a/home-manager/meta.nix b/home-manager/meta.nix new file mode 100644 index 0000000..740163d --- /dev/null +++ b/home-manager/meta.nix @@ -0,0 +1,60 @@ +{ lib, config, ... }: +{ + options.meta.home-manager = { + # Presets for easy configuring the configuration + preset = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "plasma-desktop" "cli" ]); + default = null; + defaultText = lib.literalExpression "null"; + description = '' + The preset to use for enabling individual home-manager meta configuration options. + + Presets: + - plasma-desktop + - Will enable anything that requires a desktop, and plasma-specific configuration + - cli + - Will only enable what is necessary for a CLI environment, excluding everything else + ''; + }; + + # Individual configuration options + beets.enable = lib.mkEnableOption "beets configuration"; + desktop = { + enable = lib.mkEnableOption "configuration that requires a desktop environment"; + plasma.enable = lib.mkEnableOption "plasma configuration"; + }; + email = { + enable = lib.mkEnableOption "email configuration"; + thunderbird.enable = lib.mkEnableOption "email configuration for thunderbird"; + }; + firefox.enable = lib.mkEnableOption "firefox configuration"; + rescrobbled.enable = lib.mkEnableOption "rescrobbled configuration"; + vscode.enable = lib.mkEnableOption "vscode configuration"; + }; + + # Handle preset logic + config.meta.home-manager = lib.mkMerge [ + # Desktop w/ Plasma preset + (lib.mkIf (config.meta.home-manager.preset == "plasma-desktop") { + beets.enable = true; + desktop.enable = true; + desktop.plasma.enable = true; + email.enable = true; + email.thunderbird.enable = true; + firefox.enable = true; + rescrobbled.enable = true; + vscode.enable = true; + }) + # CLI Preset + (lib.mkIf (config.meta.home-manager.preset == "cli") { + beets.enable = false; + desktop.enable = false; + desktop.plasma.enable = false; + email.enable = false; + email.thunderbird.enable = false; + firefox.enable = false; + rescrobbled.enable = false; + vscode.enable = false; + }) + ]; +} \ No newline at end of file diff --git a/home-manager/custom-modules/default.nix b/home-manager/modules/default.nix similarity index 100% rename from home-manager/custom-modules/default.nix rename to home-manager/modules/default.nix diff --git a/home-manager/modules/packages.nix b/home-manager/modules/packages.nix deleted file mode 100755 index 598f16a..0000000 --- a/home-manager/modules/packages.nix +++ /dev/null @@ -1,65 +0,0 @@ -{ pkgs, inputs, system, lib, ty-home-manager-options, ... }: -{ - home.packages = (with pkgs; [ - # :3 - fastfetch # Modern & faster neofetch alternative - - # CLI Tools - ripgrep # Text searching and manipulation - jq # JSON filtering - eza # Directory lister - bat # File reading - doggo # DNS Requests - nmap # Network scanning - glow # Markdown rendering - tealdeer # TLDR - usbutils # `lsusb` - pciutils # `lspci` - unzip # Extract zip files - - # Process tools - btop # Process monitor - nvtopPackages.full # GPU monitor - ]) ++ (lib.optionals ty-home-manager-options.plasma.enable (with pkgs; [ - # Documents - logseq # Outliner - libreoffice-qt6-fresh # Office-style editing - hunspell - hunspellDicts.en_US-large - - # Video - jellyfin-media-player # Jellyfin electron client w/ MPV - vlc # Video file player - - # Chat - element-desktop # Matrix client - vesktop # Discord client - signal-desktop # Signal client - - # KDE Themes - vimix-cursors # Cursors - (pkgs.callPackage ../../packages/beautyline {}) # Icons - (pkgs.callPackage ../../packages/magna-splash-6 {}) # Splash - - # Programming - jetbrains.idea-ultimate # Jetbrains IntelliJ Idea Ultimate IDE - nixd # LSP for .nix files - gcc # GNU C++ Compiler - (lib.meta.hiPrio clang) # LLVM C++ Compiler (better than g++) - clang-tools # Clang language server - cling # C++ REPL - deno # Typescript & Javascript runtime - gnumake # Makefile support - - # UI Tools - qalculate-qt # Calculator - ])) ++ (lib.optionals ty-home-manager-options.firefox.enable [ - # Firefox nightly - inputs.firefox-nightly.packages.${system}.firefox-nightly-bin - ]) ++ (lib.optionals ty-home-manager-options.plasma.enable (with pkgs.kdePackages; [ - kate # IDE - elisa # Music - kdeconnect-kde # Phone sync - polkit-kde-agent-1 # Polkit authentication popup support - ])); -} diff --git a/home-manager/modules/rescrobbled.nix b/home-manager/modules/rescrobbled.nix index b718c64..9f0edf3 100644 --- a/home-manager/modules/rescrobbled.nix +++ b/home-manager/modules/rescrobbled.nix @@ -1,23 +1,85 @@ -{ secrets, lib, ty-home-manager-options, ... }: -{ - config = lib.mkIf ty-home-manager-options.rescrobbled.enable { - services.custom.rescrobbled = let s = secrets.programs.rescrobbled; in lib.mkIf s.enable { - enable = true; +{ pkgs, lib, config, ... }: +let tomlFormat = pkgs.formats.toml { }; in { + options = { + services.custom.rescrobbled = { + enable = lib.mkEnableOption "rescrobbled"; - session = s.lastfm.session; + package = lib.mkOption { + type = lib.types.package; + default = (pkgs.callPackage ../../packages/rescrobbled {}); + defaultText = lib.literalExpression "pkgs.rescrobbled"; + description = "The package to use for rescrobbled"; + }; - settings = { - player-whitelist = [ "elisa" ]; + session = lib.mkOption { + type = lib.types.str; + description = '' + The session token to use for last.fm. + This can be found by setting a last.fm API key & secret, + and then manually running the daemon. Then, the session token + will be located at {file}`$XDG_CONFIG_HOME/rescrobbled/session`. + ''; + default = null; + }; - listenbrainz = lib.mkIf (s.listenbrainz.token != null) [ - { - token = s.listenbrainz.token; - } - ]; - - lastfm-key = lib.mkIf (s.lastfm.key != null && s.lastfm.secret != null) s.lastfm.key; - lastfm-secret = lib.mkIf (s.lastfm.key != null && s.lastfm.secret != null) s.lastfm.secret; + settings = lib.mkOption { + type = tomlFormat.type; + default = {}; + example = lib.literalExpression '' + lastfm-key = "Last.fm API key" + lastfm-secret = "Last.fm API secret" + min-play-time = 0 + player-whitelist = [ "Player MPRIS identity or bus name" ] + filter-script = "path/to/script" + + [[listenbrainz]] + url = "Custom API URL" + token = "User token" + ''; + description = '' + Configuration written to + {file}`$XDG_CONFIG_HOME/rescrobbled/config.toml`. + + See for the full list + of options. + ''; }; }; }; -} \ No newline at end of file + + config = let cfg = config.services.custom.rescrobbled; in lib.mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile ={ + "rescrobbled/config.toml" = lib.mkIf (cfg.settings != { }) { + enable = true; + + source = tomlFormat.generate "rescrobbled-config" cfg.settings; + }; + + "rescrobbled/session" = lib.mkIf (cfg.settings != { }) { + enable = true; + # Force makes it easy to generate the session file, then add it to nix cfg without issues + force = true; + + text = cfg.session; + }; + }; + + systemd.user.services.rescrobbled = { + Unit = { + Description = "An MPRIS scrobbler"; + Documentation = "https://github.com/InputUsername/rescrobbled"; + Wants = "network-online.target"; + After = "network-online.target"; + }; + + Service = { + ExecStartPre = "${pkgs.coreutils}/bin/sleep 15"; # Avoid listenbrainz errors by adding delay till network is connected + ExecStart = "${cfg.package}/bin/rescrobbled"; + }; + + Install.WantedBy = [ "default.target" ]; + }; + }; +}