From 9a39e2512e62de9635dcccda536ed07f6c181ec8 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 29 Apr 2025 15:16:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E8=B1=A1mkOutOfStoreSymlink=EF=BC=8C?= =?UTF-8?q?=E4=B8=BA=E4=BB=A5=E5=90=8E=E6=9B=B4=E6=96=B0=E4=B8=BA=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84=E5=81=9A=E5=87=86?= =?UTF-8?q?=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.nix | 3 ++- libs/default.nix | 3 --- libs/home-libs.nix | 18 ++++++++++++++++++ modules/home/hyprland/default.nix | 4 ++-- modules/home/vscode/default.nix | 4 ++-- profiles/apollo/configuration.nix | 3 ++- profiles/apollo/hm/ssh/default.nix | 4 ++-- 7 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 libs/home-libs.nix diff --git a/flake.nix b/flake.nix index 1c4df80..45fad95 100644 --- a/flake.nix +++ b/flake.nix @@ -5,6 +5,7 @@ inherit (nixpkgs) lib; username = "alex"; useremail = "reizero@live.com"; + sourcepath = "/home/${username}/.nix"; libs = import ./libs; in rec { @@ -19,7 +20,7 @@ (profile: { name = profile; value = import ./profiles/${profile} { - inherit self inputs outputs libs username useremail; + inherit self inputs outputs libs sourcepath username useremail; }; }) (attrNames (readDir ./profiles)) diff --git a/libs/default.nix b/libs/default.nix index e6330fb..da1b209 100644 --- a/libs/default.nix +++ b/libs/default.nix @@ -5,7 +5,4 @@ in { # 导出mkNixosSystem函数 inherit (mkNixosSystemLib) mkNixosSystem; - - # 转换相对路径到绝对路径 - absolutePath = path: "${builtins.path { name = "path"; path = path; }}"; } diff --git a/libs/home-libs.nix b/libs/home-libs.nix new file mode 100644 index 0000000..238abcd --- /dev/null +++ b/libs/home-libs.nix @@ -0,0 +1,18 @@ +{ lib, config, sourcepath, ... }: # 声明你可能需要的参数 +{ + options = { + # 使用一个独特的顶层选项名,如 myLib + home-libs = lib.mkOption { + type = lib.types.attrsOf lib.types.anything; + default = { }; + description = "Home manager custom utility functions."; + }; + }; + + config.home-libs = { + # path 参数目前无法通过内置函数的方式获取 + # 需要是相对于 flake 的相对路径,直接由目录开始不需要加 `./`。 + mkOutOfStoreSymlink = path: + config.home-libs.mkOutOfStoreSymlink "${sourcepath}/${path}"; + }; +} diff --git a/modules/home/hyprland/default.nix b/modules/home/hyprland/default.nix index c87286b..fdf2671 100644 --- a/modules/home/hyprland/default.nix +++ b/modules/home/hyprland/default.nix @@ -1,7 +1,7 @@ { config, libs, pkgs, ... }: let conf = [ "hypr" "waybar" "rofi" "kitty" "mako" "wlogout" ]; - confPath = "${config.home.homeDirectory}/.nix/modules/home/hyprland/conf"; + confPath = "modules/home/hyprland/conf"; in { imports = [ @@ -52,7 +52,7 @@ in (name: { inherit name; value = { - source = config.lib.file.mkOutOfStoreSymlink "${confPath}/${name}"; + source = config.home-libs.mkOutOfStoreSymlink "${confPath}/${name}"; }; }) conf diff --git a/modules/home/vscode/default.nix b/modules/home/vscode/default.nix index bf19b24..945c70a 100644 --- a/modules/home/vscode/default.nix +++ b/modules/home/vscode/default.nix @@ -24,10 +24,10 @@ xdg.configFile = { "Code/User/keybindings.json" = { - source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.nix/modules/home/vscode/keybindings.json"; + source = config.home-libs.mkOutOfStoreSymlink "modules/home/vscode/keybindings.json"; }; "Code/User/settings.json" = { - source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.nix/modules/home/vscode/settings.json"; + source = config.home-libs.mkOutOfStoreSymlink "modules/home/vscode/settings.json"; }; }; } diff --git a/profiles/apollo/configuration.nix b/profiles/apollo/configuration.nix index 1337a29..f1708df 100644 --- a/profiles/apollo/configuration.nix +++ b/profiles/apollo/configuration.nix @@ -20,11 +20,12 @@ args@{ self, pkgs, home-manager, username, sysversion, ... }: { # home-manager.useUserPackages = true; home-manager = { extraSpecialArgs = { - inherit (args) self inputs outputs libs hostname username useremail sysversion; + inherit (args) self inputs outputs libs sourcepath hostname username useremail sysversion; }; users."${username}" = { ... }: { imports = [ ./hm + "${self}/libs/home-libs.nix" "${self}/home/desktop.nix" "${self}/modules/home/develop.nix" ]; diff --git a/profiles/apollo/hm/ssh/default.nix b/profiles/apollo/hm/ssh/default.nix index 5d2a1f8..72bc605 100644 --- a/profiles/apollo/hm/ssh/default.nix +++ b/profiles/apollo/hm/ssh/default.nix @@ -1,9 +1,9 @@ -{ config, ... }: { +{ config, flakesPath, ... }: { programs.ssh = { enable = true; }; home.file.".ssh/config" = { - source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.nix/profiles/apollo/hm/ssh/config"; + source = config.home-libs.mkOutOfStoreSymlink "profiles/apollo/hm/ssh/config"; }; }