summaryrefslogtreecommitdiff
path: root/modules/wsl-conf.nix
blob: 877041a8a98b737ce14d6f128da07dd788d53538 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{ lib, config, ... }:

with lib; {
  imports = [
    (mkRenamedOptionModule [ "wsl" "automountPath" ] [ "wsl" "wslConf" "automount" "root" ])
    (mkRenamedOptionModule [ "wsl" "automountOptions" ] [ "wsl" "wslConf" "automount" "options" ])
  ];

  # See https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconf for all options
  options.wsl.wslConf = with types; {
    automount = {
      enabled = mkOption {
        type = bool;
        default = true;
        description = "Automatically mount windows drives under ${config.wsl.wslConf.automount.root}";
      };
      mountFsTab = mkOption {
        type = bool;
        default = false;
        description = "Mount entries from /etc/fstab through WSL. You should probably leave this on false, because systemd will mount those for you.";
      };
      root = mkOption {
        type = strMatching "^/.*[^/]$";
        default = "/mnt";
        description = "The directory under which to mount windows drives.";
      };
      options = mkOption {
        type = commas; # comma-separated strings
        default = "metadata,uid=1000,gid=100";
        description = "Comma-separated list of mount options that should be used for mounting windows drives.";
      };
    };
    boot = {
      command = mkOption {
        type = str;
        default = "";
        description = "A command to run when the distro is started.";
      };
      systemd = mkOption {
        type = bool;
        default = false;
        description = "Use systemd as init. There's no need to enable this manually, use the wsl.nativeSystemd option instead";
      };
    };
    interop = {
      enabled = mkOption {
        type = bool;
        default = true;
        description = "Support running Windows binaries from the linux shell.";
      };
      appendWindowsPath = mkOption {
        type = bool;
        default = true;
        description = "Include the Windows PATH in the PATH variable";
      };
    };
    network = {
      generateHosts = mkOption {
        type = bool;
        default = true;
        description = "Generate /etc/hosts through WSL";
      };
      generateResolvConf = mkOption {
        type = bool;
        default = true;
        description = "Generate /etc/resolv.conf through WSL";
      };
      hostname = mkOption {
        type = str;
        default = config.networking.hostName;
        defaultText = "config.networking.hostName";
        description = "The hostname of the WSL instance";
      };
    };
    user = {
      default = mkOption {
        type = str;
        default = "root";
        description = "Which user to start commands in this WSL distro as";
      };
    };
  };

  config = mkIf config.wsl.enable {

    environment.etc."wsl.conf".text = generators.toINI { } config.wsl.wslConf;

    warnings = optional (config.wsl.wslConf.boot.systemd && !config.wsl.nativeSystemd)
      "systemd is enabled in wsl.conf, but wsl.nativeSystemd is not enabled. Unless you did this on purpose, this WILL make your system UNBOOTABLE!"
    ++ optional (config.wsl.wslConf.network.generateHosts && config.networking.extraHosts != "")
      "networking.extraHosts has no effect if wsl.wslConf.network.generateHosts is true.";

  };

}