Skip to content

Commit

Permalink
Merge pull request #9 from khaykingleb/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
khaykingleb authored Feb 9, 2025
2 parents c2a440b + ef52de3 commit 0915c59
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 155 deletions.
17 changes: 6 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ nix-uninstall: ## Uninstall Nix
@/nix/nix-installer uninstall
.PHONY: nix-uninstall

nix-darwin-apply: ## Apply nix-darwin configuration
@echo "Applying nix-darwin configuration."
@darwin-rebuild switch --flake .#macbook --show-trace
.PHONY: nix-darwin-apply
nix-darwin-apply-%: ## Apply nix-darwin configuration (e.g. `make nix-darwin-apply-macbook-pro-m1`)
@echo "Applying nix-darwin configuration for $*"
@darwin-rebuild switch --flake .#$* --show-trace

nix-darwin-uninstall: ## Uninstall nix-darwin
@echo "Uninstalling nix-darwin."
Expand Down Expand Up @@ -57,22 +56,18 @@ pre-commit-run-all: ## Run pre-commit hooks
.PHONY: pre-commit-run-all

asdf-setup: ## Setup asdf
@sh users/khaykingleb/scripts/asdf.sh
@echo "Setting up asdf..."
@nix develop --command sh users/khaykingleb/scripts/asdf.sh
.PHONY: asdf-setup

conda-macos-silicon-setup: ## Setup conda for macOS Silicon
@sh users/khaykingleb/scripts/conda.sh install_conda_macos_silicon
@conda config --set auto_activate_base false
.PHONY: conda-macos-silicon-setup

##=============================================================================
##@ Helper
##=============================================================================

help: ## Display help
@awk 'BEGIN {FS = ":.*##"; \
printf "\nUsage:\n make \033[36m<target>\033[0m\n\n"} \
/^[a-zA-Z0-9_-]+:.*?##/ { \
/^[a-zA-Z0-9_-]+%?:.*?##/ { \
printf " \033[36m%-30s\033[0m %s\n", $$1, $$2 \
} \
/^##@/ { \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ make nix-install
Apply the nix-darwin configuration:

```shell
make nix-darwin-apply
make nix-darwin-apply-macbook-pro-m1
```
21 changes: 0 additions & 21 deletions flake.lock

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

60 changes: 43 additions & 17 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
description = "Personal nix-darwin system flake";
description = "Personal configuration for macOS and NixOS";

inputs = {
# Main package supplier
Expand All @@ -10,15 +10,6 @@
ref = "nixpkgs-unstable";
};

# Reduces the boilerplate code for the flake
# https://github.com/hercules-ci/flake-parts
flake-parts = {
type = "github";
owner = "hercules-ci";
repo = "flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};

# Support for MacOS specific features
# https://github.com/LnL7/nix-darwin
nix-darwin = {
Expand All @@ -38,11 +29,46 @@
};
};

outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
# TODO(khaykingleb): add NixOS support for Linux later
systems = [
"aarch64-darwin"
];
imports = [ ./machines ];
};
outputs = { self, nix-darwin, home-manager, nixpkgs, ... } @inputs:
let
darwinArch = {
macbook-pro-m1 = {
system = "aarch64-darwin";
user = "khaykingleb";
};
};
mkDarwin = name: { system, user }: nix-darwin.lib.darwinSystem {
inherit system;
specialArgs = {
inherit inputs user;
hostName = name;
};
modules = [
./hosts/${name}
home-manager.darwinModules.home-manager # NOTE: integrates home-manager with nix-darwin
];
};
forAllSystems = f: nixpkgs.lib.genAttrs
(builtins.attrValues (builtins.mapAttrs (name: value: value.system) darwinArch))
f;
devShell = system:
let pkgs = nixpkgs.legacyPackages.${system}; in {
default = with pkgs; mkShell {
nativeBuildInputs = with pkgs; [
openssl
gnupg
xz
zlib
ncurses
bzip2
libffi
sqlite
];
};
};
in
{
devShells = forAllSystems devShell;
darwinConfigurations = builtins.mapAttrs mkDarwin darwinArch;
};
}
13 changes: 13 additions & 0 deletions hosts/macbook-pro-m1/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Handles system-level configuration for Macbook Pro M1 (macOS)
{ hostName, ... }:
{
imports = [
../../modules/darwin
./home-manager.nix
];

# Used for backwards compatibility
system.stateVersion = 5;

# networking.hostName = hostName;
}
16 changes: 16 additions & 0 deletions hosts/macbook-pro-m1/home-manager.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ pkgs, user, ... }:
{
users.users.${user} = {
name = user;
home = "/Users/${user}";
shell = pkgs.zsh;
};

home-manager = {
verbose = true;
useGlobalPkgs = true;
useUserPackages = true;
backupFileExtension = "home-manager-backup";
users.${user} = import ../../users/${user};
};
}
7 changes: 0 additions & 7 deletions machines/default.nix

This file was deleted.

11 changes: 0 additions & 11 deletions machines/macbook/default.nix

This file was deleted.

12 changes: 12 additions & 0 deletions modules/common/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ ... }:
{
imports = [
./packages.nix
];

nixpkgs = {
config = {
allowUnfree = true;
};
};
}
8 changes: 7 additions & 1 deletion systems/darwin/packages.nix → modules/common/packages.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# List packages installed in system profile
{ pkgs, ... }: {
# List packages installed in system profile
environment.systemPackages = with pkgs; [
vim
neovim
Expand All @@ -12,5 +12,11 @@
jq
yq
tree
bat
ngrok

# Nix-related packages
nil
nixpkgs-fmt
];
}
17 changes: 17 additions & 0 deletions modules/darwin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# System level configuration for MacOS
{ pkgs, ... }:
{
imports = [
../common
];

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

nix = {
settings = {
# Necessary for using flakes on this system
experimental-features = "nix-command flakes";
};
};
}
31 changes: 0 additions & 31 deletions systems/darwin/default.nix

This file was deleted.

25 changes: 0 additions & 25 deletions users/default.nix

This file was deleted.

20 changes: 9 additions & 11 deletions users/khaykingleb/default.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{ ... }:
{ pkgs, ... }:
{
# Enable HM to manage itself when in standalone mode
programs.home-manager.enable = true;
imports = [
./programs
./fonts.nix
];

home = {
username = "khaykingleb";
homeDirectory = "/Users/khaykingleb";

# You should stay at the version you originally installed
stateVersion = "24.11";
homeDirectory = if pkgs.stdenv.hostPlatform.isDarwin then "/Users/khaykingleb" else "/home/khaykingleb";
stateVersion = "24.11"; # NOTE: you should stay at the version you originally installed
};

imports = [
./programs
./fonts.nix
];
# Enable HM to manage itself when in standalone mode
programs.home-manager.enable = true;
}
2 changes: 2 additions & 0 deletions users/khaykingleb/programs/asdf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
programs.zsh = {
# NOTE: https://asdf-vm.com/guide/getting-started.html
initExtra = ''
# <<< ASDF initialization >>>
. "${pkgs.asdf-vm}/share/asdf-vm/asdf.sh"
. "${pkgs.asdf-vm}/share/asdf-vm/completions/asdf.bash"
# <<< ASDF initialization >>>
'';
};
}
12 changes: 10 additions & 2 deletions users/khaykingleb/programs/conda.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{ config, ... }: {
{ config, pkgs, ... }: {
home.activation.conda =
if pkgs.stdenv.hostPlatform.isDarwin then ''
sh ${config.home.homeDirectory}/.config/dotfiles/users/khaykingleb/scripts/conda.sh install_conda_macos_silicon
'' else ''
sh ${config.home.homeDirectory}/.config/dotfiles/users/khaykingleb/scripts/conda.sh install_conda_linux
'';
programs.zsh.initExtra = ''
# Conda initialization
# <<< Conda initialization >>>
__conda_setup="$(${config.home.homeDirectory}/anaconda3/bin/conda 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
Expand All @@ -16,5 +22,7 @@
# Force deactivation of base environment for conda
# (otherwise, it's activated in Cursor IDE for some reason)
conda deactivate
# <<< Conda initialization >>>
'';
}
9 changes: 1 addition & 8 deletions users/khaykingleb/programs/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{ pkgs, ... }: {
# General user packages
home.packages = with pkgs; [
ngrok
];

# Program specific packages
{ ... }: {
imports = [
./iterm2
./vscode
Expand All @@ -13,7 +7,6 @@
./asdf.nix
./conda.nix
./git.nix
./nix.nix
./ssh.nix
];
}
Loading

0 comments on commit 0915c59

Please sign in to comment.