un-nixops

This commit is contained in:
Kiara Grouwstra 2025-08-09 23:31:25 +02:00
parent 4bce4de732
commit 8c1978efea
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
7 changed files with 49 additions and 118 deletions

View file

@ -54,11 +54,8 @@ in
system.extraDependencies =
[
inputs.nixops4
inputs.nixops4-nixos
inputs.nixpkgs
sources.nixpkgs
sources.flake-parts
sources.flake-inputs
sources.git-hooks

View file

@ -21,25 +21,17 @@ let
optionalString
;
inherit (hostPkgs)
runCommandNoCC
writeText
system
;
forConcat = xs: f: concatStringsSep "\n" (map f xs);
## We will need to override some inputs by the empty flake, so we make one.
emptyFlake = runCommandNoCC "empty-flake" { } ''
mkdir $out
echo "{ outputs = { self }: {}; }" > $out/flake.nix
'';
in
{
_class = "nixosTest";
imports = [
./sharedOptions.nix
../common/sharedOptions.nix
];
options = {
@ -67,16 +59,15 @@ in
config = {
sourceFileset = fileset.unions [
# NOTE: not the flake itself; it will be overridden.
../../../mkFlake.nix
../../../flake.lock
../../../npins
../../data-model.nix
../../function.nix
./sharedOptions.nix
./targetNode.nix
./targetResource.nix
(config.pathToCwd + "/flake-under-test.nix")
../common/sharedOptions.nix
../common/targetNode.nix
../common/targetResource.nix
];
acmeNodeIP = config.nodes.acme.networking.primaryIPAddress;
@ -84,7 +75,7 @@ in
nodes =
{
deployer = {
imports = [ ./deployerNode.nix ];
imports = [ ../common/deployerNode.nix ];
_module.args = { inherit inputs sources; };
enableAcme = config.enableAcme;
acmeNodeIP = config.nodes.acme.networking.primaryIPAddress;
@ -111,7 +102,7 @@ in
//
genAttrs config.targetMachines (_: {
imports = [ ./targetNode.nix ];
imports = [ ../common/targetNode.nix ];
_module.args = { inherit inputs sources; };
enableAcme = config.enableAcme;
acmeNodeIP = if config.enableAcme then config.nodes.acme.networking.primaryIPAddress else null;
@ -163,31 +154,8 @@ in
deployer.succeed(f"echo '{host_key}' > ${config.pathFromRoot}/${tm}_host_key.pub")
'')}
## NOTE: This is super slow. It could probably be optimised in Nix, for
## instance by allowing to grab things directly from the host's store.
##
## NOTE: We use the repository as-is (cf `src` above), overriding only
## `flake.nix` by our `flake-under-test.nix`. We also override the flake
## lock file to use locally available inputs, as we cannot download them.
##
with subtest("Override the flake and its lock"):
deployer.succeed("cp ${config.pathFromRoot}/flake-under-test.nix flake.nix")
deployer.succeed("""
nix flake lock --extra-experimental-features 'flakes nix-command' \
--offline -v \
--override-input nixops4 ${inputs.nixops4.packages.${system}.flake-in-a-bottle} \
\
--override-input nixops4-nixos ${inputs.nixops4-nixos} \
--override-input nixops4-nixos/flake-parts ${inputs.nixops4-nixos.inputs.flake-parts} \
--override-input nixops4-nixos/flake-parts/nixpkgs-lib ${inputs.nixops4-nixos.inputs.flake-parts.inputs.nixpkgs-lib} \
--override-input nixops4-nixos/nixops4-nixos ${emptyFlake} \
--override-input nixops4-nixos/nixpkgs ${inputs.nixops4-nixos.inputs.nixpkgs} \
--override-input nixops4-nixos/nixops4 ${
inputs.nixops4-nixos.inputs.nixops4.packages.${system}.flake-in-a-bottle
} \
--override-input nixops4-nixos/git-hooks-nix ${emptyFlake} \
;
""")
# with subtest("Override the flake and its lock"):
# deployer.succeed("cp ${config.pathFromRoot}/flake-under-test.nix flake.nix")
${optionalString config.enableAcme ''
with subtest("Set up handmade DNS"):

View file

@ -6,7 +6,9 @@
runNixOSTest {
imports = [
../common/nixosTest.nix
../../data-model.nix
../../function.nix
./common-nixosTest.nix
./nixosTest.nix
];
_module.args = { inherit inputs sources; };

View file

@ -1,36 +1,40 @@
{
inputs,
sources,
# sources,
lib,
providers,
# providers,
...
}:
let
inherit (import ./constants.nix) targetMachines pathToRoot pathFromRoot;
in
{
providers = {
inherit (inputs.nixops4.modules.nixops4Provider) local;
# inherit (import ./constants.nix) targetMachines pathToRoot pathFromRoot;
eval =
module:
(lib.evalModules {
specialArgs = {
inherit inputs;
};
resources = lib.genAttrs targetMachines (nodeName: {
type = providers.local.exec;
imports = [
inputs.nixops4-nixos.modules.nixops4Resource.nixos
../common/targetResource.nix
modules = [
module
../../data-model.nix
];
_module.args = { inherit inputs sources; };
inherit nodeName pathToRoot pathFromRoot;
nixos.module =
{ pkgs, ... }:
}).config;
fediversity = eval (
{ ... }:
{
environment.systemPackages = [ pkgs.${nodeName} ];
config = {
environments.single-nixos-vm =
{ ... }:
{
implementation = requests: {
input = requests;
output = { };
};
});
};
};
}
);
in
fediversity.environments.single-nixos-vm.deployment {
enable = true;
}

View file

@ -1,22 +0,0 @@
{
inputs = {
nixops4.follows = "nixops4-nixos/nixops4";
nixops4-nixos.url = "github:nixops4/nixops4-nixos";
};
outputs =
inputs:
import ./mkFlake.nix inputs (
{ inputs, sources, ... }:
{
imports = [
inputs.nixops4.modules.flake.default
];
nixops4Deployments.check-deployment-basic = {
imports = [ ./deployment/check/basic/deployment.nix ];
_module.args = { inherit inputs sources; };
};
}
);
}

View file

@ -1,4 +1,7 @@
{ inputs, lib, ... }:
{
lib,
...
}:
{
_class = "nixosTest";
@ -13,9 +16,6 @@
nodes.deployer =
{ pkgs, ... }:
{
environment.systemPackages = [
inputs.nixops4.packages.${pkgs.system}.default
];
# FIXME: sad times
system.extraDependencies = with pkgs; [

View file

@ -1,7 +1,6 @@
{
lib,
config,
inputs,
...
}:
let
@ -26,24 +25,7 @@ let
);
};
};
nixops4Deployment = types.deferredModuleWith {
staticModules = [
inputs.nixops4.modules.nixops4Deployment.default
{
_class = "nixops4Deployment";
_module.args = {
resourceProviderSystem = builtins.currentSystem;
resources = { };
};
}
];
};
deployment = attrTag {
nixops4 = mkOption {
description = "A NixOps4 NixOS deployment. For an example, see https://github.com/nixops4/nixops4-nixos/blob/main/example/deployment.nix.";
type = nixops4Deployment;
};
};
in
{