From 47a7828bc7b8b92636813d9b59c096fae266a617 Mon Sep 17 00:00:00 2001 From: ryan4yin Date: Sun, 14 May 2023 01:32:47 +0800 Subject: [PATCH] feat: nixos - nur - qqmusic/wechat-uos/dingtalk, rollback to i3 --- flake.lock | 18 ++++++- flake.nix | 92 +++++++++++++++++++---------------- home/default.nix | 3 +- home/hyprland/default.nix | 1 + home/i3/default.nix | 33 ++++++++++--- home/i3/profile | 17 +++++++ home/programs/browsers.nix | 29 +++++------ home/programs/common.nix | 6 ++- hosts/msi-rtx4090/default.nix | 3 +- modules/nur-packages.nix | 13 +++++ 10 files changed, 147 insertions(+), 68 deletions(-) create mode 100644 home/i3/profile create mode 100644 modules/nur-packages.nix diff --git a/flake.lock b/flake.lock index ab979a5c..c03959f4 100644 --- a/flake.lock +++ b/flake.lock @@ -271,13 +271,29 @@ "type": "github" } }, + "nur": { + "locked": { + "lastModified": 1683993879, + "narHash": "sha256-Vkh3NwvtjFuDp7TzSYNaqm2bG2Mbu2lvFxjHfdJX10o=", + "owner": "nix-community", + "repo": "NUR", + "rev": "9c38359908111a7338c585d986d6056618da5745", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "NUR", + "type": "github" + } + }, "root": { "inputs": { "home-manager": "home-manager", "hyprland": "hyprland", "nixpkgs": "nixpkgs_2", "nixpkgs-stable": "nixpkgs-stable", - "nixpkgs-wayland": "nixpkgs-wayland" + "nixpkgs-wayland": "nixpkgs-wayland", + "nur": "nur" } }, "systems": { diff --git a/flake.nix b/flake.nix index 26a9c0fc..e2bf918f 100644 --- a/flake.nix +++ b/flake.nix @@ -19,11 +19,13 @@ extra-substituters = [ "https://nix-community.cachix.org" "https://nixpkgs-wayland.cachix.org" + "https://xddxdd.cachix.org" ]; extra-trusted-public-keys = [ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=" + "xddxdd.cachix.org-1:ay1HJyNDYmlSwj5NXQG065C8LfoqqKaTNCyzeixGjf8=" ]; }; @@ -34,6 +36,11 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # 使用 nixos-unstable 分支 for nix flakes nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-22.11"; # unstable branch may be broken sometimes, use stable branch when necessary + + # nix users repository + # used to install some packages not in nixpkgs + # e.g. wechat-uos/qqmusic/dingtalk + nur.url = github:nix-community/NUR; home-manager.url = "github:nix-community/home-manager"; # follows 是 inputs 中的继承语法 @@ -54,29 +61,50 @@ nixpkgs, nixpkgs-stable, home-manager, + nur, ... }: { - # 名为 nixosConfigurations 的 outputs 会在执行 `nixos-rebuild switch --flake .` 时被使用 - # 默认情况下会使用与主机 hostname 同名的 nixosConfigurations,但是也可以通过 `--flake .#` 来指定 nixosConfigurations = { - # hostname 为 nixos-test 的主机会使用这个配置 - # 这里使用了 nixpkgs.lib.nixosSystem 函数来构建配置,后面的 attributes set 是它的参数 - # 在 nixos 上使用此命令部署配置:`nixos-rebuild switch --flake .#nixos-test` - nixos-test = nixpkgs.lib.nixosSystem { + msi-rtx4090 = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; - # modules 中每个参数,都是一个 NixOS Module - # NixOS Module 可以是一个 attribute set,也可以是一个返回 attribute set 的函数 - # 如果是函数,那么它的参数就是当前的 NixOS Module 的参数. - # 根据 Nix Wiki 对 NixOS modules 的描述,NixOS modules 函数的参数可以有这四个(详见本仓库中的 modules 文件): - # - # config: The configuration of the entire system - # options: All option declarations refined with all definition and declaration references. - # pkgs: The attribute set extracted from the Nix package collection and enhanced with the nixpkgs.config option. - # modulesPath: The location of the module directory of NixOS. - # - # nix flake 的 modules 系统可将配置模块化,提升配置的可维护性 - # 默认只能传上面这四个参数,如果需要传其他参数,必须使用 specialArgs + specialArgs = { + inherit nixpkgs-stable; + }; + modules = [ + ./hosts/msi-rtx4090 + + # 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; + } + + ({pkgs, config, ... }: { + config = { + # use it as an overlay + nixpkgs.overlays = [ + inputs.nixpkgs-wayland.overlay + ]; + }; + }) + + # This adds a nur configuration option. + # Use `config.nur.repos..` in NixOS Module for packages from the NUR. + nur.nixosModules.nur + + ]; + }; + + + nixos-test = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; specialArgs = { inherit nixpkgs-stable; }; @@ -103,33 +131,13 @@ ]; }; }) + + # This adds a nur configuration option. + # Use `config.nur.repos..` in NixOS Module for packages from the NUR. + nur.nixosModules.nur ]; }; - msi-rtx4090 = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - - specialArgs = { - inherit nixpkgs-stable; - }; - modules = [ - ./hosts/msi-rtx4090 - - # 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; - } - ]; - }; - - # 如果你在 x86_64-linux 平台上执行 nix build,那么默认会使用这个配置,或者也能通过 `.#` 参数来指定非 default 的配置 # packages.x86_64-linux.default = }; diff --git a/home/default.nix b/home/default.nix index 814a5ae4..188f2a81 100644 --- a/home/default.nix +++ b/home/default.nix @@ -3,7 +3,8 @@ { imports = [ - ./hyprland + # ./hyprland + ./i3 ./programs ./rofi ./shell diff --git a/home/hyprland/default.nix b/home/hyprland/default.nix index ee57c513..f8ba2d6b 100644 --- a/home/hyprland/default.nix +++ b/home/hyprland/default.nix @@ -1,6 +1,7 @@ { pkgs, config, + lib, ... }: { # hyprland configs, based on https://github.com/notwidow/hyprland diff --git a/home/i3/default.nix b/home/i3/default.nix index 51f301bb..2efcb386 100644 --- a/home/i3/default.nix +++ b/home/i3/default.nix @@ -1,6 +1,7 @@ { pkgs, config, + lib, ... }: { # i3 配置,基于 https://github.com/endeavouros-team/endeavouros-i3wm-setup @@ -18,16 +19,34 @@ executable = true; # make all scripts executable }; + home.file.".config/fcitx5/profile".source = ./profile; + # fcitx5 每次切换输入法,就会修改 ~/.config/fcitx5/profile 文件,导致我用 hm 管理的配置被覆盖 + # 解决方法是通过如下内置,每次 rebuild 前都先删除下 profile 文件 + home.activation.removeExistingFcitx5Profile = lib.hm.dag.entryBefore ["checkLinkTargets"] '' + rm -f "${config.xdg.configHome}/fcitx5/profile" + ''; + + # allow fontconfig to discover fonts and configurations installed through home.packages + fonts.fontconfig.enable = true; + + systemd.user.sessionVariables = { + "LIBVA_DRIVER_NAME" = "nvidia"; + "GBM_BACKEND" = "nvidia-drm"; + "__GLX_VENDOR_LIBRARY_NAME" = "nvidia"; + + # copy from https://github.com/nix-community/home-manager/blob/master/modules/i18n/input-method/fcitx5.nix + GLFW_IM_MODULE = "fcitx"; + GTK_IM_MODULE = "fcitx"; + QT_IM_MODULE = "fcitx"; + XMODIFIERS = "@im=fcitx"; + INPUT_METHOD = "fcitx"; + IMSETTINGS_MODULE = "fcitx"; + }; # set cursor size and dpi for 4k monitor xresources.properties = { "Xcursor.size" = 16; - "Xft.dpi" = 192; + "Xft.dpi" = 150; }; - - # 直接以 text 的方式,在 nix 配置文件中硬编码文件内容 - # home.file.".xxx".text = '' - # xxx - # ''; - + } \ No newline at end of file diff --git a/home/i3/profile b/home/i3/profile new file mode 100644 index 00000000..ca43a79c --- /dev/null +++ b/home/i3/profile @@ -0,0 +1,17 @@ +[Groups/0] +# Group Name +Name=Other +# Layout +Default Layout=us +# Default Input Method +DefaultIM=rime + +[Groups/0/Items/0] +# Name +Name=rime +# Layout +Layout= + +[GroupOrder] +0=Other + diff --git a/home/programs/browsers.nix b/home/programs/browsers.nix index b8ab3b91..5521156a 100644 --- a/home/programs/browsers.nix +++ b/home/programs/browsers.nix @@ -10,7 +10,8 @@ }; in { home.packages = with pkgs-stable; [ - firefox-wayland + # firefox-wayland + firefox ]; programs = { @@ -23,26 +24,26 @@ # https://github.com/swaywm/sway/issues/7562 package = pkgs-stable.google-chrome; - commandLineArgs = [ - # make it use GTK_IM_MODULE if it runs with Gtk4, so fcitx5 can work with it. - # (only supported by chromium/chrome at this time, not electron) - "--gtk-version=4" - # make it use text-input-v1, which works for kwin 5.27 and weston - # "--enable-wayland-ime" + # commandLineArgs = [ + # # make it use GTK_IM_MODULE if it runs with Gtk4, so fcitx5 can work with it. + # # (only supported by chromium/chrome at this time, not electron) + # "--gtk-version=4" + # # make it use text-input-v1, which works for kwin 5.27 and weston + # # "--enable-wayland-ime" - # enable hardware acceleration - vulkan api - # "--enable-features=Vulkan" - ]; + # # enable hardware acceleration - vulkan api + # # "--enable-features=Vulkan" + # ]; }; vscode = { enable = true; # use the stable version package = pkgs-stable.vscode.override { - commandLineArgs = [ - # make it use text-input-v1, which works for kwin 5.27 and weston - # "--enable-wayland-ime" - ]; + # commandLineArgs = [ + # # make it use text-input-v1, which works for kwin 5.27 and weston + # # "--enable-wayland-ime" + # ]; }; # let vscode sync and update its configuration & extensions across devices, using github account. diff --git a/home/programs/common.nix b/home/programs/common.nix index 3c0db0ec..f4072103 100644 --- a/home/programs/common.nix +++ b/home/programs/common.nix @@ -1,4 +1,7 @@ -{pkgs, ...}: { +{pkgs, config, ...}: + + +{ home.packages = with pkgs; [ # archives zip @@ -88,7 +91,6 @@ # instant messaging telegram-desktop discord - # qq & wechat are alse in the official nixpkgs qq # https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/networking/instant-messengers/qq # music diff --git a/hosts/msi-rtx4090/default.nix b/hosts/msi-rtx4090/default.nix index 69fbcd87..55063281 100644 --- a/hosts/msi-rtx4090/default.nix +++ b/hosts/msi-rtx4090/default.nix @@ -9,8 +9,9 @@ [ ./cifs-mount.nix ../../modules/system.nix - ../../modules/hyprland.nix + ../../modules/i3.nix ../../modules/fcitx5 + ../../modules/nur-packages.nix # Include the results of the hardware scan. ./hardware-configuration.nix diff --git a/modules/nur-packages.nix b/modules/nur-packages.nix new file mode 100644 index 00000000..aaeae464 --- /dev/null +++ b/modules/nur-packages.nix @@ -0,0 +1,13 @@ +{ config, pkgs, ... }: + +{ + nixpkgs.config.permittedInsecurePackages = [ + "electron-19.0.7" # required by wechat-uos, and it's already EOL + ]; + + environment.systemPackages = with config.nur.repos.xddxdd; [ + # packages from nur-xddxdd + wechat-uos + qqmusic + ]; +} \ No newline at end of file