Skip to content

Commit

Permalink
refactor: make program options more modular (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtrrll authored Sep 11, 2024
1 parent a343caa commit 15e63f1
Show file tree
Hide file tree
Showing 46 changed files with 409 additions and 372 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Managed via [Nix](https://nixos.org/) and [Home Manager](https://github.com/nix-
<!-- markdownlint-enable MD013 -->

Alternatively, activate a specific configuration by running the following command.
Replace `<CONFIG>` with the name of a configuration defined in [`flake.nix`](flake.nix):
Replace `<CONFIG>` with name of adefined in [`flake.nix`](flake.nix):

<!-- markdownlint-disable MD013 -->
```sh
Expand Down
81 changes: 39 additions & 42 deletions dotfiles/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,46 @@ homeManagerModules: {
config,
lib,
...
}:
with lib;
{
options = {
dotfiles = {
enable = mkEnableOption "jtrrll's declarative dotfiles.";
username = mkOption {
description = "The name of the user.";
type = types.str;
};
homeDirectory = mkOption {
description = "The home directory of the user.";
type = types.path;
};
};
}: {
config = lib.mkIf config.dotfiles.enable {
assertions = [
{
assertion = lib.strings.hasInfix config.dotfiles.username config.dotfiles.homeDirectory;
message = "homeDirectory (${config.dotfiles.homeDirectory}) must contain username (${config.dotfiles.username}).";
}
];

home = {
inherit (config.dotfiles) homeDirectory username;
stateVersion = "23.11";
};
config = mkIf config.dotfiles.enable {
assertions = [
{
assertion = strings.hasInfix config.dotfiles.username config.dotfiles.homeDirectory;
message = "homeDirectory (${config.dotfiles.homeDirectory}) must contain username (${config.dotfiles.username}).";
}
];
};

home = {
inherit (config.dotfiles) homeDirectory username;
stateVersion = "23.11";
imports =
homeManagerModules
++ [
./programs
./scripts
./theme
{
_module.args = {
constants = import ./constants.nix;
};
}
];

options = {
dotfiles = {
enable = lib.mkEnableOption "jtrrll's declarative dotfiles.";
homeDirectory = lib.mkOption {
default = "/home/${config.dotfiles.username}";
description = "The home directory of the user.";
type = lib.types.path;
};
username = lib.mkOption {
description = "The name of the user.";
type = lib.types.str;
};
programs.home-manager.enable = true;
};
}
// {
imports =
homeManagerModules
++ [
./programs
./scripts
./theme
{
_module.args = {
args = {inherit (config.dotfiles) homeDirectory username;};
constants = import ./constants.nix;
};
}
];
}
};
}
11 changes: 8 additions & 3 deletions dotfiles/programs/alacritty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
config,
lib,
...
}:
with lib; {
config = mkIf config.dotfiles.programs.enable {
}: {
config = lib.mkIf config.dotfiles.programs.alacritty.enable {
programs.alacritty = {
enable = true;
settings = {
Expand All @@ -23,4 +22,10 @@ with lib; {
};
};
};

options = {
dotfiles.programs.alacritty = {
enable = lib.mkEnableOption "Alacritty";
};
};
}
11 changes: 8 additions & 3 deletions dotfiles/programs/shells/bash.nix → dotfiles/programs/bash.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
config,
lib,
...
}:
with lib; {
config = mkIf config.dotfiles.programs.enable {
}: {
config = lib.mkIf config.dotfiles.programs.bash.enable {
programs.bash = {
enable = true;
historyControl = [
Expand Down Expand Up @@ -43,4 +42,10 @@ with lib; {
'';
};
};

options = {
dotfiles.programs.bash = {
enable = lib.mkEnableOption "Bash";
};
};
}
16 changes: 13 additions & 3 deletions dotfiles/programs/bat.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
lib,
pkgs,
...
}:
with lib; {
config = mkIf config.dotfiles.programs.enable {
}: {
config = lib.mkIf config.dotfiles.programs.bat.enable {
programs.bat = {
enable = true;
extraPackages = with pkgs.bat-extras; [batgrep batman];
};
home.shellAliases = {
cat = "bat --paging=never"; # print file (replaces cat)
grep = "batgrep"; # ripgrep with bat as the formatter (replaces grep)
man = "batman"; # read manual pages with bat as the formatter
};
};

options = {
dotfiles.programs.bat = {
enable = lib.mkEnableOption "bat";
};
};
}
15 changes: 9 additions & 6 deletions dotfiles/programs/btop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
config,
lib,
...
}:
with lib; {
config = mkIf config.dotfiles.programs.enable {
}: {
config = lib.mkIf config.dotfiles.programs.btop.enable {
programs.btop = {
enable = true;
settings = {
theme_background = false;
};
settings.theme_background = false;
};
};

options = {
dotfiles.programs.btop = {
enable = lib.mkEnableOption "btop";
};
};
}
29 changes: 7 additions & 22 deletions dotfiles/programs/default.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
{lib, ...}:
with lib; {
{
imports = [
./editors
./shells
./neovim
./vscode
./zellij

./alacritty.nix
./bash.nix
./bat.nix
./btop.nix
./direnv.nix
./eza.nix
./fastfetch.nix
./fzf.nix
./git.nix
./home-manager.nix
./zoxide.nix
./zsh.nix
];
options = {
dotfiles.programs = {
enable = mkOption {
default = true;
description = "Whether to enable a collection of useful program configurations.";
type = types.bool;
};
editors = mkOption {
default = ["neovim" "vscode"];
description = ''
A list of editors to be enabled. Valid values are:
- "neovim"
- "vscode"
'';
type = types.listOf (types.enum ["neovim" "vscode"]);
};
};
};
}
19 changes: 19 additions & 0 deletions dotfiles/programs/direnv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
config,
lib,
...
}: {
config = lib.mkIf config.dotfiles.programs.direnv.enable {
programs.direnv = {
enable = true;
nix-direnv.enable = true;
silent = true;
};
};

options = {
dotfiles.programs.direnv = {
enable = lib.mkEnableOption "direnv";
};
};
}
7 changes: 0 additions & 7 deletions dotfiles/programs/editors/default.nix

This file was deleted.

55 changes: 0 additions & 55 deletions dotfiles/programs/editors/vscode.nix

This file was deleted.

11 changes: 8 additions & 3 deletions dotfiles/programs/eza.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
config,
lib,
...
}:
with lib; {
config = mkIf config.dotfiles.programs.enable {
}: {
config = lib.mkIf config.dotfiles.programs.eza.enable {
programs.eza = {
enable = true;
extraOptions = ["--header"];
git = true;
icons = true;
};
};

options = {
dotfiles.programs.eza = {
enable = lib.mkEnableOption "eza";
};
};
}
13 changes: 8 additions & 5 deletions dotfiles/programs/fastfetch.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
config,
lib,
...
}:
with lib; {
config = mkIf config.dotfiles.programs.enable {
programs.fastfetch = {
enable = true;
}: {
config = lib.mkIf config.dotfiles.programs.fastfetch.enable {
programs.fastfetch.enable = true;
};

options = {
dotfiles.programs.fastfetch = {
enable = lib.mkEnableOption "fastfetch";
};
};
}
13 changes: 8 additions & 5 deletions dotfiles/programs/fzf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
config,
lib,
...
}:
with lib; {
config = mkIf config.dotfiles.programs.enable {
programs.fzf = {
enable = true;
}: {
config = lib.mkIf config.dotfiles.programs.fzf.enable {
programs.fzf.enable = true;
};

options = {
dotfiles.programs.fzf = {
enable = lib.mkEnableOption "fzf";
};
};
}
Loading

0 comments on commit 15e63f1

Please sign in to comment.