Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions nix/modules/environment.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
type = lib.types.listOf lib.types.str;
default = [ ];
};

extraInit = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Shell script code which should be called before any shell session through the host /etc/profile.";
};
};

config =
Expand All @@ -31,6 +37,7 @@
etc = {
"profile.d/system-manager-path.sh".source = pkgs.writeText "system-manager-path.sh" ''
export PATH=${pathDir}/bin/:''${PATH}
${config.environment.extraInit}
'';

# TODO: figure out how to properly add fish support. We could start by
Expand Down
35 changes: 35 additions & 0 deletions testFlake/container-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,41 @@ in
'';
};

container-extra-init = makeContainerTestFor "extra-init" {
modules = [
(
{ ... }:
{
environment.etc."nix/nix.conf".replaceExisting = true;

environment.extraInit = ''
export MY_CUSTOM_VAR="hello-from-extraInit"
'';
}
)
];
testScriptFunction =
{ toplevel, hostPkgs, ... }:
''
start_all()

machine.wait_for_unit("multi-user.target")

activation_logs = machine.activate()
for line in activation_logs.split("\n"):
assert not "ERROR" in line, line
machine.wait_for_unit("system-manager.target")

with subtest("extraInit code is present in profile script"):
content = machine.succeed("cat /etc/profile.d/system-manager-path.sh")
assert "MY_CUSTOM_VAR" in content, f"Expected extraInit content in profile script, got: {content}"

with subtest("extraInit variable is set in login shell"):
value = machine.succeed("bash --login -c 'echo $MY_CUSTOM_VAR'").strip()
assert value == "hello-from-extraInit", f"Expected 'hello-from-extraInit', got: '{value}'"
'';
};

container-masked-units = makeContainerTestFor "masked-units" {
modules = [
(
Expand Down