Refactor flake structure with flake-parts
This commit is contained in:
parent
8ca6499da1
commit
cf83a45191
10 changed files with 203 additions and 176 deletions
10
flake/default.nix
Normal file
10
flake/default.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
imports = [
|
||||
./nixos.nix
|
||||
./home.nix
|
||||
./templates.nix
|
||||
./perSystem.nix
|
||||
./deploy.nix
|
||||
./overlays.nix
|
||||
];
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
{outputs}: {
|
||||
{
|
||||
lib,
|
||||
inputs,
|
||||
flake-parts-lib,
|
||||
self,
|
||||
...
|
||||
}: let
|
||||
inherit (self) outputs;
|
||||
inherit (inputs) deploy-rs;
|
||||
mkDeployNode = {
|
||||
hostName,
|
||||
unixName ? "deploy",
|
||||
|
|
@ -18,7 +21,7 @@
|
|||
system = {
|
||||
user = "root";
|
||||
path =
|
||||
inputs.deploy-rs.lib."${system}".activate.nixos
|
||||
deploy-rs.lib."${system}".activate.nixos
|
||||
outputs.nixosConfigurations."${hostName}";
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,17 +1,13 @@
|
|||
{
|
||||
outputs,
|
||||
rootPath,
|
||||
}: {
|
||||
lib,
|
||||
inputs,
|
||||
self,
|
||||
...
|
||||
}: let
|
||||
rootPath = ./..;
|
||||
inherit (self) outputs;
|
||||
homeModules =
|
||||
{
|
||||
default = import "${toString rootPath}/home/modules";
|
||||
extra = import "${toString rootPath}/home/extra";
|
||||
}
|
||||
// (
|
||||
(
|
||||
(rootPath + "/home")
|
||||
|> builtins.readDir
|
||||
|> lib.filterAttrs (key: value: value == "directory")
|
||||
|
|
@ -23,13 +19,13 @@
|
|||
]
|
||||
)
|
||||
|> builtins.attrNames
|
||||
|> map (name: {
|
||||
name = name;
|
||||
value = import "${toString rootPath}/home/${name}/modules";
|
||||
})
|
||||
|> builtins.listToAttrs
|
||||
);
|
||||
mkHomeConfig = {
|
||||
|> (with lib; flip genAttrs (name: import (rootPath + "/home/${name}/modules")))
|
||||
)
|
||||
// {
|
||||
default = import "${toString rootPath}/home/modules";
|
||||
extra = import "${toString rootPath}/home/extra";
|
||||
};
|
||||
makeHomeConfiguration = {
|
||||
hostName,
|
||||
unixName ? "david",
|
||||
system ? "x86_64-linux",
|
||||
|
|
@ -37,10 +33,12 @@
|
|||
home-manager ? inputs.home-manager,
|
||||
}: {
|
||||
"${unixName}@${hostName}" = home-manager.lib.homeManagerConfiguration {
|
||||
pkgs = nixpkgs.legacyPackages."${system}";
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
modules =
|
||||
[
|
||||
"${toString rootPath}/home/${unixName}/configurations/${hostName}"
|
||||
(rootPath + "/home/${unixName}/configurations/${hostName}")
|
||||
]
|
||||
++ (with homeModules; [
|
||||
default
|
||||
|
|
@ -67,7 +65,7 @@ in {
|
|||
[
|
||||
# Hostname
|
||||
]
|
||||
|> map (hostName: mkHomeConfig {inherit hostName;})
|
||||
|> map (hostName: makeHomeConfiguration {inherit hostName;})
|
||||
);
|
||||
inherit homeModules;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
17
flake/overlays.nix
Normal file
17
flake/overlays.nix
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
self,
|
||||
inputs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
rootPath = ./..;
|
||||
inherit (self) outputs;
|
||||
importWithArgs = lib.flip import {inherit inputs outputs;};
|
||||
in {
|
||||
flake.overlays =
|
||||
[
|
||||
"modifications"
|
||||
"additions"
|
||||
]
|
||||
|> (with lib; flip genAttrs (name: importWithArgs (rootPath + "/overlays/${name}")));
|
||||
}
|
||||
35
flake/perSystem.nix
Normal file
35
flake/perSystem.nix
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{inputs, ...}: let
|
||||
rootPath = ./..;
|
||||
in {
|
||||
imports = [
|
||||
(rootPath + "/treefmt.nix")
|
||||
];
|
||||
perSystem = {
|
||||
pkgs,
|
||||
system,
|
||||
lib,
|
||||
self',
|
||||
...
|
||||
}: let
|
||||
inherit (inputs) nixpkgs;
|
||||
callPackages = lib.callPackagesWith (pkgs // {inherit callPackages inputs rootPath;});
|
||||
in {
|
||||
_module.args.pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
config = {
|
||||
allowUnfree = true;
|
||||
};
|
||||
};
|
||||
devShells.default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
nixd
|
||||
typos
|
||||
typos-lsp
|
||||
just
|
||||
nvfetcher
|
||||
];
|
||||
};
|
||||
packages = callPackages (rootPath + "/pkgs") {};
|
||||
checks = self'.packages;
|
||||
};
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
{rootPath, ...}: {
|
||||
{
|
||||
flake-parts-lib,
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
}: let
|
||||
rootPath = ./..;
|
||||
in {
|
||||
options = {
|
||||
flake = flake-parts-lib.mkSubmoduleOptions {
|
||||
templates = lib.mkOption {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue