mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-07-06 17:13:24 -05:00
NixOS has traditionally enabled the `ext` family of file systems by default. Originally, when switching to systemd initrd, we wanted to transition to making this explicit so that initrds could be made without `ext`. The problem is that anyone with `fsType = "auto";` for an `ext` file system in initrd will fail to boot, which is not really an acceptable regression as we switch to systemd initrd by default. By removing `default = "auto"` from `fsType`, we rule out the vast majority of these regressions as eval errors, since most users of `fsType = "auto"` for ext file systems are using it because of the default value. In hindsight, this is probably what #225352 was really about.
146 lines
4.2 KiB
Nix
146 lines
4.2 KiB
Nix
# Run:
|
|
# nix-build -A nixosTests.modularService
|
|
|
|
{
|
|
evalSystem,
|
|
runCommand,
|
|
hello,
|
|
...
|
|
}:
|
|
|
|
let
|
|
machine = evalSystem (
|
|
{ lib, ... }:
|
|
let
|
|
hello' = lib.getExe hello;
|
|
in
|
|
{
|
|
|
|
# Test input
|
|
|
|
system.services.foo = {
|
|
process = {
|
|
argv = [
|
|
hello'
|
|
"--greeting"
|
|
"hoi"
|
|
];
|
|
};
|
|
};
|
|
system.services.bar = {
|
|
process = {
|
|
argv = [
|
|
hello'
|
|
"--greeting"
|
|
"hoi"
|
|
];
|
|
};
|
|
systemd.service = {
|
|
serviceConfig.X-Bar = "lol crossbar whatever";
|
|
};
|
|
services.db = {
|
|
process = {
|
|
argv = [
|
|
hello'
|
|
"--greeting"
|
|
"Hi, I'm a database, would you believe it"
|
|
];
|
|
};
|
|
systemd.service = {
|
|
serviceConfig.RestartSec = "42";
|
|
};
|
|
};
|
|
};
|
|
|
|
# Test that systemd.mainExecStart overrides process.argv
|
|
# and allows systemd's specifier and variable substitution
|
|
system.services.argv-with-subst = {
|
|
process = {
|
|
argv = [
|
|
hello'
|
|
"--greeting"
|
|
"This should be ignored"
|
|
];
|
|
};
|
|
systemd.mainExecStart = ''/bin/sh -c "echo %n and ''${HOME}"'';
|
|
};
|
|
|
|
# Test that process.argv escapes % and $ by default
|
|
system.services.argv-escaped = {
|
|
process = {
|
|
argv = [
|
|
"/bin/sh"
|
|
"-c"
|
|
"echo %n and \${HOME}"
|
|
];
|
|
};
|
|
};
|
|
|
|
# Test extending process.argv with systemd specifiers
|
|
system.services.argv-extended =
|
|
{ config, ... }:
|
|
{
|
|
process = {
|
|
argv = [
|
|
hello'
|
|
"--greeting"
|
|
"Fun $1 fact, remainder is often expressed as m%n"
|
|
];
|
|
};
|
|
systemd.mainExecStart =
|
|
config.systemd.lib.escapeSystemdExecArgs config.process.argv + " --systemd-unit %n";
|
|
};
|
|
|
|
# irrelevant stuff
|
|
system.stateVersion = "25.05";
|
|
fileSystems."/" = {
|
|
device = "/test/dummy";
|
|
fsType = "auto";
|
|
};
|
|
boot.loader.grub.enable = false;
|
|
}
|
|
);
|
|
|
|
inherit (machine.config.system.build) toplevel;
|
|
in
|
|
runCommand "test-modular-service-systemd-units"
|
|
{
|
|
passthru = {
|
|
inherit
|
|
machine
|
|
toplevel
|
|
;
|
|
};
|
|
}
|
|
''
|
|
echo ${toplevel}/etc/systemd/system/foo.service:
|
|
cat -n ${toplevel}/etc/systemd/system/foo.service
|
|
(
|
|
set -x
|
|
grep -F 'ExecStart="${hello}/bin/hello" "--greeting" "hoi"' ${toplevel}/etc/systemd/system/foo.service >/dev/null
|
|
|
|
grep -F 'ExecStart="${hello}/bin/hello" "--greeting" "hoi"' ${toplevel}/etc/systemd/system/bar.service >/dev/null
|
|
grep -F 'X-Bar=lol crossbar whatever' ${toplevel}/etc/systemd/system/bar.service >/dev/null
|
|
|
|
grep 'ExecStart="${hello}/bin/hello" "--greeting" ".*database.*"' ${toplevel}/etc/systemd/system/bar-db.service >/dev/null
|
|
grep -F 'RestartSec=42' ${toplevel}/etc/systemd/system/bar-db.service >/dev/null
|
|
|
|
# Test that systemd.mainExecStart overrides process.argv
|
|
# Note: %n and $HOME are NOT escaped, allowing systemd to substitute them
|
|
grep -F 'ExecStart=/bin/sh -c "echo %n and ''${HOME}"' ${toplevel}/etc/systemd/system/argv-with-subst.service >/dev/null
|
|
|
|
# Test that process.argv escapes % as %% and $ as $$
|
|
# This prevents systemd from performing specifier/variable substitution
|
|
grep -F 'ExecStart="/bin/sh" "-c" "echo %%n and $${HOME}"' ${toplevel}/etc/systemd/system/argv-escaped.service >/dev/null
|
|
|
|
# Test extending process.argv with systemd specifiers
|
|
# The base command should be escaped ($1 -> $$1, m%n -> m%%n), but the appended --systemd-unit %n should not be
|
|
grep -F 'ExecStart="${hello}/bin/hello" "--greeting" "Fun $$1 fact, remainder is often expressed as m%%n" --systemd-unit %n' ${toplevel}/etc/systemd/system/argv-extended.service >/dev/null
|
|
|
|
[[ ! -e ${toplevel}/etc/systemd/system/foo.socket ]]
|
|
[[ ! -e ${toplevel}/etc/systemd/system/bar.socket ]]
|
|
[[ ! -e ${toplevel}/etc/systemd/system/bar-db.socket ]]
|
|
)
|
|
echo 🐬👍
|
|
touch $out
|
|
''
|