Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 99b5068c263b
Choose a base ref
...
head repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 35d8514a9149
Choose a head ref
  • 2 commits
  • 14 files changed
  • 2 contributors

Commits on Apr 12, 2020

  1. specialisation: replace nesting with named configurations

    Co-authored-by: worldofpeace <worldofpeace@protonmail.ch>
    grahamc and worldofpeace committed Apr 12, 2020

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    ec2d28e View commit details
  2. Merge pull request #81848 from grahamc/nested-specialisation

    specialisation: replace nesting with named configurations
    grahamc authored Apr 12, 2020

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    35d8514 View commit details
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ networking.proxy.noProxy = &quot;127.0.0.1,localhost,internal.domain&quot;;
<note>
<para>
If you are switching networks with different proxy configurations, use the
<literal>nesting.clone</literal> option in
<literal>specialisation</literal> option in
<literal>configuration.nix</literal> to switch proxies at runtime. Refer to
<xref linkend="ch-options" /> for more information.
</para>
44 changes: 44 additions & 0 deletions nixos/doc/manual/release-notes/rl-2009.xml
Original file line number Diff line number Diff line change
@@ -203,6 +203,50 @@ environment.systemPackages = [
<link xlink:href="https://github.com/gollum/gollum/wiki/5.0-release-notes#migrating-your-wiki">here</link>.
</para>
</listitem>

<listitem>
<para>
The NixOS options <literal>nesting.clone</literal> and
<literal>nesting.children</literal> have been deleted, and
replaced with named <xref linkend="opt-specialisation"/>
configurations.
</para>

<para>
Replace a <literal>nesting.clone</literal> entry with:

<programlisting>{
<link xlink:href="#opt-specialisation">specialisation.example-sub-configuration</link> = {
<link xlink:href="#opt-specialisation._name_.configuration">configuration</link> = {
...
};
};</programlisting>

</para>
<para>
Replace a <literal>nesting.children</literal> entry with:

<programlisting>{
<link xlink:href="#opt-specialisation">specialisation.example-sub-configuration</link> = {
<link xlink:href="#opt-specialisation._name_.inheritParentConfig">inheritParentConfig</link> = false;
<link xlink:href="#opt-specialisation._name_.configuration">configuration</link> = {
...
};
};</programlisting>
</para>

<para>
To switch to a specialised configuration at runtime you need to
run:
<programlisting>
# sudo /run/current-system/specialisation/example-sub-configuration/bin/switch-to-configuration test
</programlisting>
Before you would have used:
<programlisting>
# sudo /run/current-system/fine-tune/child-1/bin/switch-to-configuration test
</programlisting>
</para>
</listitem>
</itemizedlist>
</section>

3 changes: 1 addition & 2 deletions nixos/modules/system/activation/no-clone.nix
Original file line number Diff line number Diff line change
@@ -4,6 +4,5 @@ with lib;

{
boot.loader.grub.device = mkOverride 0 "nodev";
nesting.children = mkOverride 0 [];
nesting.clone = mkOverride 0 [];
specialisation = mkOverride 0 {};
}
65 changes: 35 additions & 30 deletions nixos/modules/system/activation/top-level.nix
Original file line number Diff line number Diff line change
@@ -11,21 +11,16 @@ let
# you can provide an easy way to boot the same configuration
# as you use, but with another kernel
# !!! fix this
cloner = inheritParent: list:
map (childConfig:
children = mapAttrs (childName: childConfig:
(import ../../../lib/eval-config.nix {
inherit baseModules;
system = config.nixpkgs.initialSystem;
modules =
(optionals inheritParent modules)
(optionals childConfig.inheritParentConfig modules)
++ [ ./no-clone.nix ]
++ [ childConfig ];
++ [ childConfig.configuration ];
}).config.system.build.toplevel
) list;

children =
cloner false config.nesting.children
++ cloner true config.nesting.clone;
) config.specialisation;

systemBuilder =
let
@@ -77,12 +72,9 @@ let
echo -n "$nixosLabel" > $out/nixos-version
echo -n "${config.boot.kernelPackages.stdenv.hostPlatform.system}" > $out/system
mkdir $out/fine-tune
childCount=0
for i in $children; do
childCount=$(( childCount + 1 ))
ln -s $i $out/fine-tune/child-$childCount
done
mkdir $out/specialisation
${concatStringsSep "\n"
(mapAttrsToList (name: path: "ln -s ${path} $out/specialisation/${name}") children)}
mkdir $out/bin
export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive"
@@ -112,7 +104,6 @@ let
shell = "${pkgs.bash}/bin/sh";
su = "${pkgs.shadow.su}/bin/su";

inherit children;
kernelParams = config.boot.kernelParams;
installBootLoader =
config.system.build.installBootLoader
@@ -143,6 +134,11 @@ let
in

{
imports = [
(mkRemovedOptionModule [ "nesting" "clone" ] "Use `specialisation.«name» = { inheritParentConfig = true; configuration = { ... }; }` instead.")
(mkRemovedOptionModule [ "nesting" "children" ] "Use `specialisation.«name».configuration = { ... }` instead.")
];

options = {

system.build = mkOption {
@@ -154,26 +150,35 @@ in
'';
};

nesting.children = mkOption {
default = [];
description = ''
Additional configurations to build.
'';
};

nesting.clone = mkOption {
default = [];
specialisation = mkOption {
default = {};
example = lib.literalExample "{ fewJobsManyCores.configuration = { nix.buildCores = 0; nix.maxJobs = 1; }; }";
description = ''
Additional configurations to build based on the current
configuration which then has a lower priority.
Additional configurations to build. If
<literal>inheritParentConfig</literal> is true, the system
will be based on the overall system configuration.
To switch to a cloned configuration (e.g. <literal>child-1</literal>)
at runtime, run
To switch to a specialised configuration
(e.g. <literal>fewJobsManyCores</literal>) at runtime, run:
<programlisting>
# sudo /run/current-system/fine-tune/child-1/bin/switch-to-configuration test
# sudo /run/current-system/specialisation/fewJobsManyCores/bin/switch-to-configuration test
</programlisting>
'';
type = types.attrsOf (types.submodule (
{ ... }: {
options.inheritParentConfig = mkOption {
type = types.bool;
default = true;
description = "Include the entire system's configuration. Set to false to make a completely differently configured system.";
};

options.configuration = mkOption {
default = {};
description = "Arbitrary NixOS configuration options.";
};
})
);
};

system.boot.loader.id = mkOption {
5 changes: 3 additions & 2 deletions nixos/modules/system/boot/loader/grub/install-grub.pl
Original file line number Diff line number Diff line change
@@ -409,7 +409,7 @@ sub addEntry {

# Find all the children of the current default configuration
# Do not search for grand children
my @links = sort (glob "$defaultConfig/fine-tune/*");
my @links = sort (glob "$defaultConfig/specialisation/*");
foreach my $link (@links) {

my $entryName = "";
@@ -425,7 +425,8 @@ sub addEntry {
if ($cfgName) {
$entryName = $cfgName;
} else {
$entryName = "($date - $version)";
my $linkname = basename($link);
$entryName = "($linkname - $date - $version)";
}
addEntry("NixOS - $entryName", $link);
}
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ addEntry "NixOS - Default" $defaultConfig ""
# Add all generations of the system profile to the menu, in reverse
# (most recent to least recent) order.
for link in $((ls -d $defaultConfig/fine-tune/* ) | sort -n); do
for link in $((ls -d $defaultConfig/specialisation/* ) | sort -n); do
date=$(stat --printf="%y\n" $link | sed 's/\..*//')
addEntry "NixOS - variation" $link ""
done
94 changes: 46 additions & 48 deletions nixos/tests/acme.nix
Original file line number Diff line number Diff line change
@@ -91,52 +91,50 @@ in import ./make-test-python.nix {

security.acme.server = "https://acme-v02.api.letsencrypt.org/dir";

nesting.clone = [
({pkgs, ...}: {
systemd.targets."acme-finished-b.example.com" = {};
systemd.services."acme-b.example.com" = {
wants = [ "acme-finished-b.example.com.target" ];
before = [ "acme-finished-b.example.com.target" ];
after = [ "nginx.service" ];
};
services.nginx.virtualHosts."b.example.com" = {
enableACME = true;
forceSSL = true;
locations."/".root = pkgs.runCommand "docroot" {} ''
mkdir -p "$out"
echo hello world > "$out/index.html"
'';
};
})
({pkgs, config, nodes, lib, ...}: {
security.acme.certs."example.com" = {
domain = "*.example.com";
dnsProvider = "exec";
dnsPropagationCheck = false;
credentialsFile = with pkgs; writeText "wildcard.env" ''
EXEC_PATH=${dnsScript { inherit writeScript bash curl; dnsAddress = nodes.dnsserver.config.networking.primaryIPAddress; }}
'';
user = config.services.nginx.user;
group = config.services.nginx.group;
};
systemd.targets."acme-finished-example.com" = {};
systemd.services."acme-example.com" = {
wants = [ "acme-finished-example.com.target" ];
before = [ "acme-finished-example.com.target" "nginx.service" ];
wantedBy = [ "nginx.service" ];
};
services.nginx.virtualHosts."c.example.com" = {
forceSSL = true;
sslCertificate = config.security.acme.certs."example.com".directory + "/cert.pem";
sslTrustedCertificate = config.security.acme.certs."example.com".directory + "/full.pem";
sslCertificateKey = config.security.acme.certs."example.com".directory + "/key.pem";
locations."/".root = pkgs.runCommand "docroot" {} ''
mkdir -p "$out"
echo hello world > "$out/index.html"
'';
};
})
];
specialisation.second-cert.configuration = {pkgs, ...}: {
systemd.targets."acme-finished-b.example.com" = {};
systemd.services."acme-b.example.com" = {
wants = [ "acme-finished-b.example.com.target" ];
before = [ "acme-finished-b.example.com.target" ];
after = [ "nginx.service" ];
};
services.nginx.virtualHosts."b.example.com" = {
enableACME = true;
forceSSL = true;
locations."/".root = pkgs.runCommand "docroot" {} ''
mkdir -p "$out"
echo hello world > "$out/index.html"
'';
};
};
specialisation.dns-01.configuration = {pkgs, config, nodes, lib, ...}: {
security.acme.certs."example.com" = {
domain = "*.example.com";
dnsProvider = "exec";
dnsPropagationCheck = false;
credentialsFile = with pkgs; writeText "wildcard.env" ''
EXEC_PATH=${dnsScript { inherit writeScript bash curl; dnsAddress = nodes.dnsserver.config.networking.primaryIPAddress; }}
'';
user = config.services.nginx.user;
group = config.services.nginx.group;
};
systemd.targets."acme-finished-example.com" = {};
systemd.services."acme-example.com" = {
wants = [ "acme-finished-example.com.target" ];
before = [ "acme-finished-example.com.target" "nginx.service" ];
wantedBy = [ "nginx.service" ];
};
services.nginx.virtualHosts."c.example.com" = {
forceSSL = true;
sslCertificate = config.security.acme.certs."example.com".directory + "/cert.pem";
sslTrustedCertificate = config.security.acme.certs."example.com".directory + "/full.pem";
sslCertificateKey = config.security.acme.certs."example.com".directory + "/key.pem";
locations."/".root = pkgs.runCommand "docroot" {} ''
mkdir -p "$out"
echo hello world > "$out/index.html"
'';
};
};
};

client = {nodes, lib, ...}: {
@@ -196,7 +194,7 @@ in import ./make-test-python.nix {
with subtest("Can add another certificate for nginx service"):
webserver.succeed(
"/run/current-system/fine-tune/child-1/bin/switch-to-configuration test"
"/run/current-system/specialisation/second-cert/bin/switch-to-configuration test"
)
webserver.wait_for_unit("acme-finished-b.example.com.target")
client.succeed(
@@ -208,7 +206,7 @@ in import ./make-test-python.nix {
"${switchToNewServer}"
)
webserver.succeed(
"/run/current-system/fine-tune/child-2/bin/switch-to-configuration test"
"/run/current-system/specialisation/dns-01/bin/switch-to-configuration test"
)
webserver.wait_for_unit("acme-finished-example.com.target")
client.succeed(
2 changes: 1 addition & 1 deletion nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
@@ -202,7 +202,7 @@ in
nat.standalone = handleTest ./nat.nix { withFirewall = false; };
ndppd = handleTest ./ndppd.nix {};
neo4j = handleTest ./neo4j.nix {};
nesting = handleTest ./nesting.nix {};
specialisation = handleTest ./specialisation.nix {};
netdata = handleTest ./netdata.nix {};
networking.networkd = handleTest ./networking.nix { networkd = true; };
networking.scripted = handleTest ./networking.nix { networkd = false; };
44 changes: 21 additions & 23 deletions nixos/tests/caddy.nix
Original file line number Diff line number Diff line change
@@ -20,35 +20,33 @@ import ./make-test-python.nix ({ pkgs, ... }: {
}
'';

nesting.clone = [
{
services.caddy.config = lib.mkForce ''
http://localhost {
gzip
specialisation.etag.configuration = {
services.caddy.config = lib.mkForce ''
http://localhost {
gzip
root ${
pkgs.runCommand "testdir2" {} ''
mkdir "$out"
echo changed > "$out/example.html"
''
}
root ${
pkgs.runCommand "testdir2" {} ''
mkdir "$out"
echo changed > "$out/example.html"
''
}
'';
}
}
'';
};

{
services.caddy.config = ''
http://localhost:8080 {
}
'';
}
];
specialisation.config-reload.configuration = {
services.caddy.config = ''
http://localhost:8080 {
}
'';
};
};
};

testScript = { nodes, ... }: let
etagSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-1";
justReloadSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-2";
etagSystem = "${nodes.webserver.config.system.build.toplevel}/specialisation/etag";
justReloadSystem = "${nodes.webserver.config.system.build.toplevel}/specialisation/config-reload";
in ''
url = "http://localhost/example.html"
webserver.wait_for_unit("caddy")
@@ -77,7 +75,7 @@ import ./make-test-python.nix ({ pkgs, ... }: {
assert old_etag != new_etag, "Old ETag {} is the same as {}".format(
old_etag, new_etag
)
with subtest("config is reloaded on nixos-rebuild switch"):
webserver.succeed(
"${justReloadSystem}/bin/switch-to-configuration test >&2"
Loading