refactor flake structure
This commit is contained in:
parent
3412ecb175
commit
66a2700943
9 changed files with 207 additions and 177 deletions
49
flake/deploy.nix
Normal file
49
flake/deploy.nix
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
{outputs}: {
|
||||
lib,
|
||||
inputs,
|
||||
flake-parts-lib,
|
||||
...
|
||||
}: let
|
||||
mkDeployNode = {
|
||||
hostName,
|
||||
unixName ? "deploy",
|
||||
system ? "x86_64-linux",
|
||||
sshName ? hostName,
|
||||
}: {
|
||||
"${hostName}" = {
|
||||
hostname = "${sshName}";
|
||||
sshUser = "${unixName}";
|
||||
interactiveSudo = true;
|
||||
profiles = {
|
||||
system = {
|
||||
user = "root";
|
||||
path =
|
||||
inputs.deploy-rs.lib."${system}".activate.nixos
|
||||
outputs.nixosConfigurations."${hostName}";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
options = {
|
||||
flake = flake-parts-lib.mkSubmoduleOptions {
|
||||
deploy = lib.mkOption {
|
||||
type = lib.types.lazyAttrsOf lib.types.raw;
|
||||
};
|
||||
};
|
||||
};
|
||||
config = {
|
||||
flake.deploy.nodes =
|
||||
[
|
||||
"Cape"
|
||||
"Akun"
|
||||
]
|
||||
|> map (
|
||||
hostName:
|
||||
mkDeployNode {
|
||||
inherit hostName;
|
||||
}
|
||||
)
|
||||
|> lib.foldr (a: b: a // b) {};
|
||||
};
|
||||
}
|
||||
79
flake/home.nix
Normal file
79
flake/home.nix
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
outputs,
|
||||
rootPath,
|
||||
}: {
|
||||
lib,
|
||||
inputs,
|
||||
...
|
||||
}: let
|
||||
homeModules =
|
||||
{
|
||||
default = import "${toString rootPath}/home/modules";
|
||||
extra = import "${toString rootPath}/home/extra";
|
||||
}
|
||||
// (
|
||||
(rootPath + "/home")
|
||||
|> builtins.readDir
|
||||
|> lib.filterAttrs (key: value: value == "directory")
|
||||
|> lib.filterAttrs (
|
||||
key: value:
|
||||
!builtins.elem key [
|
||||
"modules"
|
||||
"extra"
|
||||
]
|
||||
)
|
||||
|> builtins.attrNames
|
||||
|> map (name: {
|
||||
name = name;
|
||||
value = import "${toString rootPath}/home/${name}/modules";
|
||||
})
|
||||
|> builtins.listToAttrs
|
||||
);
|
||||
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 =
|
||||
[
|
||||
"${toString rootPath}/home/${unixName}/configurations/${hostName}"
|
||||
]
|
||||
++ (with homeModules; [
|
||||
default
|
||||
extra
|
||||
])
|
||||
++ [
|
||||
homeModules."${unixName}"
|
||||
];
|
||||
extraSpecialArgs = {
|
||||
inherit
|
||||
inputs
|
||||
outputs
|
||||
unixName
|
||||
hostName
|
||||
system
|
||||
rootPath
|
||||
;
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
flake = {
|
||||
homeConfigurations =
|
||||
lib.foldr (a: b: a // b) {} (
|
||||
map (hostName: mkHomeConfig {inherit hostName;}) [
|
||||
"Tytonidae"
|
||||
"Akun"
|
||||
]
|
||||
)
|
||||
// mkHomeConfig {
|
||||
hostName = "Cape";
|
||||
unixName = "alice";
|
||||
};
|
||||
inherit homeModules;
|
||||
};
|
||||
}
|
||||
42
flake/nixos.nix
Normal file
42
flake/nixos.nix
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
rootPath,
|
||||
outputs,
|
||||
}: {inputs, ...}: let
|
||||
defaultNixosModule = import (rootPath + "/nixos/modules");
|
||||
inherit (inputs.nixpkgs) lib;
|
||||
in {
|
||||
flake = {
|
||||
nixosModules.default = defaultNixosModule;
|
||||
nixosConfigurations = let
|
||||
nixosConfigDir = rootPath + "/nixos/configurations";
|
||||
makeNixConfiguration = hostName:
|
||||
lib.nixosSystem {
|
||||
modules =
|
||||
[defaultNixosModule]
|
||||
++ [
|
||||
(
|
||||
let
|
||||
dirPath = nixosConfigDir + "/${hostName}";
|
||||
filePath = nixosConfigDir + "/${hostName}.nix";
|
||||
in
|
||||
if builtins.pathExists dirPath
|
||||
then dirPath
|
||||
else filePath
|
||||
)
|
||||
];
|
||||
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;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue