diff --git a/config/common/default.nix b/config/common/default.nix index 9e95690..d5ad162 100644 --- a/config/common/default.nix +++ b/config/common/default.nix @@ -28,12 +28,13 @@ with lib; { fish.enable = true; }; - deployment = { - tags = [ "all" ]; - targetHost = mkDefault config.networking.fqdn; - targetPort = mkDefault 22; - targetUser = mkDefault null; - }; + kyouma.tags = [ "all" ]; +# deployment = { +# tags = [ "all" ]; +# targetHost = mkDefault config.networking.fqdn; +# targetPort = mkDefault 22; +# targetUser = mkDefault null; +# }; security.dhparams.defaultBitSize = 4096; diff --git a/config/hosts/base/configuration.nix b/config/hosts/_minimal/configuration.nix similarity index 100% rename from config/hosts/base/configuration.nix rename to config/hosts/_minimal/configuration.nix diff --git a/flake.nix b/flake.nix index 44dbd0f..76d1ecd 100644 --- a/flake.nix +++ b/flake.nix @@ -48,41 +48,32 @@ builders = "ssh://build@seras.kyouma.net x86_64-linux,aarch64-linux - 40 5 nixos-test,benchmark,big-parallel,kvm"; }; - outputs = { self, nixpkgs, flake-utils, ... }@inputs: { - colmena = let - hosts = builtins.filter (name: name != "base") ( - builtins.attrNames (nixpkgs.lib.filterAttrs (name: type: type == "directory") ( - builtins.readDir ./config/hosts))); - hostCfg = hostname: { - imports = [ - (./config/hosts/${hostname}/configuration.nix) - ({ ... }: { - nixpkgs.overlays = [ self.overlays.kyouma ]; - }) - ]; - }; - in { + outputs = { self, nixpkgs, flake-utils, ... }@inputs: let + shinyflakes = import ./lib/shinyflakes inputs; + in { + hosts = shinyflakes.mapHosts { + lain = { system = "aarch64-linux"; }; + }; + + colmena = shinyflakes.mapColmenaCfg { meta = { allowApplyAll = false; machinesFile = ./config/files/builders; nixpkgs = nixpkgs.legacyPackages.x86_64-linux; - nodeNixpkgs = { - lain = nixpkgs.legacyPackages.aarch64-linux; - }; specialArgs = { inherit inputs; }; }; - } // nixpkgs.lib.attrsets.genAttrs hosts (hostCfg); + }; - nixosConfigurations = { - ryuuko = nixpkgs.lib.nixosSystem { + nixosConfigurations = shinyflakes.mapNixosCfg { + ryuuko-minimal = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; specialArgs = { inherit inputs; }; modules = [ - ./config/hosts/base/configuration.nix + ./config/hosts/_minimal/configuration.nix ./config/hosts/ryuuko/disko.nix ]; }; - lain = nixpkgs.lib.nixosSystem { + lain-minimal = nixpkgs.lib.nixosSystem { system = "aarch64-linux"; specialArgs = { inherit inputs; }; modules = [ @@ -90,7 +81,8 @@ ]; }; }; - images.lain = self.nixosConfigurations.lain.config.system.build.sdImage; + images.lain = self.nixosConfigurations.lain-minimal.config.system.build.sdImage; + overlays = { kyouma = import ./pkgs/overlay.nix; default = self.overlays.kyouma; diff --git a/lib/shinyflakes/default.nix b/lib/shinyflakes/default.nix new file mode 100644 index 0000000..5b86dda --- /dev/null +++ b/lib/shinyflakes/default.nix @@ -0,0 +1,44 @@ +{ self, nixpkgs, ... }@inputs: let + readHostDir = builtins.filter (name: name != "_minimal") ( + builtins.attrNames (nixpkgs.lib.filterAttrs (name: type: type == "directory") ( + builtins.readDir ../../config/hosts))); + + filterMinimal = attr: nixpkgs.lib.filterAttrs (name: v: !(nixpkgs.lib.hasSuffix "-minimal" name)) attr; + + genColmenaCfg = name: host: { + deployment = { + allowLocalDeployment = builtins.any (hostName: hostName == name) [ "ryuuko" ]; + targetHost = nixpkgs.lib.findFirst (el: el != null) host.config.networking.fqdn [ host.config.kyouma.deployment.targetHost ]; + targetPort = 22; + # change back to null after switching ryuuko to nixos + targetUser = "emily"; + tags = host.config.kyouma.deployment.tags; + }; + imports = host._module.args.modules; + nixpkgs.system = host.config.nixpkgs.system; + }; + + genNixosCfg = { + hostname, + system ? "x86_64-linux" + }: + nixpkgs.lib.nixosSystem { + system = system; + specialArgs = { inherit inputs; }; + modules = [ + ../../config/hosts/${hostname}/configuration.nix + ({ ... }: { + nixpkgs.overlays = [ self.overlays.kyouma ]; + }) + ]; + }; +in { + mapHosts = hostCfg: nixpkgs.lib.recursiveUpdate ( + nixpkgs.lib.genAttrs readHostDir (host: { hostname = host; })) hostCfg; + + mapColmenaCfg = extraColmenaCfg: nixpkgs.lib.recursiveUpdate (builtins.mapAttrs (genColmenaCfg) ( + filterMinimal self.nixosConfigurations)) extraColmenaCfg; + + mapNixosCfg = extraNixosCfg: nixpkgs.lib.recursiveUpdate (builtins.mapAttrs (name: value: + genNixosCfg value) self.hosts) extraNixosCfg; +} diff --git a/modules/default.nix b/modules/default.nix index 2771d99..14d4e70 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,6 +1,7 @@ { ... }: { imports = [ - ./vhost ./machine-type + ./deployment + ./vhost ]; } diff --git a/modules/deployment/default.nix b/modules/deployment/default.nix new file mode 100644 index 0000000..eef4b82 --- /dev/null +++ b/modules/deployment/default.nix @@ -0,0 +1,14 @@ +{ lib, ... }: with lib; { + options.kyouma.deployment = { + tags = mkOption { + type = types.listOf types.str; + default = []; + description = "colmena deployment tags"; + }; + targetHost = mkOption { + type = types.nullOr types.str; + default = null; + description = "colmena target host override"; + }; + }; +}