Refactor my home-manager config

This commit is contained in:
Tyler Beckman 2024-12-15 22:43:55 -07:00
parent c6100f63d7
commit 7539811ce3
Signed by: Ty
GPG key ID: 2813440C772555A4
31 changed files with 294 additions and 241 deletions

View file

@ -75,16 +75,7 @@
# Home manager # Home manager
home-manager.nixosModules.home-manager home-manager.nixosModules.home-manager
./home-manager ./home-manager
{ { meta.home-manager.preset = "plasma-desktop"; }
ty-home-manager-options = {
plasma.enable = true;
beets.enable = true;
firefox.enable = true;
thunderbird.enable = true;
rescrobbled.enable = true;
vscode.enable = true;
};
}
]; ];
specialArgs = { specialArgs = {
@ -105,16 +96,7 @@
# Home manager # Home manager
home-manager.nixosModules.home-manager home-manager.nixosModules.home-manager
./home-manager ./home-manager
{ { meta.home-manager.preset = "cli"; }
ty-home-manager-options = {
plasma.enable = false;
beets.enable = false;
firefox.enable = false;
thunderbird.enable = false;
rescrobbled.enable = false;
vscode.enable = false;
};
}
# VSCode server support # VSCode server support
vscode-server.nixosModules.default vscode-server.nixosModules.default

View file

@ -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 { PurelyMail = rec {
realName = "Tyler Beckman"; realName = "Tyler Beckman";
address = "ty@myriation.xyz"; address = "ty@myriation.xyz";
@ -38,7 +38,7 @@
}; };
}; };
thunderbird.enable = true; thunderbird.enable = config.meta.home-manager.email.thunderbird.enable;
}; };
Gmail = rec { Gmail = rec {
@ -62,7 +62,7 @@
smtp.tls.useStartTls = false; smtp.tls.useStartTls = false;
thunderbird.enable = true; thunderbird.enable = config.meta.home-manager.email.thunderbird.enable;
}; };
School = rec { School = rec {

View file

@ -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; enable = true;
settings = { settings = {

View file

@ -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
];
}

View file

@ -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) # Override vesktop for matching icon in beautyline (make it generic discord icon)
vesktop = { vesktop = {
categories = [ "Network" "InstantMessaging" "Chat" ]; categories = [ "Network" "InstantMessaging" "Chat" ];

View file

@ -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; enable = true;
policies = { policies = {
ExtensionSettings = { ExtensionSettings = {

View file

@ -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 = { gtk = {
enable = true; enable = true;
gtk2.configLocation = "${config.xdg.configHome}/gtk-2.0/gtkrc"; gtk2.configLocation = "${config.xdg.configHome}/gtk-2.0/gtkrc";
theme = { theme = lib.mkIf config.meta.home-manager.desktop.plasma.enable {
name = "Breeze-Dark"; name = "Breeze-Dark";
package = pkgs.kdePackages.breeze-gtk; package = pkgs.kdePackages.breeze-gtk;
}; };

View file

@ -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
]);
}

View file

@ -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; enable = true;
workspace = { workspace = {

View file

@ -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;
};
};
};
}

View file

@ -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; enable = true;
defaultProfile = "Primary"; defaultProfile = "Primary";
profiles = { profiles = {

View file

@ -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; enable = true;
package = pkgs.thunderbird-latest; package = pkgs.thunderbird-latest;
profiles = { profiles = {

View file

@ -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 { let vscode-package = pkgs.vscodium; in {
enable = true; enable = true;
package = vscode-package; package = vscode-package;

View file

@ -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 <https://github.com/InputUsername/rescrobbled#configuration> 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" ];
};
};
}

View file

@ -1,31 +1,36 @@
{ inputs, system, secrets, lib, config, ... }: { inputs, system, secrets, lib, config, ... }:
{ {
options.ty-home-manager-options = { imports = [ ./meta.nix ];
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";
};
config = { config = {
# Allow user installation of packages
home-manager.useGlobalPkgs = true; home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true; home-manager.useUserPackages = true;
home-manager.sharedModules = [ home-manager.sharedModules = [
# Import plasma manager and all of my custom modules for use
inputs.plasma-manager.homeManagerModules.plasma-manager inputs.plasma-manager.homeManagerModules.plasma-manager
./custom-modules ./modules
]; ];
# Inherit all of my nixos config custom arguments
home-manager.extraSpecialArgs = { home-manager.extraSpecialArgs = {
inherit inputs system secrets; inherit inputs system secrets;
inherit (config) ty-home-manager-options;
}; };
# Hopefully avoid file conflicts
home-manager.backupFileExtension = "backup"; home-manager.backupFileExtension = "backup";
home-manager.users.ty = { home-manager.users.ty = {
imports = [ 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;
}; };
}; };
} }

View file

@ -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
];
}

60
home-manager/meta.nix Normal file
View file

@ -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;
})
];
}

View file

@ -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
]));
}

View file

@ -1,23 +1,85 @@
{ secrets, lib, ty-home-manager-options, ... }: { pkgs, lib, config, ... }:
{ let tomlFormat = pkgs.formats.toml { }; in {
config = lib.mkIf ty-home-manager-options.rescrobbled.enable { options = {
services.custom.rescrobbled = let s = secrets.programs.rescrobbled; in lib.mkIf s.enable { services.custom.rescrobbled = {
enable = true; 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 = { session = lib.mkOption {
player-whitelist = [ "elisa" ]; 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) [ settings = lib.mkOption {
{ type = tomlFormat.type;
token = s.listenbrainz.token; default = {};
} example = lib.literalExpression ''
]; lastfm-key = "Last.fm API key"
lastfm-secret = "Last.fm API secret"
lastfm-key = lib.mkIf (s.lastfm.key != null && s.lastfm.secret != null) s.lastfm.key; min-play-time = 0
lastfm-secret = lib.mkIf (s.lastfm.key != null && s.lastfm.secret != null) s.lastfm.secret; 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 <https://github.com/InputUsername/rescrobbled#configuration> 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" ];
};
};
}