build a brandnew architecture for configurations.

This commit is contained in:
Ulic-youthlic 2025-01-08 14:53:44 +08:00
parent 08aacf8c0d
commit 6dbbce42cf
43 changed files with 425 additions and 643 deletions

166
flake.nix
View file

@ -67,67 +67,125 @@
}@inputs:
let
inherit (self) outputs;
rootPath = ./.;
in
flake-parts.lib.mkFlake { inherit inputs; } {
systems = flake-utils.lib.defaultSystems;
flake = {
nix.settings = {
# substituters shared in home-manager and nixos configuration
substituters =
let
channelStore = x: "https://${x}/nix-channels/store";
mirrors = map (x: channelStore "mirrors.${x}.edu.cn") [
"bfsu"
"tuna.tsinghua"
"ustc"
flake =
{
nix.settings = {
# substituters shared in home-manager and nixos configuration
substituters =
let
channelStore = x: "https://${x}/nix-channels/store";
mirrors = map (x: channelStore "mirrors.${x}.edu.cn") [
"bfsu"
"tuna.tsinghua"
"ustc"
];
cachix = x: "https://${x}.cachix.org";
in
nixpkgs.lib.flatten [
mirrors
(cachix "nix-community")
"https://cache.nixos.org"
(cachix "cosmic")
];
cachix = x: "https://${x}.cachix.org";
};
nixosModules.default = import ./nixos/modules;
overlays = {
modifications = (import ./overlays/modifications { inherit inputs; });
additions = (import ./overlays/additions { inherit inputs; });
};
nixosConfigurations =
let
nixosConfigDir = ./nixos/configurations;
in
nixpkgs.lib.flatten [
mirrors
(cachix "nix-community")
"https://cache.nixos.org"
(cachix "cosmic")
];
};
nixosModules.default = import ./nixos/modules;
overlays = {
modifications = (import ./overlays/modifications { inherit inputs; });
additions = (import ./overlays/additions { inherit inputs; });
};
nixosConfigurations =
nixpkgs.lib.genAttrs
(map (f: nixpkgs.lib.removeSuffix ".nix" f) (builtins.attrNames (builtins.readDir nixosConfigDir)))
(
hostName:
nixpkgs.lib.nixosSystem {
modules =
[
outputs.nixosModules.default
]
++ [
(
let
dirPath = nixosConfigDir + "/${hostName}";
filePath = nixosConfigDir + "/${hostName}.nix";
in
if builtins.pathExists dirPath then dirPath else filePath
)
];
specialArgs = {
inherit inputs outputs rootPath;
};
}
);
}
// (
let
nixosConfigDir = ./nixos/configurations;
in
nixpkgs.lib.genAttrs
(map (f: nixpkgs.lib.removeSuffix ".nix" f) (builtins.attrNames (builtins.readDir nixosConfigDir)))
(
hostName:
nixpkgs.lib.nixosSystem {
modules =
[
(
let
dirPath = nixosConfigDir + "/${hostName}";
filePath = nixosConfigDir + "/${hostName}.nix";
in
if builtins.pathExists dirPath then dirPath else filePath
)
./configuration.nix
./users
]
++ [
outputs.nixosModules.default
];
specialArgs = {
inherit inputs outputs;
mkHomeConfig =
{
hostName,
unixName ? "david",
system ? "x86_64-linux",
nixpkgs ? inputs.nixpkgs,
home-manager ? inputs.home-manager,
}:
{
"${unixName}@${hostName}" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages."${system}";
modules =
[
(./home + "/${unixName}/configurations/${hostName}")
]
++ (with outputs.homeManagerModules; [
default
"${unixName}"
]);
extraSpecialArgs = {
inherit
inputs
outputs
unixName
hostName
system
rootPath
;
};
};
}
};
in
{
homeConfigurations = nixpkgs.foldr (a: b: a // b) { } (
map (hostName: mkHomeConfig { inherit hostName; }) [ "Tytonidae" ]
);
};
homeManagerModules =
{
default = import ./home/modules;
}
// (
let
allEntries = builtins.readDir ./home;
allUsers = nixpkgs.lib.filterAttrs (
key: value: value == "directory" && key != "modules"
) allEntries;
in
builtins.listToAttrs (
map (name: {
name = name;
value = import ./home + "/${name}/modules";
}) (builtins.attrNames allUsers)
)
);
}
);
};
}