refactor flake structure
This commit is contained in:
parent
3412ecb175
commit
66a2700943
9 changed files with 207 additions and 177 deletions
193
flake.nix
193
flake.nix
|
|
@ -168,14 +168,21 @@
|
|||
flake-parts,
|
||||
flake-utils,
|
||||
...
|
||||
} @ inputs: let
|
||||
inherit (self) outputs;
|
||||
rootPath = ./.;
|
||||
in
|
||||
flake-parts.lib.mkFlake {inherit inputs;} {
|
||||
} @ inputs:
|
||||
flake-parts.lib.mkFlake {inherit inputs;} ({flake-parts-lib, ...}: let
|
||||
inherit (self) outputs;
|
||||
inherit (flake-parts-lib) importApply;
|
||||
rootPath = ./.;
|
||||
nixos = importApply ./flake/nixos.nix {inherit rootPath outputs;};
|
||||
home = importApply ./flake/home.nix {inherit rootPath outputs;};
|
||||
deploy = importApply ./flake/deploy.nix {inherit outputs;};
|
||||
in {
|
||||
systems = flake-utils.lib.defaultSystems;
|
||||
imports = [
|
||||
inputs.home-manager.flakeModules.home-manager
|
||||
nixos
|
||||
home
|
||||
deploy
|
||||
];
|
||||
perSystem = {
|
||||
pkgs,
|
||||
|
|
@ -204,164 +211,22 @@
|
|||
];
|
||||
};
|
||||
};
|
||||
flake =
|
||||
{
|
||||
nix.settings = {
|
||||
# substituters shared in home-manager and nixos configuration
|
||||
substituters = let
|
||||
cachix = x: "https://${x}.cachix.org";
|
||||
in
|
||||
nixpkgs.lib.flatten [
|
||||
(cachix "nix-community")
|
||||
"https://cache.nixos.org"
|
||||
(cachix "cosmic")
|
||||
];
|
||||
};
|
||||
|
||||
nixosModules.default = import ./nixos/modules;
|
||||
|
||||
overlays = {
|
||||
modifications = import ./overlays/modifications {inherit inputs outputs;};
|
||||
additions = import ./overlays/additions {inherit inputs outputs;};
|
||||
};
|
||||
|
||||
nixosConfigurations = let
|
||||
nixosConfigDir = ./nixos/configurations;
|
||||
makeNixConfiguration = 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;};
|
||||
};
|
||||
flake = {
|
||||
overlays = {
|
||||
modifications = import ./overlays/modifications {inherit inputs outputs;};
|
||||
additions = import ./overlays/additions {inherit inputs outputs;};
|
||||
};
|
||||
nix.settings = {
|
||||
# substituters shared in home-manager and nixos configuration
|
||||
substituters = let
|
||||
cachix = x: "https://${x}.cachix.org";
|
||||
in
|
||||
nixosConfigDir
|
||||
|> builtins.readDir
|
||||
|> builtins.attrNames
|
||||
|> map (f: nixpkgs.lib.removeSuffix ".nix" f)
|
||||
|> map (name: {
|
||||
inherit name;
|
||||
value = makeNixConfiguration name;
|
||||
})
|
||||
|> builtins.listToAttrs;
|
||||
}
|
||||
// (
|
||||
let
|
||||
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 ./home}/${unixName}/configurations/${hostName}"
|
||||
]
|
||||
++ (with outputs.homeModules; [
|
||||
default
|
||||
extra
|
||||
])
|
||||
++ [
|
||||
outputs.homeModules."${unixName}"
|
||||
];
|
||||
extraSpecialArgs = {
|
||||
inherit
|
||||
inputs
|
||||
outputs
|
||||
unixName
|
||||
hostName
|
||||
system
|
||||
rootPath
|
||||
;
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
homeConfigurations =
|
||||
nixpkgs.lib.foldr (a: b: a // b) {} (
|
||||
map (hostName: mkHomeConfig {inherit hostName;}) [
|
||||
"Tytonidae"
|
||||
"Akun"
|
||||
]
|
||||
)
|
||||
// mkHomeConfig {
|
||||
hostName = "Cape";
|
||||
unixName = "alice";
|
||||
};
|
||||
homeModules =
|
||||
{
|
||||
default = import ./home/modules;
|
||||
extra = import ./home/extra;
|
||||
}
|
||||
// (
|
||||
./home
|
||||
|> builtins.readDir
|
||||
|> nixpkgs.lib.filterAttrs (key: value: value == "directory")
|
||||
|> nixpkgs.lib.filterAttrs (
|
||||
key: value:
|
||||
!builtins.elem key [
|
||||
"modules"
|
||||
"extra"
|
||||
]
|
||||
)
|
||||
|> builtins.attrNames
|
||||
|> map (name: {
|
||||
name = name;
|
||||
value = import "${toString ./home}/${name}/modules";
|
||||
})
|
||||
|> builtins.listToAttrs
|
||||
);
|
||||
}
|
||||
)
|
||||
// (
|
||||
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
|
||||
self.outputs.nixosConfigurations."${hostName}";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
deploy.nodes =
|
||||
[
|
||||
"Cape"
|
||||
"Akun"
|
||||
]
|
||||
|> map (
|
||||
hostName:
|
||||
mkDeployNode {
|
||||
inherit hostName;
|
||||
}
|
||||
)
|
||||
|> nixpkgs.lib.foldr (a: b: a // b) {};
|
||||
}
|
||||
);
|
||||
};
|
||||
nixpkgs.lib.flatten [
|
||||
(cachix "nix-community")
|
||||
"https://cache.nixos.org"
|
||||
(cachix "cosmic")
|
||||
];
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue