un-nixops

This commit is contained in:
Kiara Grouwstra 2025-08-09 23:31:25 +02:00
parent ed027c9f7c
commit 3e7c0c577c
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 = system.extraDependencies =
[ [
inputs.nixops4 sources.nixpkgs
inputs.nixops4-nixos
inputs.nixpkgs
sources.flake-parts
sources.flake-inputs sources.flake-inputs
sources.git-hooks sources.git-hooks

View file

@ -21,25 +21,17 @@ let
optionalString optionalString
; ;
inherit (hostPkgs) inherit (hostPkgs)
runCommandNoCC
writeText writeText
system
; ;
forConcat = xs: f: concatStringsSep "\n" (map f xs); 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 in
{ {
_class = "nixosTest"; _class = "nixosTest";
imports = [ imports = [
./sharedOptions.nix ../common/sharedOptions.nix
]; ];
options = { options = {
@ -67,16 +59,15 @@ in
config = { config = {
sourceFileset = fileset.unions [ sourceFileset = fileset.unions [
# NOTE: not the flake itself; it will be overridden.
../../../mkFlake.nix ../../../mkFlake.nix
../../../flake.lock ../../../flake.lock
../../../npins ../../../npins
../../data-model.nix
../../function.nix
./sharedOptions.nix ../common/sharedOptions.nix
./targetNode.nix ../common/targetNode.nix
./targetResource.nix ../common/targetResource.nix
(config.pathToCwd + "/flake-under-test.nix")
]; ];
acmeNodeIP = config.nodes.acme.networking.primaryIPAddress; acmeNodeIP = config.nodes.acme.networking.primaryIPAddress;
@ -84,7 +75,7 @@ in
nodes = nodes =
{ {
deployer = { deployer = {
imports = [ ./deployerNode.nix ]; imports = [ ../common/deployerNode.nix ];
_module.args = { inherit inputs sources; }; _module.args = { inherit inputs sources; };
enableAcme = config.enableAcme; enableAcme = config.enableAcme;
acmeNodeIP = config.nodes.acme.networking.primaryIPAddress; acmeNodeIP = config.nodes.acme.networking.primaryIPAddress;
@ -111,7 +102,7 @@ in
// //
genAttrs config.targetMachines (_: { genAttrs config.targetMachines (_: {
imports = [ ./targetNode.nix ]; imports = [ ../common/targetNode.nix ];
_module.args = { inherit inputs sources; }; _module.args = { inherit inputs sources; };
enableAcme = config.enableAcme; enableAcme = config.enableAcme;
acmeNodeIP = if config.enableAcme then config.nodes.acme.networking.primaryIPAddress else null; 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") 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 # with subtest("Override the flake and its lock"):
## instance by allowing to grab things directly from the host's store. # deployer.succeed("cp ${config.pathFromRoot}/flake-under-test.nix flake.nix")
##
## 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} \
;
""")
${optionalString config.enableAcme '' ${optionalString config.enableAcme ''
with subtest("Set up handmade DNS"): with subtest("Set up handmade DNS"):

View file

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

View file

@ -1,36 +1,40 @@
{ {
inputs, inputs,
sources, # sources,
lib, lib,
providers, # providers,
... ...
}: }:
let let
inherit (import ./constants.nix) targetMachines pathToRoot pathFromRoot; # inherit (import ./constants.nix) targetMachines pathToRoot pathFromRoot;
in eval =
module:
{ (lib.evalModules {
providers = { specialArgs = {
inherit (inputs.nixops4.modules.nixops4Provider) local; inherit inputs;
}; };
modules = [
resources = lib.genAttrs targetMachines (nodeName: { module
type = providers.local.exec; ../../data-model.nix
imports = [
inputs.nixops4-nixos.modules.nixops4Resource.nixos
../common/targetResource.nix
]; ];
}).config;
_module.args = { inherit inputs sources; }; fediversity = eval (
{ ... }:
inherit nodeName pathToRoot pathFromRoot;
nixos.module =
{ pkgs, ... }:
{ {
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"; _class = "nixosTest";
@ -15,9 +18,6 @@
nodes.deployer = nodes.deployer =
{ pkgs, ... }: { pkgs, ... }:
{ {
environment.systemPackages = [
inputs.nixops4.packages.${pkgs.system}.default
];
# FIXME: sad times # FIXME: sad times
system.extraDependencies = with pkgs; [ system.extraDependencies = with pkgs; [

View file

@ -1,7 +1,6 @@
{ {
lib, lib,
config, config,
inputs,
... ...
}: }:
let 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 { 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 in
{ {