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"; }; }