commit 45253ce21e43dbc04fbe3bf8702022f952cadcfd Author: Sense T Date: Sun Jun 18 20:41:10 2023 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..60edb41 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# 个人用的 macos 与 Nix 的集成配置 + +需要安装 [nix-darwin](https://github.com/lnl7/nix-darwin) + +构建命令 + +```bash +darwin-rebuild switch --flake '.#mbp' +``` diff --git a/darwin-configuration.nix b/darwin-configuration.nix new file mode 100644 index 0000000..0dda1ed --- /dev/null +++ b/darwin-configuration.nix @@ -0,0 +1,49 @@ +{ lib, config, pkgs, ... }: + +{ + # List packages installed in system profile. To search by name, run: + # $ nix-env -qaP | grep wget + environment.systemPackages = with pkgs;[ + vim + wget + curl + axel + htop + ]; + + # Use a custom configuration.nix location. + # $ darwin-rebuild switch -I darwin-config=$HOME/.config/nixpkgs/darwin/configuration.nix + # environment.darwinConfig = "$HOME/.config/nixpkgs/darwin/configuration.nix"; + + # Auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + # nix.package = pkgs.nix; + nixpkgs.config = { + allowUnfree = true; + allowUnsupportedSystem = true; + }; + + nix.settings = { + auto-optimise-store = true; + substituters = lib.mkForce [ + "https://mirrors.ustc.edu.cn/nix-channels/store" # 中科大 + "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" #清华 + "https://mirrors.bfsu.edu.cn/nix-channels/store" # 北外 + "https://mirror.sjtu.edu.cn/nix-channels/store" #交大 + "https://cache.nixos.org/" + ]; + }; + + # Create /etc/zshrc that loads the nix-darwin environment. + programs.zsh.enable = true; # default shell on catalina + # programs.fish.enable = true; + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 4; + + users.users.tonychyi = { + name = "tonychyi"; + home = "/Users/tonychyi"; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a8b5491 --- /dev/null +++ b/flake.lock @@ -0,0 +1,71 @@ +{ + "nodes": { + "darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1686307493, + "narHash": "sha256-R4VEFnDn7nRmNxAu1LwNbjns5DPM8IBsvnrWmZ8ymPs=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "7c16d31383a90e0e72ace0c35d2d66a18f90fb4f", + "type": "github" + }, + "original": { + "owner": "lnl7", + "ref": "master", + "repo": "nix-darwin", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1687041925, + "narHash": "sha256-Zfn/SphInZ9PEIHWdQk+wGQ0XGlwAgRUp/Qso+8vDOY=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "a8d549351d4b87ab80665f35e57bee2a04201245", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-23.05", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1687008202, + "narHash": "sha256-V5mlLY/s4Vt3I7JeyqAuuinep/haMlPLWFpeLFsF8uA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a44bf9484215c9dbd5acbf937e5c1be582b30fc6", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-23.05-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "darwin": "darwin", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..839bc1b --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-23.05-darwin"; + darwin.url = "github:lnl7/nix-darwin/master"; + darwin.inputs.nixpkgs.follows = "nixpkgs"; + home-manager.url = "github:nix-community/home-manager/release-23.05"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, darwin, nixpkgs, home-manager }: { + darwinConfigurations."mbp" = darwin.lib.darwinSystem { + system = "x86_64-darwin"; + modules = [ + ./darwin-configuration.nix + home-manager.darwinModules.home-manager { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.tonychyi = import ./home.nix; + } + ]; + }; + }; +} diff --git a/home.nix b/home.nix new file mode 100644 index 0000000..e041da9 --- /dev/null +++ b/home.nix @@ -0,0 +1,71 @@ +{pkgs, config, ...}: { + home = { + stateVersion = "23.05"; + homeDirectory = "/Users/tonychyi"; + + packages = with pkgs; [ + bat + thefuck + ranger + coreutils + icdiff + podman + coreutils + gnutar + gnused + jdk17 + kubectl + kubernetes-helm + arduino-cli + ]; + + shellAliases = { + cao = "fuck"; + nixos-rebuild = "darwin-rebuild"; + top = "htop"; + pip = "pip3"; + ls = "ls --color=auto"; + cat = "bat -p --paging=never -u"; + diff="icdiff"; + }; + + sessionVariables = { + HOMEBREW_API_DOMAIN = "https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"; + HOMEBREW_BOTTLE_DOMAIN = "https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"; + HOMEBREW_BREW_GIT_REMOTE = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"; + HOMEBREW_CORE_GIT_REMOTE = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"; + }; + + sessionPath = [ + "$HOME/.local/bin" + "$HOME/.cargo/bin" + "$GOPATH/bin" + ]; + }; + + programs = { + home-manager.enable = true; + timidity.enable = true; + + vim = { + enable = true; + defaultEditor = true; + }; + + go = { + enable = true; + goPath = ".gopath"; + }; + + zsh = { + enable = true; + enableSyntaxHighlighting = true; + + oh-my-zsh = { + enable = true; + plugins = [ "sudo" "git" "golang" "thefuck" "kubectl" "emoji" "pip" "npm" "yarn" "vscode" ]; + theme = "agnoster"; + }; + }; + }; +}