Refactor flake structure with flake-parts

This commit is contained in:
ulic-youthlic 2025-06-09 16:14:57 +08:00
parent 8ca6499da1
commit cf83a45191
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
10 changed files with 203 additions and 176 deletions

View file

@ -1,42 +1,37 @@
{
rootPath,
outputs,
}: {inputs, ...}: let
inputs,
lib,
self,
...
}: let
rootPath = ./..;
inherit (self) outputs;
inherit (inputs) nixpkgs;
defaultNixosModule = import (rootPath + "/nixos/modules");
inherit (inputs.nixpkgs) lib;
in {
flake = {
nixosModules.default = defaultNixosModule;
nixosConfigurations = let
nixosConfigDir = rootPath + "/nixos/configurations";
makeNixConfiguration = hostName:
lib.nixosSystem {
nixpkgs.lib.nixosSystem {
modules =
[defaultNixosModule]
++ [
(
let
dirPath = nixosConfigDir + "/${hostName}";
filePath = nixosConfigDir + "/${hostName}.nix";
in
if builtins.pathExists dirPath
then dirPath
else filePath
)
(rootPath + "/nixos/configurations/${hostName}")
];
specialArgs = {
inherit inputs outputs rootPath;
};
};
in
nixosConfigDir
|> builtins.readDir
|> builtins.attrNames
|> map (f: lib.removeSuffix ".nix" f)
|> map (name: {
inherit name;
value = makeNixConfiguration name;
})
|> builtins.listToAttrs;
[
"Tytonidae"
"Cape"
"Akun"
]
|> (
with lib;
flip genAttrs makeNixConfiguration
);
};
}