From ab1ecc49edf08298ff1906c09ca22531de88604a Mon Sep 17 00:00:00 2001 From: ryan4yin Date: Thu, 25 May 2023 23:45:13 +0800 Subject: [PATCH 1/6] feat: add TODO --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d05b4fb1..c7b3817b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ This repository is home to the nix code that builds my systems. - enable disk encryption to enhance data security - make fcitx5-rime work in vscode/chrome on wayland +- auto unlock with `ssh-agent` after login + - [People using ssh-agent, how do you unlock it on login? - reddit](https://www.reddit.com/r/NixOS/comments/lsbo9a/people_using_sshagent_how_do_you_unlock_it_on/) ## Why Nix? From d86aae96ff96f01253086d298e1c57c61812daa7 Mon Sep 17 00:00:00 2001 From: ryan4yin Date: Thu, 25 May 2023 18:51:34 +0800 Subject: [PATCH 2/6] feat: add support for darwin --- flake.nix | 33 ++++++++++++++++++++++++-- home/home-darwin.nix | 28 ++++++++++++++++++++++ home/{default.nix => home-wayland.nix} | 3 --- home/home-x11.nix | 31 ++++++++++++++++++++++++ hosts/harmonica/default.nix | 10 ++++++++ 5 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 home/home-darwin.nix rename home/{default.nix => home-wayland.nix} (97%) create mode 100644 home/home-x11.nix create mode 100644 hosts/harmonica/default.nix diff --git a/flake.nix b/flake.nix index 7ae198aa..de7836d7 100644 --- a/flake.nix +++ b/flake.nix @@ -37,6 +37,13 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # 使用 nixos-unstable 分支 for nix flakes nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.05"; # unstable branch may be broken sometimes, use stable branch when necessary + # for macos + nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-23.05-darwin"; + darwin = { + url = "github:lnl7/nix-darwin/master"; + inputs.nixpkgs.follows = "nixpkgs-darwin"; + } + # nix users repository # used to install some packages not in nixpkgs # e.g. wechat-uos/qqmusic/dingtalk @@ -74,6 +81,7 @@ outputs = inputs@{ self, nixpkgs, + darwin, home-manager, ... }: { @@ -94,7 +102,7 @@ # 使用 home-manager.extraSpecialArgs 自定义传递给 ./home 的参数 home-manager.extraSpecialArgs = inputs; - home-manager.users.ryan = import ./home; + home-manager.users.ryan = import ./home/home-wayland.nix; } ]; }; @@ -115,12 +123,33 @@ # 使用 home-manager.extraSpecialArgs 自定义传递给 ./home 的参数 home-manager.extraSpecialArgs = inputs; - home-manager.users.ryan = import ./home; + home-manager.users.ryan = import ./home/home-wayland.nix; } ]; }; }; + darwinConfigurations."harmonica" = darwin.lib.darwinSystem { + system = "x86_64-darwin"; + + specialArgs = inputs; + modules = [ + ./hosts/harmonica + + # home-manager 作为 nixos 的一个 module + # 这样在 nixos-rebuild switch 时,home-manager 也会被自动部署,不需要额外执行 home-manager switch 命令 + home-manager.nixosModules.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; + } + ]; + }; + # generate qcow2 & iso image from nixos configuration # https://github.com/nix-community/nixos-generators # packages.x86_64-linux = { diff --git a/home/home-darwin.nix b/home/home-darwin.nix new file mode 100644 index 00000000..e793405c --- /dev/null +++ b/home/home-darwin.nix @@ -0,0 +1,28 @@ +{ config, pkgs, ... }: + +{ + imports = [ + ./programs + ./shell + ]; + + # Home Manager needs a bit of information about you and the + # paths it should manage. + home = { + username = "admin"; + homeDirectory = "/Users/admin"; + + # 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 + # incompatible changes. + # + # You can update Home Manager without changing this value. See + # the Home Manager release notes for a list of state version + # changes in each release. + stateVersion = "22.11"; + }; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; +} diff --git a/home/default.nix b/home/home-wayland.nix similarity index 97% rename from home/default.nix rename to home/home-wayland.nix index 91652e3a..efa1dfac 100644 --- a/home/default.nix +++ b/home/home-wayland.nix @@ -1,13 +1,10 @@ { config, pkgs, ... }: { - imports = [ ./fcitx5 ./hyprland - # ./i3 ./programs - ./rofi ./shell ]; diff --git a/home/home-x11.nix b/home/home-x11.nix new file mode 100644 index 00000000..281b12cb --- /dev/null +++ b/home/home-x11.nix @@ -0,0 +1,31 @@ +{ config, pkgs, ... }: + +{ + imports = [ + ./fcitx5 + ./i3 + ./programs + ./rofi + ./shell + ]; + + # Home Manager needs a bit of information about you and the + # paths it should manage. + home = { + username = "ryan"; + homeDirectory = "/home/ryan"; + + # 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 + # incompatible changes. + # + # You can update Home Manager without changing this value. See + # the Home Manager release notes for a list of state version + # changes in each release. + stateVersion = "22.11"; + }; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; +} diff --git a/hosts/harmonica/default.nix b/hosts/harmonica/default.nix new file mode 100644 index 00000000..d35d12e7 --- /dev/null +++ b/hosts/harmonica/default.nix @@ -0,0 +1,10 @@ +{ config, pkgs, home-manager, ... } @ args: + +{ + imports = [ + ../../modules/fhs-fonts.nix + ../../modules/system.nix + ]; +} + + From 7c7591e167311545f4e5a532dd21247b651b15d7 Mon Sep 17 00:00:00 2001 From: ryan4yin Date: Thu, 25 May 2023 23:34:38 +0800 Subject: [PATCH 3/6] feat: switch to x11 + i3 --- flake.lock | 39 +++++++++++++++++++++++++++++++++++ flake.nix | 4 ++-- home/programs/common.nix | 3 +++ hosts/msi-rtx4090/default.nix | 4 ++-- modules/hyprland.nix | 15 -------------- modules/system.nix | 15 ++++++++++++++ 6 files changed, 61 insertions(+), 19 deletions(-) diff --git a/flake.lock b/flake.lock index 3d399ad0..1858dbcd 100644 --- a/flake.lock +++ b/flake.lock @@ -43,6 +43,27 @@ "type": "github" } }, + "darwin_2": { + "inputs": { + "nixpkgs": [ + "nixpkgs-darwin" + ] + }, + "locked": { + "lastModified": 1684774948, + "narHash": "sha256-hJTaw4dYzcB+lsasKejnafq0CxPsVetn9RLXrcL+4jE=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "b8c286c82c6b47826a6c0377e7017052ad91353c", + "type": "github" + }, + "original": { + "owner": "lnl7", + "ref": "master", + "repo": "nix-darwin", + "type": "github" + } + }, "devenv": { "inputs": { "flake-compat": "flake-compat", @@ -426,6 +447,22 @@ "type": "github" } }, + "nixpkgs-darwin": { + "locked": { + "lastModified": 1684968804, + "narHash": "sha256-y78lDeiJC/MSOM6HBe1VI5G2lrrmJMkWigRuOrf20uA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "f69907854223d6d49f75b1ae52b2f6567f711d90", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-23.05-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-lib": { "locked": { "lastModified": 1681001314, @@ -652,12 +689,14 @@ "root": { "inputs": { "agenix": "agenix", + "darwin": "darwin_2", "devenv": "devenv", "home-manager": "home-manager_2", "hyprland": "hyprland", "nil": "nil", "nixos-generators": "nixos-generators", "nixpkgs": "nixpkgs_5", + "nixpkgs-darwin": "nixpkgs-darwin", "nixpkgs-stable": "nixpkgs-stable_2", "nixpkgs-wayland": "nixpkgs-wayland", "nur": "nur" diff --git a/flake.nix b/flake.nix index de7836d7..d5630f94 100644 --- a/flake.nix +++ b/flake.nix @@ -42,7 +42,7 @@ darwin = { url = "github:lnl7/nix-darwin/master"; inputs.nixpkgs.follows = "nixpkgs-darwin"; - } + }; # nix users repository # used to install some packages not in nixpkgs @@ -102,7 +102,7 @@ # 使用 home-manager.extraSpecialArgs 自定义传递给 ./home 的参数 home-manager.extraSpecialArgs = inputs; - home-manager.users.ryan = import ./home/home-wayland.nix; + home-manager.users.ryan = import ./home/home-x11.nix; } ]; }; diff --git a/home/programs/common.nix b/home/programs/common.nix index a1c46972..c499a25d 100644 --- a/home/programs/common.nix +++ b/home/programs/common.nix @@ -104,6 +104,9 @@ ltrace # library call monitoring lsof mtr + + # A tool to create bootable live USB drives from ISO images + unetbootin ]; programs = { diff --git a/hosts/msi-rtx4090/default.nix b/hosts/msi-rtx4090/default.nix index e5164d1a..8315c33b 100644 --- a/hosts/msi-rtx4090/default.nix +++ b/hosts/msi-rtx4090/default.nix @@ -16,8 +16,8 @@ ./hardware-configuration.nix ../../modules/fhs-fonts.nix - ../../modules/hyprland.nix - #../../modules/i3.nix + # ../../modules/hyprland.nix + ../../modules/i3.nix ../../modules/nur-packages.nix ../../modules/system.nix ../../modules/user_group.nix diff --git a/modules/hyprland.nix b/modules/hyprland.nix index 1b3598ce..61e81830 100644 --- a/modules/hyprland.nix +++ b/modules/hyprland.nix @@ -71,19 +71,4 @@ ncmpcpp # a mpd client with a UI networkmanagerapplet # provide GUI app: nm-connection-editor ]; - - xdg.portal = { - enable = true; - wlr.enable = true; - xdgOpenUsePortal = true; - extraPortals = with pkgs; [ - xdg-desktop-portal-wlr # for wlroots based compositors - xdg-desktop-portal-gtk # for gtk - # xdg-desktop-portal-kde # for kde - ]; - }; - - # for power management - services.upower.enable = true; - } diff --git a/modules/system.nix b/modules/system.nix index ba4f3eac..71953f6d 100644 --- a/modules/system.nix +++ b/modules/system.nix @@ -220,4 +220,19 @@ # android development tools, this will install adb/fastboot and other android tools and udev rules # see https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/programs/adb.nix programs.adb.enable = true; + + + xdg.portal = { + enable = true; + wlr.enable = true; + xdgOpenUsePortal = true; + extraPortals = with pkgs; [ + xdg-desktop-portal-wlr # for wlroots based compositors + xdg-desktop-portal-gtk # for gtk + # xdg-desktop-portal-kde # for kde + ]; + }; + + # for power management + services.upower.enable = true; } \ No newline at end of file From 5503e7bac0f7fa4c8deadb775794cf8a9a78eac1 Mon Sep 17 00:00:00 2001 From: ryan4yin Date: Thu, 25 May 2023 23:51:33 +0800 Subject: [PATCH 4/6] fix: error in ssh config --- home/programs/git.nix | 14 +++++++------- home/programs/xdg.nix | 4 +--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/home/programs/git.nix b/home/programs/git.nix index 88f90ba8..7acd24aa 100644 --- a/home/programs/git.nix +++ b/home/programs/git.nix @@ -10,13 +10,13 @@ # all my ssh private key are generated by `ssh-keygen -t ed25519 -C "ryan@nickname"` # the config's format: - # Host — the nickname you’ll use for the host. - # HostName — the IP address or domain of the remote server. - # User — the username associated with the remote account. + # Host — given the pattern used to match against the host name given on the command line. + # HostName — specify nickname or abbreviation for host # IdentityFile — the location of your SSH key authentication file for the account. + # format in details: + # https://www.ssh.com/academy/ssh/config extraConfig = '' - Host Homelab - Hostname 192.168.* + Host 192.168.* # allow to securely use local SSH agent to authenticate on the remote machine. # It has the same effect as adding cli option `ssh -A user@host` ForwardAgent yes @@ -26,8 +26,7 @@ # required to prevent sending default identity files first. IdentitiesOnly yes - Host GitHub - Hostname github.com + Host github.com # github is controlled by gluttony~ IdentityFile ~/.ssh/gluttony # Specifies that ssh should only use the identity file explicitly configured above @@ -38,6 +37,7 @@ # use ssh-agent so we only need to input passphrase once # run `ssh-add /path/to/key` for every identity file # check imported keys by `ssh-add -l` + # TODO `ssh-add` can only add keys temporary, use gnome-keyring to unlock all keys after login. }; programs.git = { diff --git a/home/programs/xdg.nix b/home/programs/xdg.nix index f386accd..251d38d0 100644 --- a/home/programs/xdg.nix +++ b/home/programs/xdg.nix @@ -11,7 +11,6 @@ "application/xhtml+xml" = browser; "text/html" = browser; "x-scheme-handler/about" = browser; - # "x-scheme-handler/chrome" = ["chromium-browser.desktop"]; "x-scheme-handler/ftp" = browser; "x-scheme-handler/http" = browser; "x-scheme-handler/https" = browser; @@ -21,9 +20,8 @@ "video/*" = ["mpv.dekstop"]; "image/*" = ["imv.desktop"]; "application/json" = browser; - "application/pdf" = ["org.pwmt.zathura.desktop.desktop"]; # TODO: pdf viewer + "application/pdf" = browser; # TODO: pdf viewer "x-scheme-handler/discord" = ["discord.desktop"]; - "x-scheme-handler/spotify" = ["spotify.desktop"]; "x-scheme-handler/tg" = ["telegramdesktop.desktop"]; }; in { From c694c81215f5a98c48a6b3df81af1b4bec157081 Mon Sep 17 00:00:00 2001 From: ryan4yin Date: Fri, 26 May 2023 00:01:09 +0800 Subject: [PATCH 5/6] feat: migrate x11/wayland related apps into i3/hyprland folder --- home/hyprland/default.nix | 4 ++ .../wayland-apps.nix} | 4 -- home/i3/default.nix | 4 ++ home/i3/x11-apps.nix | 37 +++++++++++++++++++ home/programs/common.nix | 4 +- home/programs/default.nix | 1 - home/shell/default.nix | 6 ++- 7 files changed, 53 insertions(+), 7 deletions(-) rename home/{programs/browsers.nix => hyprland/wayland-apps.nix} (94%) create mode 100644 home/i3/x11-apps.nix diff --git a/home/hyprland/default.nix b/home/hyprland/default.nix index 07988cc6..59ecb0e2 100644 --- a/home/hyprland/default.nix +++ b/home/hyprland/default.nix @@ -4,6 +4,10 @@ lib, ... }: { + imports = [ + ./wayland-apps.nix + ]; + # hyprland configs, based on https://github.com/notwidow/hyprland home.file.".config/hypr" = { source = ./hypr-conf; diff --git a/home/programs/browsers.nix b/home/hyprland/wayland-apps.nix similarity index 94% rename from home/programs/browsers.nix rename to home/hyprland/wayland-apps.nix index acde7d41..71927412 100644 --- a/home/programs/browsers.nix +++ b/home/hyprland/wayland-apps.nix @@ -2,7 +2,6 @@ pkgs, nixpkgs-stable, config, - nil, ... }: let pkgs-stable = import nixpkgs-stable { @@ -12,9 +11,6 @@ in { home.packages = with pkgs-stable; [ firefox-wayland # firefox with wayland support - # firefox - - nil.packages."${pkgs.system}".default # nix language server ]; diff --git a/home/i3/default.nix b/home/i3/default.nix index 2675d05c..57f66de2 100644 --- a/home/i3/default.nix +++ b/home/i3/default.nix @@ -7,6 +7,10 @@ # i3 配置,基于 https://github.com/endeavouros-team/endeavouros-i3wm-setup # 直接从当前文件夹中读取配置文件作为配置内容 + imports = [ + ./x11-apps.nix + ]; + # wallpaper, binary file home.file.".config/i3/wallpaper.png".source = ../wallpapers/wallpaper.png; home.file.".config/i3/config".source = ./config; diff --git a/home/i3/x11-apps.nix b/home/i3/x11-apps.nix new file mode 100644 index 00000000..b216554a --- /dev/null +++ b/home/i3/x11-apps.nix @@ -0,0 +1,37 @@ +{ + pkgs, + ... +}: { + home.packages = with pkgs; [ + firefox + ]; + + + # TODO vscode & chrome both have wayland support, but they don't work with fcitx5, need to fix it. + programs = { + + # source code: https://github.com/nix-community/home-manager/blob/master/modules/programs/chromium.nix + google-chrome = { + enable = true; + + # chrome wayland support was broken on nixos-unstable branch, so fallback to stable branch for now + # https://github.com/swaywm/sway/issues/7562 + package = pkgs.google-chrome; + + # commandLineArgs = [ + # ]; + }; + + vscode = { + enable = true; + # use the stable version + # package = pkgs.vscode.override { + # commandLineArgs = [ + # ]; + # }; + + # let vscode sync and update its configuration & extensions across devices, using github account. + # userSettings = {}; + }; + }; +} diff --git a/home/programs/common.nix b/home/programs/common.nix index c499a25d..1cef888e 100644 --- a/home/programs/common.nix +++ b/home/programs/common.nix @@ -1,4 +1,4 @@ -{pkgs, config, ...}: +{pkgs, config, nil, ...}: { @@ -29,6 +29,8 @@ obsidian hugo + nil.packages."${pkgs.system}".default # nix language server + # IDE insomnia jetbrains.pycharm-community diff --git a/home/programs/default.nix b/home/programs/default.nix index 11941d5b..74ecdb1e 100644 --- a/home/programs/default.nix +++ b/home/programs/default.nix @@ -4,7 +4,6 @@ ... }: { imports = [ - ./browsers.nix ./common.nix ./git.nix ./media.nix diff --git a/home/shell/default.nix b/home/shell/default.nix index 0a2a1521..b2c8792d 100644 --- a/home/shell/default.nix +++ b/home/shell/default.nix @@ -24,7 +24,11 @@ in rec { LESSHISTFILE = cache + "/less/history"; LESSKEY = c + "/less/lesskey"; WINEPREFIX = d + "/wine"; - XAUTHORITY = "$XDG_RUNTIME_DIR/Xauthority"; + + # set this variable make i3 failed to start + # related issue: + # https://github.com/sddm/sddm/issues/871 + # XAUTHORITY = "$XDG_RUNTIME_DIR/Xauthority"; # set default applications BROWSER = "firefox"; From fedcf1bafd3426261d72bf86587271f18c91ad03 Mon Sep 17 00:00:00 2001 From: ryan4yin Date: Fri, 26 May 2023 11:06:19 +0800 Subject: [PATCH 6/6] feat: update for darwin --- .gitignore | 2 ++ Makefile | 27 +++++++++++++-- README.md | 15 ++++++++- flake.lock | 60 +++++++++++++++++----------------- flake.nix | 8 +++-- home/darwin/default.nix | 10 ++++++ home/home-darwin.nix | 8 ++--- home/hyprland/wayland-apps.nix | 1 + home/programs/common.nix | 1 - hosts/harmonica/default.nix | 29 ++++++++++++++-- hosts/nixos-test/default.nix | 4 +++ modules/darwin/common.nix | 41 +++++++++++++++++++++++ scripts/darwin_set_proxy.py | 29 ++++++++++++++++ 13 files changed, 191 insertions(+), 44 deletions(-) create mode 100644 .gitignore create mode 100644 home/darwin/default.nix create mode 100644 modules/darwin/common.nix create mode 100644 scripts/darwin_set_proxy.py 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)) +