Split modules and profiles

This commit is contained in:
Alexander Bantyev 2021-06-24 11:41:17 +03:00
parent 7efadcdd7f
commit 7db6eb7179
Signed by: balsoft
GPG Key ID: E081FF12ADCB4AD5
89 changed files with 81 additions and 74 deletions

101
flake.nix
View File

@ -59,9 +59,7 @@
flake = false;
};
nix-direnv = {
url = "github:nix-community/nix-direnv";
};
nix-direnv = { url = "github:nix-community/nix-direnv"; };
nheko = {
url = "github:balsoft/nheko/allow-edits-of-pending-messages";
@ -69,53 +67,72 @@
};
};
outputs = { nixpkgs, nix, self, deploy-rs, ... }@inputs: {
nixosModules = import ./modules;
outputs = { nixpkgs, nix, self, deploy-rs, ... }@inputs:
let
findModules = dir:
builtins.concatLists (builtins.attrValues (builtins.mapAttrs
(name: type:
if type == "regular" then
[{
name = builtins.elemAt (builtins.match "(.*)\\.nix" name) 0;
value = dir + "/${name}";
}]
else if (builtins.readDir (dir + "/${name}"))
? "default.nix" then [{
inherit name;
value = dir + "/${name}";
}] else
findModules (dir + "/${name}")) (builtins.readDir dir)));
in {
nixosModules = builtins.listToAttrs (findModules ./modules);
nixosProfiles = import ./profiles;
nixosProfiles = builtins.listToAttrs (findModules ./profiles);
nixosConfigurations = with nixpkgs.lib;
let
hosts = builtins.attrNames (builtins.readDir ./machines);
mkHost = name:
nixosSystem {
system = builtins.readFile (./machines + "/${name}/system");
modules = [ (import (./machines + "/${name}")) { device = name; } ];
specialArgs = { inherit inputs; };
};
in genAttrs hosts mkHost;
nixosRoles = import ./roles;
legacyPackages.x86_64-linux =
(builtins.head (builtins.attrValues self.nixosConfigurations)).pkgs;
nixosConfigurations = with nixpkgs.lib;
let
hosts = builtins.attrNames (builtins.readDir ./machines);
mkHost = name:
nixosSystem {
system = builtins.readFile (./machines + "/${name}/system");
modules =
[ (import (./machines + "/${name}")) { device = name; } ];
specialArgs = { inherit inputs; };
};
in genAttrs hosts mkHost;
defaultApp = deploy-rs.defaultApp;
legacyPackages.x86_64-linux =
(builtins.head (builtins.attrValues self.nixosConfigurations)).pkgs;
devShell.x86_64-linux = with nixpkgs.legacyPackages.x86_64-linux;
mkShell {
buildInputs = [
nix.defaultPackage.x86_64-linux
deploy-rs.defaultPackage.x86_64-linux
nixfmt
];
};
defaultApp = deploy-rs.defaultApp;
deploy = {
user = "root";
nodes = (builtins.mapAttrs (_: machine: {
hostname = machine.config.networking.hostName;
profiles.system = {
user = "balsoft";
path = deploy-rs.lib.x86_64-linux.activate.noop
machine.config.system.build.toplevel;
devShell.x86_64-linux = with nixpkgs.legacyPackages.x86_64-linux;
mkShell {
buildInputs = [
nix.defaultPackage.x86_64-linux
deploy-rs.defaultPackage.x86_64-linux
nixfmt
];
};
}) self.nixosConfigurations) // {
T420-Laptop = {
hostname =
self.nixosConfigurations.T420-Laptop.config.networking.hostName;
profiles.system.path = deploy-rs.lib.x86_64-linux.activate.nixos
self.nixosConfigurations.T420-Laptop;
deploy = {
user = "root";
nodes = (builtins.mapAttrs (_: machine: {
hostname = machine.config.networking.hostName;
profiles.system = {
user = "balsoft";
path = deploy-rs.lib.x86_64-linux.activate.noop
machine.config.system.build.toplevel;
};
}) self.nixosConfigurations) // {
T420-Laptop = {
hostname =
self.nixosConfigurations.T420-Laptop.config.networking.hostName;
profiles.system.path = deploy-rs.lib.x86_64-linux.activate.nixos
self.nixosConfigurations.T420-Laptop;
};
};
};
};
};
}

View File

@ -1,9 +1,9 @@
{ config, inputs, ... }: {
imports = [
./hardware-configuration.nix
inputs.self.nixosProfiles.desktop
inputs.self.nixosModules.print-scan
inputs.self.nixosModules.aws
inputs.self.nixosRoles.desktop
inputs.self.nixosProfiles.print-scan
inputs.self.nixosProfiles.aws
];
deviceSpecific.devInfo = {
cpu = {

View File

@ -1,7 +1,7 @@
{ inputs, ... }: {
imports = with inputs.self.nixosModules; [
./hardware-configuration.nix
inputs.self.nixosProfiles.server
inputs.self.nixosRoles.server
mailserver
];

View File

@ -1,7 +1,7 @@
{ inputs, ... }: {
imports = with inputs.self.nixosModules; [
./hardware-configuration.nix
inputs.self.nixosProfiles.base
inputs.self.nixosRoles.base
gitea
# jitsi
mailserver

View File

@ -1,5 +1,5 @@
{ inputs, ... }: {
imports = [ ./hardware-configuration.nix inputs.self.nixosProfiles.desktop ];
imports = [ ./hardware-configuration.nix inputs.self.nixosRoles.desktop ];
deviceSpecific.devInfo = {
cpu = {
vendor = "intel";

View File

@ -1,7 +1,7 @@
{ inputs, lib, config, pkgs, ... }: {
imports = [
./hardware-configuration.nix
inputs.self.nixosProfiles.desktop
inputs.self.nixosRoles.desktop
];
deviceSpecific.devInfo = {
cpu = {

View File

@ -1,7 +1,7 @@
{ modulesPath, lib, inputs, pkgs, ... }: {
imports = with inputs.self.nixosModules; [
"${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
inputs.self.nixosProfiles.base
inputs.self.nixosRoles.base
themes
fonts
cage

View File

@ -1,17 +0,0 @@
let
findModules = dir:
builtins.concatLists (builtins.attrValues (builtins.mapAttrs (name: type:
if type == "regular" then
(if name == "default.nix" then
[ ]
else [{
name = builtins.elemAt (builtins.match "(.*)\\.nix" name) 0;
value = dir + "/${name}";
}])
else if (builtins.readDir (dir + "/${name}")) ? "default.nix" then [{
inherit name;
value = dir + "/${name}";
}] else
findModules (dir + "/${name}")) (builtins.readDir dir)));
in builtins.listToAttrs (findModules ./.)

View File

@ -1,15 +1,19 @@
{ inputs, ... }: {
imports = with inputs.self.nixosModules; [
imports = with inputs.self.nixosModules; with inputs.self.nixosProfiles; [
inputs.home-manager.nixosModules.home-manager
# MODULES
applications
boot
secrets
secrets-envsubst
persist
# PROFILES
autoRun
xdg
boot
devices
git
gpg
@ -18,7 +22,6 @@
network
nix
overlay
persist
security
ssh
zsh

View File

@ -1,11 +1,15 @@
{ inputs, ... }: {
imports = with inputs.self.nixosModules; [
imports = with inputs.self.nixosModules; with inputs.self.nixosProfiles; [
./base.nix
applications-setup
ezwg
hardware
# MODULES
themes
ezwg
# PROFILES
applications-setup
hardware
virtualisation
alacritty