抽象mkOutOfStoreSymlink,为以后更新为引用相对路径做准备

This commit is contained in:
2025-04-29 15:16:45 +08:00
parent d4177d6823
commit 9a39e2512e
7 changed files with 28 additions and 11 deletions

View File

@@ -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))

View File

@@ -5,7 +5,4 @@ in
{
# 导出mkNixosSystem函数
inherit (mkNixosSystemLib) mkNixosSystem;
# 转换相对路径到绝对路径
absolutePath = path: "${builtins.path { name = "path"; path = path; }}";
}

18
libs/home-libs.nix Normal file
View File

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

View File

@@ -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

View File

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

View File

@@ -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"
];

View File

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