♻️ refactor layout, simplify flake.nix

This commit is contained in:
James Walker 2023-07-27 15:22:16 -04:00
parent 74296f8b9b
commit d4b4ba1d1e
Signed by: walkah
GPG Key ID: 3C127179D6086E93
12 changed files with 225 additions and 228 deletions

45
flake.lock generated
View File

@ -7,11 +7,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1690247892, "lastModified": 1690431538,
"narHash": "sha256-WMGc1yq1cqRd+kzjWgbvHxckJIe8VQfiZ5RfR8tgABw=", "narHash": "sha256-Uml8ivMMOFPB9fNSDcw72imGHRdJpaK12sRm2DTLLe8=",
"owner": "lnl7", "owner": "lnl7",
"repo": "nix-darwin", "repo": "nix-darwin",
"rev": "efd35d99ce412335c478dff9da9a4256bbd39757", "rev": "16c07487ac9bc59f58b121d13160c67befa3342e",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -53,14 +53,17 @@
], ],
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
],
"pre-commit-hooks": [
"pre-commit-hooks"
] ]
}, },
"locked": { "locked": {
"lastModified": 1690231853, "lastModified": 1690407224,
"narHash": "sha256-kayhWrLn6kcf2tLT20Lj9ldsjhjtxmDyaLT6tp+k1T0=", "narHash": "sha256-pmgl0SZ6dXMXBJXykyoCiK4niLfIghhV566V14BMctI=",
"owner": "walkah", "owner": "walkah",
"repo": "dotfiles", "repo": "dotfiles",
"rev": "63b05b74b4a7166d099049d39dad4d13860411b0", "rev": "fcaf64f19fd4d53bed05104ed42717ea0a8e35f9",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -174,11 +177,11 @@
"systems": "systems_3" "systems": "systems_3"
}, },
"locked": { "locked": {
"lastModified": 1685518550, "lastModified": 1689068808,
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -213,11 +216,11 @@
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
}, },
"locked": { "locked": {
"lastModified": 1690269402, "lastModified": 1690476848,
"narHash": "sha256-SybA24IOGigiHfcTB5eBge4UZQI6a0z8Ah+EzD17tdk=", "narHash": "sha256-PSmzyuEbMxEn2uwwLYUN2l1psoJXb7jm/kfHD12Sq0k=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "0306d5ed7e9d1662b55ec0d08afc73d4cb5eadca", "rev": "8d243f7da13d6ee32f722a3f1afeced150b6d4da",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -328,11 +331,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1690235791, "lastModified": 1690441914,
"narHash": "sha256-QkPVQ859F0wXyd74A7UPYbmi4B5xYN4Ns7AQ0pvM0Wo=", "narHash": "sha256-Ac+kJQ5z9MDAMyzSc0i0zJDx2i3qi9NjlW5Lz285G/I=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "dfcffbd74fd6f0419370d8240e445252a39f4d10", "rev": "db8672b8d0a2593c2405aed0c1dfa64b2a2f428f",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -353,11 +356,11 @@
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
"lastModified": 1689668210, "lastModified": 1690464206,
"narHash": "sha256-XAATwDkaUxH958yXLs1lcEOmU6pSEIkatY3qjqk8X0E=", "narHash": "sha256-38V4kmOh6ikpfGiAS+Kt2H/TA2DubSqE66veP/jmB4Q=",
"owner": "cachix", "owner": "cachix",
"repo": "pre-commit-hooks.nix", "repo": "pre-commit-hooks.nix",
"rev": "eb433bff05b285258be76513add6f6c57b441775", "rev": "9289996dcac62fd45836db7c07b87d2521eb526d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -472,11 +475,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1686189967, "lastModified": 1690483941,
"narHash": "sha256-MKEIclafqC6oXxaP+w0zDtdVEmW3WCPgHzhnLyt7ijU=", "narHash": "sha256-/Fo0i4QNWkTpAB+4Dxd/mG6poy2THZ61dTgHmSyQets=",
"owner": "walkah", "owner": "walkah",
"repo": "workon", "repo": "workon",
"rev": "ea4766fa8dc5219804ebbdb6df411586fba402e9", "rev": "3ad1dcfa4fc8192391210640c2c22ef2c0a17d36",
"type": "github" "type": "github"
}, },
"original": { "original": {

226
flake.nix
View File

@ -44,6 +44,7 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
inputs.home-manager.follows = "home-manager"; inputs.home-manager.follows = "home-manager";
inputs.flake-utils.follows = "flake-utils"; inputs.flake-utils.follows = "flake-utils";
inputs.pre-commit-hooks.follows = "pre-commit-hooks";
}; };
workon = { workon = {
@ -52,211 +53,28 @@
}; };
}; };
outputs = outputs = { self, nixpkgs, flake-utils, deploy-rs, pre-commit-hooks, workon, ... }@inputs:
{ self flake-utils.lib.eachDefaultSystem
, nixpkgs (system: {
, deploy-rs pkgs = import nixpkgs {
, darwin inherit system;
, flake-utils overlays = [ self.overlays.default ];
, home-manager config.allowUnfree = true;
, nixos-generators };
, pre-commit-hooks checks = import ./nix/checks.nix { inherit self system pre-commit-hooks; };
, dotfiles devShells = import ./nix/shells.nix { inherit self system; };
, workon formatter = self.pkgs.nixpkgs-fmt;
, ... })
}@inputs: // {
let hosts = import ./nix/hosts.nix;
overlays = [ overlays.default = nixpkgs.lib.composeManyExtensions [
(self: _super: { deploy-rs.overlay
workon = workon.packages.${self.system}.default; workon.overlays.default
})
]; ];
mkSystem = hostName: system: modules: darwinConfigurations = import ./nix/darwin.nix inputs;
nixpkgs.lib.nixosSystem { homeConfigurations = import ./nix/home.nix inputs;
inherit system; nixosConfigurations = import ./nix/nixos.nix inputs;
modules = [ deploy = import ./nix/deploy.nix inputs;
home-manager.nixosModules.home-manager
(_: {
networking.hostName = hostName;
nixpkgs.overlays = overlays;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
})
] ++ modules;
specialArgs = inputs;
};
mkDarwin = hostName: system: modules:
darwin.lib.darwinSystem {
inherit system;
modules = [
home-manager.darwinModules.home-manager
(_: {
networking.hostName = hostName;
nixpkgs.overlays = overlays;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
})
] ++ modules;
specialArgs = inputs;
};
in
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
darwin-local = pkgs.writeScriptBin "darwin-local" ''
#!${pkgs.stdenv.shell}
nix build .#darwinConfigurations.$(hostname -s).system
./result/sw/bin/darwin-rebuild switch --flake .
'';
in
{
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
deadnix.enable = true;
nixpkgs-fmt.enable = true;
statix.enable = true;
};
};
};
packages = {
digitalocean = nixos-generators.nixosGenerate {
system = "x86_64-linux";
format = "do";
modules = [
./modules/base
./users
];
};
};
devShells.default = pkgs.mkShell {
name = "athens";
buildInputs = with pkgs; [
darwin-local
deploy-rs.packages.${system}.deploy-rs
deadnix
nil
nixpkgs-fmt
statix
sops
];
inherit (self.checks.${system}.pre-commit-check) shellHook;
};
formatter = pkgs.nixpkgs-fmt;
}) // {
nixosConfigurations = {
# Aristotle
agent = mkSystem "agent" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ];
form = mkSystem "form" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ];
matter = mkSystem "matter" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ];
purpose = mkSystem "purpose" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ];
plato = mkSystem "plato" "x86_64-linux" [ ./hosts/plato/configuration.nix ];
socrates = mkSystem "socrates" "x86_64-linux" [ ./hosts/socrates/configuration.nix ];
};
darwinConfigurations = {
epicurus = mkDarwin "epicurus" "aarch64-darwin" [ ./hosts/epicurus/darwin-configuration.nix ];
heraclitus = mkDarwin "heraclitus" "aarch64-darwin" [ ./hosts/heraclitus/darwin-configuration.nix ];
};
homeConfigurations = {
"walkah@epicurus" = dotfiles.homeConfigurations.aarch64-darwin.walkah;
"walkah@heraclitus" = dotfiles.homeConfigurations.aarch64-darwin.walkah;
};
deploy.nodes = {
agent = {
hostname = "agent";
sshUser = "root";
profiles.system = {
user = "root";
path = deploy-rs.lib.aarch64-linux.activate.nixos
self.nixosConfigurations.agent;
};
};
form = {
hostname = "form";
sshUser = "root";
profiles.system = {
user = "root";
path = deploy-rs.lib.aarch64-linux.activate.nixos
self.nixosConfigurations.form;
};
};
matter = {
hostname = "matter";
sshUser = "root";
profiles.system = {
user = "root";
path = deploy-rs.lib.aarch64-linux.activate.nixos
self.nixosConfigurations.matter;
};
};
purpose = {
hostname = "purpose";
sshUser = "root";
profiles.system = {
user = "root";
path = deploy-rs.lib.aarch64-linux.activate.nixos
self.nixosConfigurations.purpose;
};
};
plato = {
hostname = "plato";
profiles = {
system = {
user = "root";
path = deploy-rs.lib.x86_64-linux.activate.nixos
self.nixosConfigurations.plato;
};
walkah = {
user = "walkah";
path = deploy-rs.lib.x86_64-linux.activate.home-manager
dotfiles.homeConfigurations.x86_64-linux.walkah;
};
};
};
socrates = {
hostname = "socrates";
profiles = {
system = {
user = "root";
path = deploy-rs.lib.x86_64-linux.activate.nixos
self.nixosConfigurations.socrates;
};
walkah = {
user = "walkah";
path = deploy-rs.lib.x86_64-linux.activate.home-manager
dotfiles.homeConfigurations.x86_64-linux.walkah;
};
};
};
epicurus = {
hostname = "epicurus";
profiles = {
system = {
user = "root";
path = deploy-rs.lib.aarch64-darwin.activate.darwin self.darwinConfigurations.epicurus;
};
walkah = {
user = "walkah";
path = deploy-rs.lib.aarch64-darwin.activate.home-manager dotfiles.homeConfigurations.aarch64-darwin.walkah;
};
};
};
};
}; };
} }

View File

@ -1,4 +1,4 @@
{ pkgs, ... }: { { pkgs, dotfiles, ... }: {
imports = [ ./common.nix ]; imports = [ ./common.nix ];
@ -42,6 +42,11 @@
}; };
}; };
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.walkah = import "${dotfiles}/home.nix";
nixpkgs.config.packageOverrides = pkgs: { nixpkgs.config.packageOverrides = pkgs: {
haskellPackages = pkgs.haskellPackages.override { haskellPackages = pkgs.haskellPackages.override {
overrides = _self: super: { overrides = _self: super: {

View File

@ -24,7 +24,6 @@
cachix cachix
nil nil
niv niv
nixfmt
nixpkgs-fmt nixpkgs-fmt
# Node/JS # Node/JS

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;
};
}

View File

@ -1,4 +1,4 @@
{ pkgs, ... }: { pkgs, dotfiles, ... }:
{ {
users.users.walkah = { users.users.walkah = {
@ -10,4 +10,8 @@
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM8YMax7PGIrcPNIHkpuNRFgn3HJK6Wepm+ycZWO6jfR walkah@walkah-ipadpro11" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM8YMax7PGIrcPNIHkpuNRFgn3HJK6Wepm+ycZWO6jfR walkah@walkah-ipadpro11"
]; ];
}; };
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.walkah = import "${dotfiles}/home.nix";
} }