Test host specific nixpkgs

This commit is contained in:
yuri 2023-07-30 01:38:31 +02:00
parent 361f5ef709
commit 29fe1fbeca
4 changed files with 106 additions and 96 deletions

View file

@ -38,11 +38,27 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1690538549, "lastModified": 1690630041,
"narHash": "sha256-FfScFHxidupVGPw9BrQOHz/SoFLRjoNmVC5ymS+g8xU=", "narHash": "sha256-gbnvqm5goS9DSKAqGFpq3398aOpwejmq4qWikqmQyRo=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "de5ca86149b0c4ff8bf69782cd25896fff0254e1", "rev": "d57e8c535d4cbb07f441c30988ce52eec69db7a8",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.05-small",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1690628621,
"narHash": "sha256-fHmW03fQziNt1+tt/Goa0lwObsR8kY8auNEWnv92Sfw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9508c7104d697af158ebc719586d64eb7b64c0d7",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -55,7 +71,8 @@
"root": { "root": {
"inputs": { "inputs": {
"nixos-generators": "nixos-generators", "nixos-generators": "nixos-generators",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable"
} }
} }
}, },

View file

@ -1,90 +1,35 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05-small";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable-small";
nixos-generators = { nixos-generators = {
url = "github:nix-community/nixos-generators"; url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
}; };
outputs = { self, nixpkgs, nixos-generators, ... }@inputs: let outputs = { self, nixpkgs, nixpkgs-unstable, nixos-generators, ... }@inputs: let
hosts = import ./hosts.nix inputs;
helper = (import ./helper.nix) inputs; helper = (import ./helper.nix) inputs;
in { in {
hosts = {
hydra = {
site = "vs";
};
iperf = {
site = "vs";
};
jackett = {
site = "vs";
};
nitter = {
site = "vs";
};
nixos-coturn = {
site = "vs";
};
tor-relay = {
site = "vs";
};
web-public-2 = {
site = "vs";
};
};
generateColmenaHost = name: host: {
deployment = {
targetHost = "${name}.${host.site}.grzb.de";
targetUser = "colmena-deploy";
};
imports = [
./configuration/common
./configuration/proxmox-vm
./configuration/proxmox-vm/hardware-configuration.nix
./hosts/${name}
] ++ nixpkgs.lib.optional (builtins.pathExists ./hosts/${name}/secrets.nix) ./hosts/${name}/secrets.nix;
};
colmena = { colmena = {
meta = { meta = {
nixpkgs = import nixpkgs { # Set the default pkgs, which is pointless in this case,
system = "x86_64-linux"; # because nodeNixpkgs is overriding it anyway and a default value is generated.
}; # It is still needed for colmena to run.
}; nixpkgs = nixpkgs.legacyPackages."x86_64-linux";
} // builtins.mapAttrs (self.generateColmenaHost) self.hosts;
nixosConfigurations = nixpkgs.lib.mapAttrs (name: config: let # Specify nixpkgs to use for each host.
nodeNixpkgs = self.outputs.colmena.meta.nodeNixpkgs.${name} or self.outputs.colmena.meta.nixpkgs; # The default is "nixpkgs" for "x86_64-linux" systems,
nodeNixos = import (nodeNixpkgs.path + "/nixos/lib/eval-config.nix"); # but it is overridden by the host-specific "hostNixpkgs" and "system" attributes.
in nodeNixos { nodeNixpkgs = builtins.mapAttrs (name: host: host.pkgs) hosts;
modules = [ };
#self.outputs.colmena.defaults } // builtins.mapAttrs (helper.generateColmenaHost) hosts;
config
#inputs.colmena.nixosModules.deploymentOptions
{
_module.args.name = nixpkgs.lib.mkForce name;
_module.args.nodes = self.outputs.nixosConfigurations;
#nixpkgs.overlays = nixpkgs.lib.attrValues self.overlays;
}
];
inherit (nodeNixpkgs) system;
}
) (builtins.removeAttrs self.outputs.colmena ["meta" "defaults"]);
hydraJobs = { hydraJobs = {
nixosConfigurations = nixpkgs.lib.mapAttrs (_: config: config.config.system.build.toplevel) self.outputs.nixosConfigurations; nixConfigurations = builtins.mapAttrs (helper.generateNixConfiguration) hosts;
}; };
/*
nixosConfigurations = (builtins.mapAttrs (helper.mapToNixosConfigurations) self.hosts);
hydraJobs = {
nixConfigurations = helper.buildHosts self.nixosConfigurations;
};
*/
# Generate a base VM image for Proxmox with `nix build .#base-proxmox` # Generate a base VM image for Proxmox with `nix build .#base-proxmox`
packages.x86_64-linux = { packages.x86_64-linux = {
base-proxmox = nixos-generators.nixosGenerate { base-proxmox = nixos-generators.nixosGenerate {

View file

@ -1,25 +1,26 @@
{ nixpkgs, ... }@inputs: { nixpkgs, ... }:
rec { {
generateNixosSystem = name: { generateColmenaHost = name: {
system ? "x86_64-linux", site,
group ? null, modules,
modules ? [], ...
site }: {
}: let deployment = {
localNixpkgs = nixpkgs.lib.attrByPath [ "nixpkgs-${name}" ] nixpkgs inputs; targetHost = "${name}.${site}.grzb.de";
in localNixpkgs.lib.nixosSystem { targetUser = "colmena-deploy";
system = system;
modules = modules ++ [
./configuration/common
./configuration/proxmox-vm
./configuration/proxmox-vm/hardware-configuration.nix
./hosts/${name}
];
}; };
mapToNixosConfigurations = name: host: generateNixosSystem name host; # Set imports and optionally import colmena secrets configuration
imports = modules ++ nixpkgs.lib.optional (builtins.pathExists ./hosts/${name}/secrets.nix) ./hosts/${name}/secrets.nix;
};
filterUnderscore = hosts: (nixpkgs.lib.filterAttrs (name: host: (builtins.substring 0 1 name) != "_") hosts); generateNixConfiguration = name: {
hostNixpkgs,
buildHosts = hosts: builtins.mapAttrs (name: host: host.config.system.build.toplevel) (filterUnderscore hosts); system,
modules,
...
}:
(nixpkgs.lib.filterAttrs (name: host: (builtins.substring 0 1 name) != "_") (hostNixpkgs.lib.nixosSystem {
inherit system modules;
})).config.system.build.toplevel;
} }

47
hosts.nix Normal file
View file

@ -0,0 +1,47 @@
{ nixpkgs, nixpkgs-unstable, ... }:
let
environments = {
"proxmox" = [
./configuration/proxmox-vm
./configuration/proxmox-vm/hardware-configuration.nix
];
};
generateDefaults = hosts: builtins.mapAttrs (name: {
hostNixpkgs ? nixpkgs,
system ? "x86_64-linux",
pkgs ? hostNixpkgs.legacyPackages.${system},
environment ? "proxmox",
site
}: {
inherit hostNixpkgs system pkgs environment site;
modules = [
./configuration/common
./hosts/${name}
] ++ (if environments ? ${environment} then environments.${environment} else []);
}) hosts;
in
generateDefaults {
hydra = {
hostNixpkgs = nixpkgs-unstable;
site = "vs";
};
iperf = {
site = "vs";
};
jackett = {
site = "vs";
};
nitter = {
site = "vs";
};
nixos-coturn = {
site = "vs";
};
tor-relay = {
site = "vs";
};
web-public-2 = {
hostNixpkgs = nixpkgs-unstable;
site = "vs";
};
}