mirror of
https://github.com/smg1024/nix-darwin.git
synced 2026-05-22 20:32:59 +09:00
refactor: migrate nix-darwin config to a flake-parts dendritic layout
This commit is contained in:
parent
f80b0b0d4f
commit
09801ac429
84 changed files with 1029 additions and 687 deletions
70
modules/flake/darwin-configurations.nix
Normal file
70
modules/flake/darwin-configurations.nix
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
config,
|
||||
inputs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
userName = config.repo.user.name;
|
||||
|
||||
mkDarwinConfiguration = hostName: hostConfig: let
|
||||
hostContext = {
|
||||
name = hostName;
|
||||
system = hostConfig.system;
|
||||
features = hostConfig.features;
|
||||
};
|
||||
|
||||
darwinModules = builtins.map (feature: config.flake.modules.darwin.${feature} or {}) hostConfig.features;
|
||||
homeModules = builtins.map (feature: config.repo.homeModules.${feature} or {}) hostConfig.features;
|
||||
in
|
||||
inputs.darwin.lib.darwinSystem {
|
||||
system = hostConfig.system;
|
||||
modules =
|
||||
[
|
||||
./darwin-context.nix
|
||||
{
|
||||
repo = {
|
||||
user = config.repo.user;
|
||||
host = hostContext;
|
||||
};
|
||||
}
|
||||
]
|
||||
++ darwinModules
|
||||
++ [
|
||||
inputs.nix-homebrew.darwinModules.nix-homebrew
|
||||
inputs.home-manager.darwinModules.home-manager
|
||||
{
|
||||
home-manager = {
|
||||
useGlobalPkgs = true;
|
||||
useUserPackages = true;
|
||||
backupFileExtension = "backup";
|
||||
sharedModules = [
|
||||
inputs.nvf.homeManagerModules.nvf
|
||||
inputs.sops-nix.homeManagerModules.sops
|
||||
./home-context.nix
|
||||
];
|
||||
users.${userName}.imports =
|
||||
[
|
||||
{
|
||||
repo = {
|
||||
user = {
|
||||
inherit
|
||||
(config.repo.user)
|
||||
name
|
||||
email
|
||||
homeDirectory
|
||||
homeStateVersion
|
||||
secretFile
|
||||
;
|
||||
};
|
||||
host = hostContext;
|
||||
};
|
||||
}
|
||||
]
|
||||
++ homeModules;
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
in {
|
||||
flake.darwinConfigurations = lib.mapAttrs mkDarwinConfiguration config.repo.hosts;
|
||||
}
|
||||
39
modules/flake/darwin-context.nix
Normal file
39
modules/flake/darwin-context.nix
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkOption;
|
||||
types = lib.types;
|
||||
in {
|
||||
options.repo = {
|
||||
user = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
email = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
homeDirectory = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
homeStateVersion = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
darwinStateVersion = mkOption {
|
||||
type = types.int;
|
||||
};
|
||||
secretFile = mkOption {
|
||||
type = types.path;
|
||||
};
|
||||
};
|
||||
|
||||
host = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
system = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
features = mkOption {
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
6
modules/flake/default.nix
Normal file
6
modules/flake/default.nix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{...}: {
|
||||
imports = [
|
||||
./options.nix
|
||||
./darwin-configurations.nix
|
||||
];
|
||||
}
|
||||
36
modules/flake/home-context.nix
Normal file
36
modules/flake/home-context.nix
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkOption;
|
||||
types = lib.types;
|
||||
in {
|
||||
options.repo = {
|
||||
user = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
email = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
homeDirectory = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
homeStateVersion = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
secretFile = mkOption {
|
||||
type = types.path;
|
||||
};
|
||||
};
|
||||
|
||||
host = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
system = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
features = mkOption {
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
60
modules/flake/options.nix
Normal file
60
modules/flake/options.nix
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkDefault mkOption;
|
||||
types = lib.types;
|
||||
in {
|
||||
options.repo = {
|
||||
user = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
email = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
homeDirectory = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
homeStateVersion = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
darwinStateVersion = mkOption {
|
||||
type = types.int;
|
||||
};
|
||||
secretFile = mkOption {
|
||||
type = types.path;
|
||||
};
|
||||
};
|
||||
|
||||
hosts = mkOption {
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
system = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
features = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
});
|
||||
default = {};
|
||||
};
|
||||
|
||||
homeModules = mkOption {
|
||||
type = types.lazyAttrsOf types.deferredModule;
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
|
||||
config.repo.user = {
|
||||
name = mkDefault "poby";
|
||||
email = mkDefault "smg981024@gmail.com";
|
||||
homeDirectory = mkDefault "/Users/${config.repo.user.name}";
|
||||
homeStateVersion = mkDefault "25.11";
|
||||
darwinStateVersion = mkDefault 6;
|
||||
secretFile = mkDefault ../../secrets/poby.yaml;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue