diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..82992825 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +result +result/ \ No newline at end of file diff --git a/Makefile b/Makefile index 7e98dff0..893953b1 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,11 @@ deploy: - sudo nixos-rebuild switch --flake . + sudo nixos-rebuild switch --flake . \ + --extra-experimental-features 'nix-command flakes' debug: - sudo nixos-rebuild switch --flake . --show-trace --verbose + sudo nixos-rebuild switch --flake . \ + --show-trace --verbose \ + --extra-experimental-features 'nix-command flakes' update: nix flake update @@ -13,3 +16,23 @@ history: gc: sudo nix-collect-garbage --delete-older-than 14d +darwin-set-proxy: + # set proxy for nix-daemon to speed up downloads + # https://github.com/NixOS/nix/issues/1472#issuecomment-1532955973 + sudo python3 scripts/darwin_set_proxy.py + +darwin: darwin-set-proxy + nix build .#darwinConfigurations.harmonica.system \ + --extra-experimental-features 'nix-command flakes' + ./result/sw/bin/darwin-rebuild switch --flake . + +darwin-debug: darwin-set-proxy + nix build .#darwinConfigurations.harmonica.system \ + --show-trace --verbose \ + --extra-experimental-features 'nix-command flakes' + ./result/sw/bin/darwin-rebuild switch --flake . --show-trace --verbose + + +.PHONY: clean +clean: + -rm -rf result diff --git a/README.md b/README.md index c7b3817b..2b9da7ea 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,9 @@ Want to know Nix in details? Looking for a beginner-friendly tutorial? Check out >Note: you should NOT deploy this flake directly on your machine, it contains my hardware information and personal information which is not suitable for you. You may use this repo as a reference to build your own configuration. -After installed NixOS with `nix-command` & `flake` enabled, you can deploy this flake with the following command: +After installed NixOS with `nix-command` & `flake` enabled, flow the steps below to deploy this flake. + +For NixOS, use the following commands: ```bash # deploy my test configuration @@ -41,6 +43,17 @@ sudo nixos-rebuild switch make deploy ``` +For MacOS, use the following commands: + +```bash +# set proxy for nix-daemon to speed up downloads +# https://github.com/NixOS/nix/issues/1472#issuecomment-1532955973 +make darwin-set-proxy + +# or just deploy using make, which is defined in Makefile +make darwin +``` + ## Install Apps from Flatpak We can install apps from flathub, which has a lot of apps that are not supported well in nixpkgs. diff --git a/flake.lock b/flake.lock index 1858dbcd..f8194718 100644 --- a/flake.lock +++ b/flake.lock @@ -29,11 +29,11 @@ ] }, "locked": { - "lastModified": 1684343812, - "narHash": "sha256-ZTEjiC8PDKeP8JRchuwcFXUNlMcyQ4U+DpyVZ3pB6Q4=", + "lastModified": 1673295039, + "narHash": "sha256-AsdYgE8/GPwcelGgrntlijMg4t3hLFJFCRF3tL5WVjA=", "owner": "lnl7", "repo": "nix-darwin", - "rev": "dfbdabbb3e797334172094d4f6c0ffca8c791281", + "rev": "87b9d090ad39b25b2400029c64825fc2a8868943", "type": "github" }, "original": { @@ -220,11 +220,11 @@ ] }, "locked": { - "lastModified": 1684596126, - "narHash": "sha256-4RZZmygeEXpuBqEXGs38ZAcWjWKGwu13Iqbxub6wuJk=", + "lastModified": 1682203081, + "narHash": "sha256-kRL4ejWDhi0zph/FpebFYhzqlOBrk0Pl3dzGEKSAlEw=", "owner": "nix-community", "repo": "home-manager", - "rev": "27ef11f0218d9018ebb2948d40133df2b1de622d", + "rev": "32d3e39c491e2f91152c84f8ad8b003420eab0a1", "type": "github" }, "original": { @@ -240,11 +240,11 @@ ] }, "locked": { - "lastModified": 1684484967, - "narHash": "sha256-P3ftCqeJmDYS9LSr2gGC4XGGcp5vv8TOasJX6fVHWsw=", + "lastModified": 1685019994, + "narHash": "sha256-81o6SKZPALvib21hIOMx2lIhFSs0mRy0PfPvg0zsfTk=", "owner": "nix-community", "repo": "home-manager", - "rev": "b9a52ad20e58ebd003444915e35e3dd2c18fc715", + "rev": "d1f04b0f365a34896a37d9015637796537ec88a3", "type": "github" }, "original": { @@ -418,11 +418,11 @@ ] }, "locked": { - "lastModified": 1683530131, - "narHash": "sha256-R0RSqj6JdZfru2x/cM19KJMHsU52OjtyxI5cccd+uFc=", + "lastModified": 1685000237, + "narHash": "sha256-pm+2xP9g9sh6wapk1ulg7/1DdENkTNDB7Kx+6lwGs/k=", "owner": "nix-community", "repo": "nixos-generators", - "rev": "10079333313ff62446e6f2b0e7c5231c7431d269", + "rev": "05bef004794f352ea12475a89f3f55b4102c0728", "type": "github" }, "original": { @@ -433,11 +433,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1684570954, - "narHash": "sha256-FX5y4Sm87RWwfu9PI71XFvuRpZLowh00FQpIJ1WfXqE=", + "lastModified": 1677676435, + "narHash": "sha256-6FxdcmQr5JeZqsQvfinIMr0XcTyTuR7EXX0H3ANShpQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3005f20ce0aaa58169cdee57c8aa12e5f1b6e1b3", + "rev": "a08d6979dd7c82c4cef0dcc6ac45ab16051c1169", "type": "github" }, "original": { @@ -512,11 +512,11 @@ }, "nixpkgs-stable_2": { "locked": { - "lastModified": 1684782344, - "narHash": "sha256-SHN8hPYYSX0thDrMLMWPWYulK3YFgASOrCsIL3AJ78g=", + "lastModified": 1685004253, + "narHash": "sha256-AbVL1nN/TDicUQ5wXZ8xdLERxz/eJr7+o8lqkIOVuaE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "8966c43feba2c701ed624302b6a935f97bcbdf88", + "rev": "3e01645c40b92d29f3ae76344a6d654986a91a91", "type": "github" }, "original": { @@ -534,11 +534,11 @@ "nixpkgs": "nixpkgs_7" }, "locked": { - "lastModified": 1684592015, - "narHash": "sha256-6gFt1LE/stVQFeGI263pU6O5EAeY1TPTGee1vvbkwZo=", + "lastModified": 1685045766, + "narHash": "sha256-MK128KJnrf0PqfdnL40KN57ZSpHPtru19TH+Ok0A0TU=", "owner": "nix-community", "repo": "nixpkgs-wayland", - "rev": "aeb1b88206756e867e398d18e2856b60fc803e12", + "rev": "38c86d9ff0a4cff1e229214031f7eaaab34e10f1", "type": "github" }, "original": { @@ -597,11 +597,11 @@ }, "nixpkgs_5": { "locked": { - "lastModified": 1684570954, - "narHash": "sha256-FX5y4Sm87RWwfu9PI71XFvuRpZLowh00FQpIJ1WfXqE=", + "lastModified": 1684935479, + "narHash": "sha256-6QMMsXMr2nhmOPHdti2j3KRHt+bai2zw+LJfdCl97Mk=", "owner": "nixos", "repo": "nixpkgs", - "rev": "3005f20ce0aaa58169cdee57c8aa12e5f1b6e1b3", + "rev": "f91ee3065de91a3531329a674a45ddcb3467a650", "type": "github" }, "original": { @@ -629,11 +629,11 @@ }, "nixpkgs_7": { "locked": { - "lastModified": 1684570954, - "narHash": "sha256-FX5y4Sm87RWwfu9PI71XFvuRpZLowh00FQpIJ1WfXqE=", + "lastModified": 1684935479, + "narHash": "sha256-6QMMsXMr2nhmOPHdti2j3KRHt+bai2zw+LJfdCl97Mk=", "owner": "nixos", "repo": "nixpkgs", - "rev": "3005f20ce0aaa58169cdee57c8aa12e5f1b6e1b3", + "rev": "f91ee3065de91a3531329a674a45ddcb3467a650", "type": "github" }, "original": { @@ -645,11 +645,11 @@ }, "nur": { "locked": { - "lastModified": 1684585623, - "narHash": "sha256-28XEOYjrpzlVDt11Elz7db8R3HwY/4B6EspFscSRsfk=", + "lastModified": 1685061478, + "narHash": "sha256-fNCFmOOfTmtWCV4WEoAnwwyjjB4NRAzucTKdt0w5zvg=", "owner": "nix-community", "repo": "NUR", - "rev": "4e959da0346280293e4008150d48b82fe055a311", + "rev": "82f3aa5c5a85a9f2a1e72eaf0eec30c8ab8fdf2c", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index d5630f94..ee8abf8c 100644 --- a/flake.nix +++ b/flake.nix @@ -9,10 +9,12 @@ # sudo ip route del default via 192.168.5.201 nixConfig = { experimental-features = [ "nix-command" "flakes" ]; + substituters = [ # replace official cache with a mirror located in China "https://mirrors.bfsu.edu.cn/nix-channels/store" - "https://cache.nixos.org/" + "https://mirrors.ustc.edu.cn/nix-channels/store" + "https://cache.nixos.org" ]; # nix community's cache server @@ -138,14 +140,14 @@ # home-manager 作为 nixos 的一个 module # 这样在 nixos-rebuild switch 时,home-manager 也会被自动部署,不需要额外执行 home-manager switch 命令 - home-manager.nixosModules.home-manager + home-manager.darwinModules.home-manager { home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; # 使用 home-manager.extraSpecialArgs 自定义传递给 ./home 的参数 home-manager.extraSpecialArgs = inputs; - home-manager.users.ryan = import ./home/home-darwin.nix; + home-manager.users.admin = import ./home/home-darwin.nix; } ]; }; diff --git a/home/darwin/default.nix b/home/darwin/default.nix new file mode 100644 index 00000000..8bb65890 --- /dev/null +++ b/home/darwin/default.nix @@ -0,0 +1,10 @@ +{pkgs, ...}: +{ + home.packages = with pkgs; [ + docker-compose + kubectl + kubernetes-helm + terraform + pulumi + ]; +} \ No newline at end of file diff --git a/home/home-darwin.nix b/home/home-darwin.nix index e793405c..d0f28242 100644 --- a/home/home-darwin.nix +++ b/home/home-darwin.nix @@ -1,16 +1,16 @@ -{ config, pkgs, ... }: +{ pkgs, ... }: { imports = [ - ./programs - ./shell + ./darwin ]; # Home Manager needs a bit of information about you and the # paths it should manage. home = { username = "admin"; - homeDirectory = "/Users/admin"; + # set homeDirectory make build fail + # homeDirectory = "/Users/admin"; # This value determines the Home Manager release that your # configuration is compatible with. This helps avoid breakage diff --git a/home/hyprland/wayland-apps.nix b/home/hyprland/wayland-apps.nix index 71927412..39b8e43d 100644 --- a/home/hyprland/wayland-apps.nix +++ b/home/hyprland/wayland-apps.nix @@ -11,6 +11,7 @@ in { home.packages = with pkgs-stable; [ firefox-wayland # firefox with wayland support + wineWowPackages.wayland ]; diff --git a/home/programs/common.nix b/home/programs/common.nix index 1cef888e..a2feb64b 100644 --- a/home/programs/common.nix +++ b/home/programs/common.nix @@ -22,7 +22,6 @@ # misc libnotify - wineWowPackages.wayland xdg-utils # productivity diff --git a/hosts/harmonica/default.nix b/hosts/harmonica/default.nix index d35d12e7..491dd9e4 100644 --- a/hosts/harmonica/default.nix +++ b/hosts/harmonica/default.nix @@ -1,10 +1,33 @@ -{ config, pkgs, home-manager, ... } @ args: +# My MacBook Pro - Computer for Business +{ pkgs, ... } @ args: { imports = [ - ../../modules/fhs-fonts.nix - ../../modules/system.nix + ../../modules/darwin/common.nix ]; + + # # enable flakes globally + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + + # Auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + # Use this instead of services.nix-daemon.enable if you + # don't wan't the daemon service to be managed for you. + # nix.useDaemon = true; + + nix.package = pkgs.nix; + + programs.nix-index.enable = true; + + # Add ability to used TouchID for sudo authentication + security.pam.enableSudoTouchIdAuth = true; + + # Keyboard + system.keyboard.enableKeyMapping = true; + system.keyboard.remapCapsLockToEscape = true; + + # Set your time zone. + time.timeZone = "Asia/Shanghai"; } diff --git a/hosts/nixos-test/default.nix b/hosts/nixos-test/default.nix index e4615dbf..3f2320b6 100644 --- a/hosts/nixos-test/default.nix +++ b/hosts/nixos-test/default.nix @@ -53,6 +53,10 @@ } ]; }; defaultGateway = "192.168.5.201"; + nameservers = [ + "119.29.29.29" # DNSPod + "223.5.5.5" # AliDNS + ]; }; # This value determines the NixOS release from which the default diff --git a/modules/darwin/common.nix b/modules/darwin/common.nix new file mode 100644 index 00000000..c5669979 --- /dev/null +++ b/modules/darwin/common.nix @@ -0,0 +1,41 @@ +{ pkgs, lib, ... }: +{ + + # Create /etc/zshrc that loads the nix-darwin environment. + programs.zsh.enable = true; + + # Apps + # `home-manager` currently has issues adding them to `~/Applications` + # Issue: https://github.com/nix-community/home-manager/issues/1341 + environment.systemPackages = with pkgs; [ + alacritty + jq + bat + ]; + + # Fonts + fonts = { + # use fonts specified by user rather than default ones + fontDir.enable = true; + + fonts = with pkgs; [ + # icon fonts + material-design-icons + font-awesome + + # Noto 系列字体是 Google 主导的,名字的含义是「没有豆腐」(no tofu),因为缺字时显示的方框或者方框被叫作 tofu + # Noto 系列字族名只支持英文,命名规则是 Noto + Sans 或 Serif + 文字名称。 + # 其中汉字部分叫 Noto Sans/Serif CJK SC/TC/HK/JP/KR,最后一个词是地区变种。 + noto-fonts # 大部分文字的常见样式,不包含汉字 + noto-fonts-cjk # 汉字部分 + noto-fonts-emoji # 彩色的表情符号字体 + noto-fonts-extra # 提供额外的字重和宽度变种 + + # 思源系列字体是 Adobe 主导的。其中汉字部分被称为「思源黑体」和「思源宋体」,是由 Adobe + Google 共同开发的 + source-sans # 无衬线字体,不含汉字。字族名叫 Source Sans 3 和 Source Sans Pro,以及带字重的变体,加上 Source Sans 3 VF + source-serif # 衬线字体,不含汉字。字族名叫 Source Code Pro,以及带字重的变体 + source-han-sans # 思源黑体 + source-han-serif # 思源宋体 + ]; + }; +} \ No newline at end of file diff --git a/scripts/darwin_set_proxy.py b/scripts/darwin_set_proxy.py new file mode 100644 index 00000000..90881c1a --- /dev/null +++ b/scripts/darwin_set_proxy.py @@ -0,0 +1,29 @@ +import os +import plistlib +import shlex +import subprocess +from pathlib import Path + + +NIX_DAEMON_PLIST = Path("/Library/LaunchDaemons/org.nixos.nix-daemon.plist") +NIX_DAEMON_NAME = "org.nixos.nix-daemon" +# http proxy provided by clash +HTTP_PROXY = "http://127.0.0.1:7890" + +pl = plistlib.loads(NIX_DAEMON_PLIST.read_bytes()) + +# set http proxy +pl["EnvironmentVariables"]["HTTP_PROXY"] = HTTP_PROXY +pl["EnvironmentVariables"]["HTTPS_PROXY"] = HTTP_PROXY + +os.chmod(NIX_DAEMON_PLIST, 0o644) +NIX_DAEMON_PLIST.write_bytes(plistlib.dumps(pl)) +os.chmod(NIX_DAEMON_PLIST, 0o444) + +# reload the plist +for cmd in ( + f"launchctl unload {NIX_DAEMON_NAME}", + f"launchctl load {NIX_DAEMON_NAME}", +): + subprocess.run(shlex.split(cmd)) +