♻️ refactor layout, simplify flake.nix

This commit is contained in:
2023-07-27 15:22:16 -04:00
parent 74296f8b9b
commit d4b4ba1d1e
12 changed files with 225 additions and 228 deletions

12
nix/checks.nix Normal file
View File

@ -0,0 +1,12 @@
{ self, system, pre-commit-hooks, ... }:
with self.pkgs.${system};
{
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
deadnix.enable = true;
nixpkgs-fmt.enable = true;
statix.enable = true;
};
};
} // (deploy-rs.lib.deployChecks self.deploy)

22
nix/darwin.nix Normal file
View File

@ -0,0 +1,22 @@
{ self, darwin, home-manager, dotfiles, ... }:
let
mkDarwin = hostName: modules:
let
hostSystem = self.hosts.${hostName}.system;
in
darwin.lib.darwinSystem {
system = hostSystem;
modules = [
home-manager.darwinModules.home-manager
(_: {
networking.hostName = hostName;
nixpkgs.pkgs = self.pkgs.${hostSystem};
})
] ++ modules;
specialArgs = { inherit dotfiles home-manager; };
};
in
{
epicurus = mkDarwin "epicurus" [ ../hosts/epicurus/darwin-configuration.nix ];
heraclitus = mkDarwin "heraclitus" [ ../hosts/heraclitus/darwin-configuration.nix ];
}

25
nix/deploy.nix Normal file
View File

@ -0,0 +1,25 @@
{ self, deploy-rs, ... }:
let
mkDeploy = hostName:
let
inherit (self.hosts.${hostName}) type address system sshUser;
inherit (deploy-rs.lib.${system}) activate;
in
{
hostname = address;
profiles.system.user = "root";
profiles.system.sshUser = sshUser;
profiles.system.path = activate.${type} self."${type}Configurations".${hostName};
};
in
{
nodes = {
socrates = mkDeploy "socrates";
plato = mkDeploy "plato";
agent = mkDeploy "agent";
form = mkDeploy "form";
matter = mkDeploy "matter";
purpose = mkDeploy "purpose";
epicurus = mkDeploy "epicurus";
};
}

5
nix/home.nix Normal file
View File

@ -0,0 +1,5 @@
{ dotfiles, ... }:
{
"walkah@epicurus" = dotfiles.homeConfigurations.aarch64-darwin.walkah;
"walkah@heraclitus" = dotfiles.homeConfigurations.aarch64-darwin.walkah;
}

49
nix/hosts.nix Normal file
View File

@ -0,0 +1,49 @@
{
socrates = {
type = "nixos";
address = "100.103.57.96";
system = "x86_64-linux";
sshUser = "walkah";
};
plato = {
type = "nixos";
address = "100.111.208.75";
system = "x86_64-linux";
sshUser = "walkah";
};
agent = {
type = "nixos";
address = "100.95.167.126";
system = "aarch64-linux";
sshUser = "root";
};
form = {
type = "nixos";
address = "100.87.220.71";
system = "aarch64-linux";
sshUser = "root";
};
matter = {
type = "nixos";
address = "100.126.255.109";
system = "aarch64-linux";
sshUser = "root";
};
purpose = {
type = "nixos";
address = "100.74.59.80";
system = "aarch64-linux";
sshUser = "root";
};
epicurus = {
type = "darwin";
address = "100.66.26.116";
system = "aarch64-darwin";
sshUser = "walkah";
};
heraclitus = {
type = "darwin";
address = "100.107.57.128";
system = "aarch64-darwin";
};
}

28
nix/nixos.nix Normal file
View File

@ -0,0 +1,28 @@
{ self, dotfiles, nixpkgs, home-manager, nixos-hardware, sops-nix, ... }:
let
mkSystem = hostName: modules:
let
hostSystem = self.hosts.${hostName}.system;
in
nixpkgs.lib.nixosSystem {
system = hostSystem;
modules = [
home-manager.nixosModules.home-manager
(_: {
networking.hostName = hostName;
nixpkgs.pkgs = self.pkgs.${hostSystem};
})
] ++ modules;
specialArgs = { inherit dotfiles nixos-hardware sops-nix; };
};
in
{
# Aristotle
agent = mkSystem "agent" [ ../hosts/aristotle/configuration.nix ];
form = mkSystem "form" [ ../hosts/aristotle/configuration.nix ];
matter = mkSystem "matter" [ ../hosts/aristotle/configuration.nix ];
purpose = mkSystem "purpose" [ ../hosts/aristotle/configuration.nix ];
plato = mkSystem "plato" [ ../hosts/plato/configuration.nix ];
socrates = mkSystem "socrates" [ ../hosts/socrates/configuration.nix ];
}

27
nix/shells.nix Normal file
View File

@ -0,0 +1,27 @@
{ system, self, ... }:
with self.pkgs.${system};
let
darwin-local = writeScriptBin "darwin-local" ''
#!${stdenv.shell}
nix build .#darwinConfigurations.$(hostname -s).system
./result/sw/bin/darwin-rebuild switch --flake .
'';
in
{
default = mkShell {
name = "athens";
buildInputs = with pkgs; [
darwin-local
deploy-rs.deploy-rs
deadnix
nil
nixpkgs-fmt
statix
sops
];
inherit (self.checks.${system}.pre-commit-check) shellHook;
};
}