Skip to content

Commit

Permalink
feat(nix): init darwin config (#62)
Browse files Browse the repository at this point in the history
* feat(nix): initial working nix-darwin config

* refactor(nix): restructure nixos config

* fixup! feat(nix): initial working nix-darwin config

* fixup! feat(nix): initial working nix-darwin config
  • Loading branch information
WilliamHsieh authored Aug 30, 2024
1 parent a7848af commit b9c49d1
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 13 deletions.
21 changes: 21 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
inputs.nixpkgs.follows = "nixpkgs";
};

nix-darwin = {
url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};

git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
Expand Down Expand Up @@ -76,7 +81,7 @@
${hostname} = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs outputs pkgs; };
modules = [
./system
./system/nixos
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
Expand All @@ -88,6 +93,22 @@
};
};

darwinConfigurations = {
${hostname} = inputs.nix-darwin.lib.darwinSystem {
specialArgs = { inherit inputs outputs pkgs; };
modules = [
./system/darwin
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
# home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = { inherit inputs outputs; };
home-manager.users.${username} = import ./home;
}
];
};
};

# Convenience output that aggregates the outputs for home, nixos, and darwin configurations.
# Instead of calling `nix build .#nixosConfigurations.{host}.config.system.build.toplevel`,
# now it's simply `nix build .#top.{host}` or `nix build .#top.{user}`
Expand All @@ -96,6 +117,9 @@
nixtop = nixpkgs.lib.genAttrs
(builtins.attrNames inputs.self.nixosConfigurations)
(attr: inputs.self.nixosConfigurations.${attr}.config.system.build.toplevel);
darwintop = nixpkgs.lib.genAttrs
(builtins.attrNames inputs.self.darwinConfigurations)
(attr: inputs.self.darwinConfigurations.${attr}.system);
hometop = nixpkgs.lib.genAttrs
(builtins.attrNames inputs.self.homeConfigurations)
(attr: inputs.self.homeConfigurations.${attr}.activationPackage);
Expand Down
1 change: 1 addition & 0 deletions home/alacritty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
env = {
TERM = "xterm-256color";
LANG = "C.UTF-8";
CC = "gcc";
};
font = {
normal.family = "MesloLGMDZ Nerd Font Mono";
Expand Down
14 changes: 9 additions & 5 deletions home/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ in
less
procps
zlib
glibc #ldd, iconv, ...
iconv
wget
curl

Expand All @@ -68,8 +68,6 @@ in

# images
viu
# fast and feature rich
qimgv # export QT_XCB_GL_INTEGRATION=none
# super fast
feh

Expand Down Expand Up @@ -99,7 +97,6 @@ in
# network
httpie
socat
netcat-openbsd # only the bsd version support `-k`

# fun
sl
Expand All @@ -115,7 +112,10 @@ in
hello-unfree #test unfree packages
nurl #generate nix fetcher call from repo
cloc
];
] ++ (pkgs.lib.optionals pkgs.stdenv.isLinux [
qimgv # export QT_XCB_GL_INTEGRATION=none
netcat-openbsd # only the bsd version support `-k`
]);

sessionVariables = rec {
NIX_PATH = "nixpkgs=${inputs.nixpkgs}";
Expand All @@ -126,6 +126,10 @@ in
VISUAL = EDITOR;
MANPAGER = "nvim +Man!";
LESSUTFCHARDEF = "E000-F8FF:p,F0000-FFFFD:p,100000-10FFFD:p"; # HACK: https://github.com/sharkdp/bat/issues/2578

# NOTE: https://github.com/NixOS/nixpkgs/issues/206242
# LIBRARY_PATH = "${pkgs.iconv}/lib";
LIBRARY_PATH = "${config.home.profileDirectory}/lib";
};
};

Expand Down
13 changes: 9 additions & 4 deletions home/zsh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
let
cfg = import ./config.nix;
dotfilesDir = "${config.home.homeDirectory}/${cfg.repo-path}";
in
{
home.shellAliases = {
aliases = {
ls = "eza --group-directories-first";
l = "ls -l";
la = "ls -lag --icons=auto";
Expand All @@ -19,11 +17,18 @@ in
cp = "cp -i";
rm = "trash";

visudo = "${pkgs.sudo}/bin/visudo";
sudo = ''sudo -E env "PATH=$PATH" '';
pythonServer = "python3 -m http.server";
cpcmd = "fc -ln -1 | awk '{$1=$1}1' | tee /dev/fd/2 | yank";
};
in
{
home.shellAliases = pkgs.lib.mkMerge [
aliases
(pkgs.lib.mkIf pkgs.stdenv.isLinux {
visudo = "${pkgs.sudo}/bin/visudo";
})
];

home.packages = [
pkgs.zsh-forgit
Expand Down
96 changes: 96 additions & 0 deletions system/darwin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{ inputs, config, pkgs, ... }:
let
username = (import ../../home/config.nix).user;
in
{
environment.systemPackages =
[
pkgs.spotify
pkgs.discord
pkgs.xquartz
];

nixpkgs.hostPlatform = "aarch64-darwin";

networking.hostName = (import ../config.nix).host;

services.karabiner-elements.enable = true;

users.users."${username}" = {
description = username;
home = "/Users/${username}";
shell = pkgs.zsh;
};

# for login shell
programs.zsh.enable = true; # default shell on catalina

homebrew = {
enable = true;
casks = [
"google-chrome"
"google-drive"
"raycast"
"rectangle"
"logi-options+"
"vmware-fusion"
"hammerspoon"
"skype"
"arc"
];
};

fonts.packages = with pkgs; [
(nerdfonts.override {
fonts = [
"Iosevka"
"JetBrainsMono"
"CodeNewRoman"
"Meslo"
"FiraCode"
"DroidSansMono"
];
})
];

system = {
defaults = {
NSGlobalDomain = {
AppleInterfaceStyle = "Dark";
NSAutomaticCapitalizationEnabled = false;
"com.apple.keyboard.fnState" = true;
};
dock = {
largesize = 100;
magnification = true;
mru-spaces = false;
persistent-others = [
"/Users/${username}/Documents"
"/Users/${username}/Downloads"
];
};
trackpad = {
Dragging = true;
};
finder.FXPreferredViewStyle = "icnv";
# universalaccess = {
# closeViewScrollWheelToggle = true;
# closeViewZoomFollowsFocus = true;
# };
};

# how to only apply internal keyboard?
keyboard = {
enableKeyMapping = true;
# swapLeftCommandAndLeftAlt = true;
# swapLeftCtrlAndFn = true;
};
};

# Auto upgrade nix package and the daemon service.
services.nix-daemon.enable = true;

# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;
}
6 changes: 3 additions & 3 deletions system/default.nix → system/nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
};
};

networking.hostName = (import ./config.nix).host;
networking.hostName = (import ../config.nix).host;
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.

# Configure network proxy if necessary
Expand Down Expand Up @@ -95,7 +95,7 @@
# Define a user account. Don't forget to set a password with ‘passwd’.
users.users.william = {
isNormalUser = true;
description = (import ../home/config.nix).name;
description = (import ../../home/config.nix).name;
extraGroups = [ "networkmanager" "wheel" ];
shell = pkgs.zsh;
packages = with pkgs; [
Expand Down Expand Up @@ -161,5 +161,5 @@
# Or disable the firewall altogether.
# networking.firewall.enable = false;

system.stateVersion = (import ../lib { inherit inputs; }).stateVersion;
system.stateVersion = (import ../../lib { inherit inputs; }).stateVersion;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b9c49d1

Please sign in to comment.