Skip to content

Commit

Permalink
Merge pull request #264 from himkt/nix-modularized
Browse files Browse the repository at this point in the history
misc(nix): make nix files more modularized
  • Loading branch information
himkt authored Dec 6, 2024
2 parents fb8d514 + cb13c0a commit 8885f7a
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 134 deletions.
93 changes: 14 additions & 79 deletions nix/config.d/darwin.nix
Original file line number Diff line number Diff line change
@@ -1,92 +1,27 @@
{ pkgs, ... }: {
# List packages installed in system profile. To search by name, run:
# $ nix-env -qaP | grep wget
environment.systemPackages = [
];

fonts.packages = [
pkgs.jetbrains-mono
];
{ ... }:

{
# Necessary for using flakes on this system.
nix.settings.experimental-features = "nix-command flakes";
nix.settings.trusted-users = [ "root" "himkt" ];

# Enable alternative shell support in nix-darwin.
# programs.fish.enable = true;
imports = [
./darwin/system/defaults/controlcenter.nix
./darwin/system/defaults/dock.nix
./darwin/system/defaults/finder.nix
./darwin/system/defaults/NSGlobalDomain.nix
./darwin/system/defaults/loginwindow.nix
./darwin/system/keyboard.nix
./darwin/security/pam.nix
./darwin/homebrew.nix
./darwin/font.nix
./darwin/environment/systemPackages.nix
];

# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 5;

system.defaults.finder = {
AppleShowAllExtensions = true;
AppleShowAllFiles = false;
FXPreferredViewStyle = "clmv";
};

system.defaults.dock = {
autohide = true;
show-recents = false;
orientation = "bottom";
};

system.defaults.controlcenter = {
AirDrop = false;
BatteryShowPercentage = false;
Bluetooth = false;
Display = false;
FocusModes = false;
NowPlaying = false;
Sound = false;
};

# TODO(himkt); other items visibility settings (e.g. Wi-Fi).
# It modifies the almost same entries as the following command:
# `defaults -currentHost write com.apple.controlcenter WiFi -int 18`
# (18: show, 24: hide)
#
# However, it didn't change macOS UI actually even if I explicitly ran `killall SystemUIServer`.
# https://superuser.com/questions/398071/how-can-i-hide-show-the-wi-fi-menu-item-from-the-terminal-in-os-x
#
# system.defaults.CustomUserPreferences."com.apple.controlcenter" = {
# "NSStatusItem Preferred Position WiFi" = 18;
# "NSStatusItem Visible WiFi" = 1;
# };

system.keyboard = {
enableKeyMapping = true;
remapCapsLockToControl = true;
};

system.defaults.NSGlobalDomain = {
InitialKeyRepeat = 15;
KeyRepeat = 2;
};

system.defaults.loginwindow = {
GuestEnabled = false;
};

security.pam.enableSudoTouchIdAuth = true;

homebrew = {
enable = true;
casks = [
"arc"
"font-jetbrains-mono"
"docker"
# "notion"
"ngrok"
"insomnia"
"slack"
"visual-studio-code"
"wezterm"
"1password"
];
onActivation.cleanup = "uninstall";
};

# The platform the configuration will be used on.
nixpkgs.hostPlatform = "aarch64-darwin";
}
8 changes: 8 additions & 0 deletions nix/config.d/darwin/environment/systemPackages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ ... }:

{
# List packages installed in system profile. To search by name, run:
# $ nix-env -qaP | grep wget
environment.systemPackages = [
];
}
7 changes: 7 additions & 0 deletions nix/config.d/darwin/font.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ pkgs, ... }:

{
fonts.packages = [
pkgs.jetbrains-mono
];
}
20 changes: 20 additions & 0 deletions nix/config.d/darwin/homebrew.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ ... }:

{
homebrew = {
enable = true;
casks = [
"arc"
"font-jetbrains-mono"
"docker"
# "notion"
"ngrok"
"insomnia"
"slack"
"visual-studio-code"
"wezterm"
"1password"
];
onActivation.cleanup = "uninstall";
};
}
7 changes: 7 additions & 0 deletions nix/config.d/darwin/security/pam.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ ... }:

{
security.pam = {
enableSudoTouchIdAuth = true;
};
}
8 changes: 8 additions & 0 deletions nix/config.d/darwin/system/defaults/NSGlobalDomain.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ ... }:

{
system.defaults.NSGlobalDomain = {
InitialKeyRepeat = 15;
KeyRepeat = 2;
};
}
26 changes: 26 additions & 0 deletions nix/config.d/darwin/system/defaults/controlcenter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ ... }:

{
# TODO(himkt); other items visibility settings (e.g. Wi-Fi).
# It modifies the almost same entries as the following command:
# `defaults -currentHost write com.apple.controlcenter WiFi -int 18`
# (18: show, 24: hide)
#
# However, it didn't change macOS UI actually even if I explicitly ran `killall SystemUIServer`.
# https://superuser.com/questions/398071/how-can-i-hide-show-the-wi-fi-menu-item-from-the-terminal-in-os-x
#
# system.defaults.CustomUserPreferences."com.apple.controlcenter" = {
# "NSStatusItem Preferred Position WiFi" = 18;
# "NSStatusItem Visible WiFi" = 1;
# };

system.defaults.controlcenter = {
AirDrop = false;
BatteryShowPercentage = false;
Bluetooth = false;
Display = false;
FocusModes = false;
NowPlaying = false;
Sound = false;
};
}
9 changes: 9 additions & 0 deletions nix/config.d/darwin/system/defaults/dock.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ ... }:

{
system.defaults.dock = {
autohide = true;
show-recents = false;
orientation = "bottom";
};
}
9 changes: 9 additions & 0 deletions nix/config.d/darwin/system/defaults/finder.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ ... }:

{
system.defaults.finder = {
AppleShowAllExtensions = true;
AppleShowAllFiles = false;
FXPreferredViewStyle = "clmv";
};
}
7 changes: 7 additions & 0 deletions nix/config.d/darwin/system/defaults/loginwindow.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ ... }:

{
system.defaults.loginwindow = {
GuestEnabled = false;
};
}
8 changes: 8 additions & 0 deletions nix/config.d/darwin/system/keyboard.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ ... }:

{
system.keyboard = {
enableKeyMapping = true;
remapCapsLockToControl = true;
};
}
61 changes: 6 additions & 55 deletions nix/config.d/home.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ pkgs, config, ... }:
{
home.username = "himkt";
{ ... }:

{
# This value determines the Home Manager release that your
# configuration is compatible with. This helps avoid breakage
# when a new Home Manager release introduces backwards
Expand All @@ -11,60 +10,12 @@
# the Home Manager release notes for a list of state version
# changes in each release.
home.stateVersion = "24.11";
home.username = "himkt";

home.packages = [
pkgs.atuin
pkgs.coreutils
pkgs.difftastic
pkgs.fzf
pkgs.jq
pkgs.tree

pkgs.git
pkgs.git-lfs
pkgs.gh
pkgs.ghq

pkgs.zsh
pkgs.zsh-autocomplete
pkgs.zsh-syntax-highlighting
pkgs.zoxide

pkgs.kubectl
pkgs.krew
pkgs.k9s

pkgs.neovim

pkgs.nixd
imports = [
./home/shell.nix
./home/packages.nix
];

# NOTE(himkt); https://github.com/nix-community/home-manager/blob/master/modules/programs/zsh.nix
# (different from https://github.com/NixOS/nixpkgs/blob/nixos-24.11/nixos/modules/programs/zsh/zsh.nix)
programs.zsh = {
enable = true;
enableCompletion = true;
autosuggestion.enable = true;
syntaxHighlighting.enable = true;

history = {
size = 100000;
};

shellAliases = {
git-home = "cd `git rev-parse --show-toplevel`";
t = "tips";
vim = "nvim";
cd = "z";
ls = "ls --color";
retcode = "echo $?";
};


initExtra = ''
source ${config.home.homeDirectory}/dotfiles/zsh/config.d/zshrc
'';
};

programs.home-manager.enable = true;
}
30 changes: 30 additions & 0 deletions nix/config.d/home/packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ pkgs, ... }:

{
home.packages = [
pkgs.atuin
pkgs.coreutils
pkgs.difftastic
pkgs.fzf
pkgs.jq
pkgs.tree

pkgs.git
pkgs.git-lfs
pkgs.gh
pkgs.ghq

pkgs.zsh
pkgs.zsh-autocomplete
pkgs.zsh-syntax-highlighting
pkgs.zoxide

pkgs.kubectl
pkgs.krew
pkgs.k9s

pkgs.neovim

pkgs.nixd
];
}
29 changes: 29 additions & 0 deletions nix/config.d/home/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ config, ... }:

{
# NOTE(himkt); https://github.com/nix-community/home-manager/blob/master/modules/programs/zsh.nix
# (different from https://github.com/NixOS/nixpkgs/blob/nixos-24.11/nixos/modules/programs/zsh/zsh.nix)
programs.zsh = {
enable = true;
enableCompletion = true;
autosuggestion.enable = true;
syntaxHighlighting.enable = true;

history = {
size = 100000;
};

shellAliases = {
git-home = "cd `git rev-parse --show-toplevel`";
t = "tips";
vim = "nvim";
cd = "z";
ls = "ls --color";
retcode = "echo $?";
};

initExtra = ''
source ${config.home.homeDirectory}/dotfiles/zsh/config.d/zshrc
'';
};
}

0 comments on commit 8885f7a

Please sign in to comment.