Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos: systemd doesn't respect fileSystems.<name>.depends #217179

Open
ElvishJerricco opened this issue Feb 19, 2023 · 2 comments · May be fixed by #233707
Open

nixos: systemd doesn't respect fileSystems.<name>.depends #217179

ElvishJerricco opened this issue Feb 19, 2023 · 2 comments · May be fixed by #233707

Comments

@ElvishJerricco
Copy link
Contributor

ElvishJerricco commented Feb 19, 2023

Describe the bug

systemd doesn't respect the depends option for file systems. Usually this is ok because systemd will mount file systems in the correct topological ordering. The depends option is useful because it allows you to express dependencies on e.g. the file systems that an overlay FS's lower/upper/work directories exist on.

Steps To Reproduce

This test should hang forever. Instead, it exits cleanly.

import ./nixos/tests/make-test-python.nix ({ lib, pkgs, ... }: {
  name = "should-hang";

  nodes.machine = {
    systemd.services.block-foo = {
      unitConfig.DefaultDependencies = false;
      serviceConfig = {
        ExecStart = "${pkgs.coreutils}/bin/sleep infinity";
        Type = "oneshot";
      };
    };

    virtualisation.fileSystems = {
      "/foo" = {
        device = "tmpfs";
        fsType = "tmpfs";
        options = ["nofail" "x-systemd.requires=block-foo.service" "x-systemd.after=block-foo.service"];
      };

      "/bar" = {
        device = "tmpfs";
        fsType = "tmpfs";
        depends = ["/foo"];
        # This would fix it:
        # options = ["x-systemd.requires-mounts-for=/foo"];                                                                                                                                   
      };
    };
  };

  testScript = ''                                                                                                                                                                             
    machine.wait_for_unit("bar.mount")                                                                                                                                                        
    machine.fail("mount | grep foo")                                                                                                                                                          
  '';
})

Expected behavior

The block-foo service never exits, so /foo is never mounted, and therefore /bar should never be mounted. So the test should hang.

Additional context

This is also a problem for systemd stage 1, but it's worse because we also have to account for the /sysroot prefix. We can fix this by adding x-systemd.requires-mounts-for= options for every dependency, and prefixing /sysroot for the systemd stage 1 file systems.

@ElvishJerricco ElvishJerricco added this to To Do in systemd in Stage 1 via automation Feb 19, 2023
@nikstur
Copy link
Contributor

nikstur commented Jun 14, 2024

Do we even need the depends option? I don't think it's particularly useful. The overlay also shouldn't be a concern since #286176 anymore.

@ElvishJerricco
Copy link
Contributor Author

@nikstur Well, currently depends literally only does anything in scripted stage 1. In stage 2 and in systemd stage 1, you have to use x-systemd.requires-mounts-for=, which is what the overlay stuff does. That's fine, but it's an incompatibility between scripted and systemd stage 1. So we need to either deprecate it or implement it, and it's really easy to implement (I just need to fixup #233707). It's a handy convenience for people I guess, though far from a necessary one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To Do
Development

Successfully merging a pull request may close this issue.

2 participants