summaryrefslogtreecommitdiff
path: root/modules/systemd/native/default.nix
blob: f641580970c5f8bbb933fb955abfa3f85831840b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{ config, pkgs, lib, ... }:
with lib; {

  config =
    let
      cfg = config.wsl;
      nativeUtils = pkgs.callPackage ../../../utils { };

      bashWrapper = pkgs.writeShellScriptBin "sh" ''
        export PATH="$PATH:${lib.makeBinPath [ pkgs.systemd pkgs.gnugrep ]}"
        exec ${pkgs.bashInteractive}/bin/sh "$@"
      '';
    in
    mkIf (cfg.enable && cfg.nativeSystemd) {

      wsl = {
        binShPkg = bashWrapper;
        wslConf = {
          user.default = config.users.users.${cfg.defaultUser}.name;
          boot.systemd = true;
        };
      };

      system.activationScripts = {
        shimSystemd = stringAfter [ ] ''
          echo "setting up /sbin/init shim..."
          mkdir -p /sbin
          ln -sf ${nativeUtils}/bin/systemd-shim /sbin/init
        '';
        setupLogin = lib.mkIf cfg.populateBin (stringAfter [ ] ''
          echo "setting up /bin/login..."
          mkdir -p /bin
          ln -sf ${pkgs.shadow}/bin/login /bin/login
        '');
      };

      environment = {
        # preserve $PATH from parent
        variables.PATH = [ "$PATH" ];
        extraInit = ''
          eval $(${nativeUtils}/bin/split-path --automount-root="${cfg.wslConf.automount.root}" ${lib.optionalString cfg.interop.includePath "--include-interop"})
        '';
      };
    };

}