minor flake refactor

This commit is contained in:
emily 2024-04-27 19:34:17 +02:00
parent 0a4b7c4458
commit e4fd5ee179
Signed by: emily
GPG key ID: F6F4C66207FCF995
6 changed files with 82 additions and 30 deletions

View file

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

View file

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

View file

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

View file

@ -1,6 +1,7 @@
{ ... }: {
imports = [
./vhost
./machine-type
./deployment
./vhost
];
}

View file

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