Commit fd3b3fd

HPCesia <me@hpcesia.com>
2026-03-20 06:16:18
refactor: init migration to denful/den
den
1 parent a92b086
modules/flake/gen-configuration/deploy-rs.nix
@@ -1,48 +0,0 @@
-{
-  lib,
-  config,
-  inputs,
-  self,
-  ...
-}: let
-  prefix = config.flake.meta.host.prefix;
-  hostsMeta = config.flake.meta.host.hosts;
-  collectHostsModules = modules:
-    lib.filterAttrs
-    (name: _:
-      (lib.hasPrefix prefix name)
-      && (hostsMeta.${lib.removePrefix prefix name}.deploy))
-    modules;
-in {
-  flake.deploy.nodes =
-    lib.pipe
-    (collectHostsModules config.flake.modules.nixos)
-    [
-      (lib.mapAttrs' (
-        name: value: {
-          name = lib.removePrefix prefix name;
-          inherit value;
-        }
-      ))
-      (lib.mapAttrs' (
-        name: _: {
-          inherit name;
-          value = {
-            hostname = name;
-            profiles.system = {
-              user = "root";
-              sshUser = "root";
-              path =
-                inputs.deploy-rs.lib.${hostsMeta.${name}.system}.activate.nixos
-                self.nixosConfigurations.${name};
-            };
-          };
-        }
-      ))
-    ];
-  flake.checks =
-    builtins.mapAttrs (
-      system: deployLib: deployLib.deployChecks self.deploy
-    )
-    inputs.deploy-rs.lib;
-}
modules/flake/gen-configuration/nixos.nix
@@ -1,47 +0,0 @@
-{
-  inputs,
-  lib,
-  config,
-  withSystem,
-  ...
-}: let
-  prefix = config.flake.meta.host.prefix;
-  collectHostsModules = modules:
-    lib.filterAttrs
-    (name: _: lib.hasPrefix prefix name)
-    modules;
-in {
-  flake.nixosConfigurations =
-    lib.pipe
-    (collectHostsModules config.flake.modules.nixos)
-    [
-      (lib.mapAttrs' (
-        name: value: {
-          name = lib.removePrefix prefix name;
-          inherit value;
-        }
-      ))
-      (lib.mapAttrs' (
-        name: module: {
-          inherit name;
-          value = withSystem config.flake.meta.host.hosts.${name}.system (
-            {system, ...}:
-              inputs.nixpkgs.lib.nixosSystem {
-                # Fix vaultix error: attribute 'inputs' missing
-                # This is an anti-pattern of Dendritic Pattern
-                # I don't like this, but I don't see another way
-                specialArgs = {inherit (inputs) self;};
-
-                modules = [
-                  module
-                  {
-                    networking.hostName = name;
-                    nixpkgs.system = system;
-                  }
-                ];
-              }
-          );
-        }
-      ))
-    ];
-}
modules/flake/dendritic.nix
@@ -0,0 +1,14 @@
+{
+  inputs,
+  den,
+  ...
+}: {
+  imports = [
+    inputs.flake-parts.flakeModules.modules
+    inputs.den.flakeModule
+  ];
+
+  den.schema.user.includes = [den._.mutual-provider];
+
+  flake.den = den; # for debugging
+}
modules/flake/flake-parts.nix
@@ -1,3 +0,0 @@
-{inputs, ...}: {
-  imports = [inputs.flake-parts.flakeModules.modules];
-}
modules/flake/inputs.nix
@@ -5,7 +5,7 @@
     description = "NixOS configuration of HPCesia.";
 
     inputs = {
-      deploy-rs.url = "github:serokell/deploy-rs";
+      den.url = "github:denful/den/v0.17.0";
       flake-file.url = "github:vic/flake-file";
       flake-parts.url = "github:hercules-ci/flake-parts";
       home-manager = {
modules/hosts/kevin/default.nix
@@ -1,10 +1,35 @@
-{config, ...}: {
+{
+  inputs,
+  config,
+  ...
+}: {
   #############################################################
   #
   #  Kevin - NixOS running on ThinkBook 16P G5 IRX
   #  My main computer, with I7-14650HX + RTX4060 Laptop GPU + 48GB memory, for daily use.
   #
   #############################################################
+  den.hosts.x86_64-linux.kevin = {
+    usage = "laptop";
+    pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOO9CyAqGo/WbJkncrt1a9jxS1E+hd550SC4A08I/l0/ root@kevin";
+    users.hpcesia.classes = ["homeManager"];
+    instantiate = {modules}:
+      inputs.nixpkgs.lib.nixosSystem {
+        inherit modules;
+
+        # Fix vaultix error: attribute 'inputs' missing
+        # This is an anti-pattern of Dendritic Pattern
+        # I don't like this, but I don't see another way
+        specialArgs = {inherit (inputs) self;};
+      };
+  };
+
+  den.aspects.kevin.nixos = {
+    imports = [
+      config.flake.modules.nixos."hosts/kevin"
+    ];
+  };
+
   flake.meta.host.hosts.kevin = {
     system = "x86_64-linux";
     hostPubKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOO9CyAqGo/WbJkncrt1a9jxS1E+hd550SC4A08I/l0/ root@kevin";
modules/hosts/pardofelis/default.nix
@@ -1,10 +1,35 @@
-{config, ...}: {
+{
+  inputs,
+  config,
+  ...
+}: {
   #############################################################
   #
   #  Pardofelis - NixOS running on a 2C4G VPS
   #  My main server hosted by Yecaoyun.
   #
   #############################################################
+  den.hosts.x86_64-linux.pardofelis = {
+    usage = "server";
+    sshPorts = [23930];
+    pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEuT/WkeA7btTeATmWJ2O9f/A6FI0Gl/1KjPGfHbWD5C root@pardofelis";
+    users.hpcesia = {};
+    instantiate = {modules}:
+      inputs.nixpkgs.lib.nixosSystem {
+        inherit modules;
+
+        # Fix vaultix error: attribute 'inputs' missing
+        # This is an anti-pattern of Dendritic Pattern
+        # I don't like this, but I don't see another way
+        specialArgs = {inherit (inputs) self;};
+      };
+  };
+
+  den.aspects.pardofelis.nixos = {
+    imports = [
+      config.flake.modules.nixos."hosts/pardofelis"
+    ];
+  };
 
   flake.meta.host.hosts.pardofelis = {
     system = "x86_64-linux";
modules/hosts/default.nix
@@ -1,4 +1,6 @@
-{
+{den, ...}: let
+  inherit (den.lib) __findFile;
+in {
   flake-file.inputs = {
     disko.url = "github:nix-community/disko/v1.11.0";
     nix-cachyos-kernel = {
@@ -7,4 +9,7 @@
     };
     nixos-hardware.url = "github:NixOS/nixos-hardware/master";
   };
+  den.default.includes = [
+    <den/hostname>
+  ];
 }
modules/hosts/deploy.nix
@@ -0,0 +1,30 @@
+{
+  inputs,
+  self,
+  config,
+  lib,
+  ...
+}: let
+  nodeDeploy = host: {
+    inherit (host) name;
+    value = {
+      hostname = host.name;
+      profiles.system = {
+        user = "root";
+        sshUser = "root";
+        path =
+          inputs.deploy-rs.lib.${host.system}.activate.nixos
+          self.nixosConfigurations.${host.name};
+      };
+    };
+  };
+  nodesDeployable = lib.filter (host: host.deployable) (builtins.attrValues config.den.hosts.x86_64-linux);
+in {
+  flake-file.inputs.deploy-rs.url = "github:serokell/deploy-rs";
+  flake.deploy.nodes = builtins.listToAttrs (map nodeDeploy nodesDeployable);
+  flake.checks =
+    builtins.mapAttrs (
+      system: deployLib: deployLib.deployChecks self.deploy
+    )
+    inputs.deploy-rs.lib;
+}
modules/hosts/schema.nix
@@ -0,0 +1,26 @@
+{
+  den.schema.host = {
+    host,
+    lib,
+    ...
+  }: {
+    options.usage = lib.mkOption {
+      type = lib.types.enum ["server" "dev-server" "desktop" "laptop"];
+      description = "Usage of the host.";
+    };
+    options.deployable = lib.mkOption {
+      type = lib.types.bool;
+      description = "Whether the host is deployable using deploy-rs.";
+      default = host.usage == "server" || host.usage == "dev-server";
+    };
+    options.pubkey = lib.mkOption {
+      type = lib.types.str;
+      description = "Public SSH key for the host.";
+    };
+    options.sshPorts = lib.mkOption {
+      type = lib.types.listOf lib.types.port;
+      description = "List of ports to open for SSH access.";
+      default = [22];
+    };
+  };
+}
flake.lock
@@ -153,6 +153,22 @@
         "type": "github"
       }
     },
+    "den": {
+      "locked": {
+        "lastModified": 1779284890,
+        "narHash": "sha256-M13hhd4qXKrAyqfTFFP8ov1dNu6acHyeQdUj/V5dj3g=",
+        "owner": "denful",
+        "repo": "den",
+        "rev": "8f1a59448043677ac8bc7854348c1b8ee6889c0b",
+        "type": "github"
+      },
+      "original": {
+        "owner": "denful",
+        "ref": "v0.17.0",
+        "repo": "den",
+        "type": "github"
+      }
+    },
     "deploy-rs": {
       "inputs": {
         "flake-compat": "flake-compat_2",
@@ -1025,6 +1041,7 @@
     "root": {
       "inputs": {
         "aagl-gtk-on-nix": "aagl-gtk-on-nix",
+        "den": "den",
         "deploy-rs": "deploy-rs",
         "disko": "disko",
         "distro-grub-themes": "distro-grub-themes",
flake.nix
@@ -10,6 +10,7 @@
       url = "github:ezKEa/aagl-gtk-on-nix";
       inputs.nixpkgs.follows = "nixpkgs";
     };
+    den.url = "github:denful/den/v0.17.0";
     deploy-rs.url = "github:serokell/deploy-rs";
     disko.url = "github:nix-community/disko/v1.11.0";
     distro-grub-themes.url = "github:AdisonCavani/distro-grub-themes";