summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parts/default.nix5
-rw-r--r--parts/deploy.nix34
-rw-r--r--parts/lib/configs.nix56
-rw-r--r--parts/lib/default.nix6
-rw-r--r--parts/lib/utils.nix36
5 files changed, 101 insertions, 36 deletions
diff --git a/parts/default.nix b/parts/default.nix
index dc01879..3626f4a 100644
--- a/parts/default.nix
+++ b/parts/default.nix
@@ -1,12 +1,11 @@
-{inputs, ...}: {
+_: {
imports = [
./deploy.nix
./dev.nix
+ ./lib
./overlays
];
- _module.args.myLib = inputs.getchoo.lib;
-
systems = [
"x86_64-linux"
"aarch64-linux"
diff --git a/parts/deploy.nix b/parts/deploy.nix
index bebf25c..9bd98b2 100644
--- a/parts/deploy.nix
+++ b/parts/deploy.nix
@@ -1,8 +1,6 @@
{
self,
- inputs,
lib,
- withSystem,
...
}: let
systems = ["atlas" "p-body"];
@@ -11,39 +9,9 @@
lib.filterAttrs
(n: _: builtins.elem n systems)
self.nixosConfigurations;
-
- deployPkgs = import inputs.nixpkgs rec {
- system = "x86_64-linux";
- overlays = [
- inputs.deploy-rs.overlay
- (_: prev: {
- deploy-rs = {
- inherit (withSystem system (p: p.pkgs)) deploy-rs;
- inherit (prev.deploy-rs) lib;
- };
- })
- ];
- };
-
- mkNodes = hosts: let
- inherit (builtins) attrNames listToAttrs map;
- vals =
- map (name: let
- system = self.nixosConfigurations.${name};
- in {
- inherit name;
- value = {
- sshUser = "root";
- hostname = system.config.networking.hostName;
- profiles.system.path = deployPkgs.deploy-rs.lib.activate.nixos system;
- };
- })
- (attrNames hosts);
- in
- listToAttrs vals;
in {
flake.deploy = {
remoteBuild = true;
- nodes = mkNodes deployedSystems;
+ nodes = self.lib.utils.mkDeployNodes deployedSystems;
};
}
diff --git a/parts/lib/configs.nix b/parts/lib/configs.nix
new file mode 100644
index 0000000..31524e2
--- /dev/null
+++ b/parts/lib/configs.nix
@@ -0,0 +1,56 @@
+{inputs, ...}: let
+ inherit (builtins) attrNames elemAt map;
+ inherit (inputs.nixpkgs.lib) flatten genAttrs optional splitString;
+
+ archs = ["x86_64" "aarch64"];
+ os' = ["linux" "darwin"];
+ mkSystems = systems: flatten (map (sys: map (arch: ["${arch}-${sys}" "${arch}-${sys}"]) archs) systems);
+ systems = mkSystems os';
+
+ mkSystemCfg = name: {
+ profile,
+ modules ? profile.modules,
+ system ? profile.system,
+ specialArgs ? profile.specialArgs,
+ }:
+ profile.builder {
+ inherit specialArgs system;
+ modules =
+ [../../hosts/${name}]
+ ++ (
+ if modules == profile.modules
+ then modules
+ else modules ++ profile.modules
+ );
+ };
+in {
+ inherit mkSystemCfg;
+ mapSystems = builtins.mapAttrs mkSystemCfg;
+
+ genHMCfgs = users: let
+ names = flatten (map (user: map (system: "${user}@${system}") systems) (attrNames users));
+ in
+ genAttrs names (name: let
+ getPart = elemAt (splitString "@" name);
+ username = getPart 0;
+ system = getPart 1;
+ in
+ inputs.home-manager.lib.homeManagerConfiguration rec {
+ pkgs = import (users.${username}.nixpkgs or inputs.nixpkgs) (
+ {inherit system;} // users.${username}.nixpkgsArgs or {}
+ );
+
+ extraSpecialArgs = users.${username}.extraSpecialArgs or inputs;
+
+ modules =
+ [
+ {
+ _module.args.osConfig = {};
+ programs.home-manager.enable = true;
+ }
+ ../../users/${username}/home.nix
+ ]
+ ++ optional pkgs.stdenv.isDarwin ../../users/${username}/darwin.nix
+ ++ users.${username}.modules or [];
+ });
+}
diff --git a/parts/lib/default.nix b/parts/lib/default.nix
new file mode 100644
index 0000000..bdc485c
--- /dev/null
+++ b/parts/lib/default.nix
@@ -0,0 +1,6 @@
+{withSystem, ...} @ args: {
+ flake.lib = {
+ configs = import ./configs.nix args;
+ utils = import ./utils.nix ({inherit withSystem;} // args);
+ };
+}
diff --git a/parts/lib/utils.nix b/parts/lib/utils.nix
new file mode 100644
index 0000000..f830b1c
--- /dev/null
+++ b/parts/lib/utils.nix
@@ -0,0 +1,36 @@
+{
+ self,
+ inputs,
+ withSystem,
+ ...
+}: let
+ deployPkgs = import inputs.nixpkgs rec {
+ system = "x86_64-linux";
+ overlays = [
+ inputs.deploy-rs.overlay
+ (_: prev: {
+ deploy-rs = {
+ inherit (withSystem system (p: p.pkgs)) deploy-rs;
+ inherit (prev.deploy-rs) lib;
+ };
+ })
+ ];
+ };
+in {
+ mkDeployNodes = hosts: let
+ inherit (builtins) attrNames listToAttrs map;
+ vals =
+ map (name: let
+ system = self.nixosConfigurations.${name};
+ in {
+ inherit name;
+ value = {
+ sshUser = "root";
+ hostname = system.config.networking.hostName;
+ profiles.system.path = deployPkgs.deploy-rs.lib.activate.nixos system;
+ };
+ })
+ (attrNames hosts);
+ in
+ listToAttrs vals;
+}