mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-16 14:54:29 +01:00
4a9d9928dc
The `nix.*` options, apart from options for setting up the daemon itself, currently provide a lot of setting mappings for the Nix daemon configuration. The scope of the mapping yields convience, but the line where an option is considered essential is blurry. For instance, the `extra-sandbox-paths` mapping is provided without its primary consumer, and the corresponding `sandbox-paths` option is also not mapped. The current system increases the maintenance burden as maintainers have to closely follow upstream changes. In this case, there are two state versions of Nix which have to be maintained collectively, with different options avaliable. This commit aims to following the standard outlined in RFC 42[1] to implement a structural setting pattern. The Nix configuration is encoded at its core as key-value pairs which maps nicely to attribute sets, making it feasible to express in the Nix language itself. Some existing options are kept such as `buildMachines` and `registry` which present a simplified interface to managing the respective settings. The interface is exposed as `nix.settings`. Legacy configurations are mapped to their corresponding options under `nix.settings` for backwards compatibility. Various options settings in other nixos modules and relevant tests have been updated to use structural setting for consistency. The generation and validation of the configration file has been modified to use `writeTextFile` instead of `runCommand` for clarity. Note that validation is now mandatory as strict checking of options has been pushed down to the derivation level due to freeformType consuming unmatched options. Furthermore, validation can not occur when cross-compiling due to current limitations. A new option `publicHostKey` was added to the `buildMachines` submodule corresponding to the base64 encoded public host key settings exposed in the builder syntax. The build machine generation was subsequently rewritten to use `concatStringsSep` for better performance by grouping concatenations. [1] - https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md
114 lines
3.7 KiB
Nix
114 lines
3.7 KiB
Nix
{ pkgs, ... }:
|
|
let
|
|
inherit (pkgs) lib;
|
|
|
|
tests = {
|
|
# TODO: uncomment stable
|
|
# - Blocked on https://github.com/NixOS/nixpkgs/issues/138584 which has a
|
|
# PR in staging: https://github.com/NixOS/nixpkgs/pull/139986
|
|
# - Alternatively, blocked on a NixOps 2 release
|
|
# https://github.com/NixOS/nixops/issues/1242
|
|
# stable = testsLegacyNetwork { nixopsPkg = pkgs.nixops; };
|
|
unstable = testsForPackage { nixopsPkg = pkgs.nixopsUnstable; };
|
|
|
|
# inherit testsForPackage;
|
|
};
|
|
|
|
testsForPackage = lib.makeOverridable (args: lib.recurseIntoAttrs {
|
|
legacyNetwork = testLegacyNetwork args;
|
|
});
|
|
|
|
testLegacyNetwork = { nixopsPkg }: pkgs.nixosTest ({
|
|
nodes = {
|
|
deployer = { config, lib, nodes, pkgs, ... }: {
|
|
imports = [ ../../modules/installer/cd-dvd/channel.nix ];
|
|
environment.systemPackages = [ nixopsPkg ];
|
|
nix.settings.substituters = lib.mkForce [ ];
|
|
users.users.person.isNormalUser = true;
|
|
virtualisation.writableStore = true;
|
|
virtualisation.additionalPaths = [
|
|
pkgs.hello
|
|
pkgs.figlet
|
|
|
|
# This includes build dependencies all the way down. Not efficient,
|
|
# but we do need build deps to an *arbitrary* depth, which is hard to
|
|
# determine.
|
|
(allDrvOutputs nodes.server.config.system.build.toplevel)
|
|
];
|
|
};
|
|
server = { lib, ... }: {
|
|
imports = [ ./legacy/base-configuration.nix ];
|
|
};
|
|
};
|
|
|
|
testScript = { nodes }:
|
|
let
|
|
deployerSetup = pkgs.writeScript "deployerSetup" ''
|
|
#!${pkgs.runtimeShell}
|
|
set -eux -o pipefail
|
|
cp --no-preserve=mode -r ${./legacy} unicorn
|
|
cp --no-preserve=mode ${../ssh-keys.nix} unicorn/ssh-keys.nix
|
|
mkdir -p ~/.ssh
|
|
cp ${snakeOilPrivateKey} ~/.ssh/id_ed25519
|
|
chmod 0400 ~/.ssh/id_ed25519
|
|
'';
|
|
serverNetworkJSON = pkgs.writeText "server-network.json"
|
|
(builtins.toJSON nodes.server.config.system.build.networkConfig);
|
|
in
|
|
''
|
|
import shlex
|
|
|
|
def deployer_do(cmd):
|
|
cmd = shlex.quote(cmd)
|
|
return deployer.succeed(f"su person -l -c {cmd} &>/dev/console")
|
|
|
|
start_all()
|
|
|
|
deployer_do("cat /etc/hosts")
|
|
|
|
deployer_do("${deployerSetup}")
|
|
deployer_do("cp ${serverNetworkJSON} unicorn/server-network.json")
|
|
|
|
# Establish that ssh works, regardless of nixops
|
|
# Easy way to accept the server host key too.
|
|
server.wait_for_open_port(22)
|
|
deployer.wait_for_unit("network.target")
|
|
|
|
# Put newlines on console, to flush the console reader's line buffer
|
|
# in case nixops' last output did not end in a newline, as is the case
|
|
# with a status line (if implemented?)
|
|
deployer.succeed("while sleep 60s; do echo [60s passed]; done >&2 &")
|
|
|
|
deployer_do("cd ~/unicorn; ssh -oStrictHostKeyChecking=accept-new root@server echo hi")
|
|
|
|
# Create and deploy
|
|
deployer_do("cd ~/unicorn; nixops create")
|
|
|
|
deployer_do("cd ~/unicorn; nixops deploy --confirm")
|
|
|
|
deployer_do("cd ~/unicorn; nixops ssh server 'hello | figlet'")
|
|
'';
|
|
});
|
|
|
|
inherit (import ../ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey;
|
|
|
|
/*
|
|
Return a store path with a closure containing everything including
|
|
derivations and all build dependency outputs, all the way down.
|
|
*/
|
|
allDrvOutputs = pkg:
|
|
let name = lib.strings.sanitizeDerivationName "allDrvOutputs-${pkg.pname or pkg.name or "unknown"}";
|
|
in
|
|
pkgs.runCommand name { refs = pkgs.writeReferencesToFile pkg.drvPath; } ''
|
|
touch $out
|
|
while read ref; do
|
|
case $ref in
|
|
*.drv)
|
|
cat $ref >>$out
|
|
;;
|
|
esac
|
|
done <$refs
|
|
'';
|
|
|
|
in
|
|
tests
|