diff options
| author | nzbr <mail@nzbr.de> | 2022-11-06 05:43:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-06 05:43:17 +0100 |
| commit | 318fc7801d8391c0cdea8ef7943d53cd437b9a09 (patch) | |
| tree | cb9b0bfbf567a5659bfb35bb7a8d3a18686485cb /modules | |
| parent | f3d88c099d3ae1e5c28f16856171bb5fcd31f814 (diff) | |
wsl.conf: proper option types (#153)
* wsl.conf: proper option types
* remove `with builtins;`
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
* add native systemd warning
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/wsl-conf.nix | 94 | ||||
| -rw-r--r-- | modules/wsl-distro.nix | 39 |
2 files changed, 100 insertions, 33 deletions
diff --git a/modules/wsl-conf.nix b/modules/wsl-conf.nix new file mode 100644 index 0000000..cb870c7 --- /dev/null +++ b/modules/wsl-conf.nix @@ -0,0 +1,94 @@ +{ lib, pkgs, 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 = str; + 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 purpos, this WILL make your system UNBOOTABLE!" + ); + + }; + +} diff --git a/modules/wsl-distro.nix b/modules/wsl-distro.nix index 87f630f..8dd5cce 100644 --- a/modules/wsl-distro.nix +++ b/modules/wsl-distro.nix @@ -1,7 +1,7 @@ { lib, pkgs, config, ... }: -with lib; -{ +with lib; { + options.wsl = with types; { enable = mkEnableOption "support for running NixOS as a WSL distribution"; nativeSystemd = mkOption { @@ -9,26 +9,12 @@ with lib; default = false; description = "Use native WSL systemd support"; }; - automountPath = mkOption { - type = str; - default = "/mnt"; - description = "The path where windows drives are mounted (e.g. /mnt/c)"; - }; - automountOptions = mkOption { - type = str; - default = "metadata,uid=1000,gid=100"; - description = "Options to use when mounting windows drives"; - }; defaultUser = mkOption { type = str; default = "nixos"; description = "The name of the default user"; }; startMenuLaunchers = mkEnableOption "shortcuts for GUI applications in the windows start menu"; - wslConf = mkOption { - type = attrsOf (attrsOf (oneOf [ string int bool ])); - description = "Entries that are added to /etc/wsl.conf"; - }; }; config = @@ -51,19 +37,6 @@ with lib; mkIf cfg.enable ( mkMerge [ { - wsl.wslConf = { - automount = { - enabled = true; - mountFsTab = true; - root = "${cfg.automountPath}/"; - options = cfg.automountOptions; - }; - network = { - generateResolvConf = mkDefault true; - generateHosts = mkDefault true; - }; - }; - # We don't need a boot loader boot.loader.grub.enable = false; system.build.installBootLoader = "${pkgs.coreutils}/bin/true"; @@ -79,8 +52,6 @@ with lib; environment = { etc = { - "wsl.conf".text = generators.toINI { } cfg.wslConf; - # DNS settings are managed by WSL hosts.enable = !config.wsl.wslConf.network.generateHosts; "resolv.conf".enable = !config.wsl.wslConf.network.generateResolvConf; @@ -146,14 +117,16 @@ with lib; enableEmergencyMode = false; }; - warnings = (optional (config.systemd.services.systemd-resolved.enable && config.wsl.wslConf.network.generateResolvConf) "systemd-resolved is enabled, but resolv.conf is managed by WSL"); + warnings = (optional (config.systemd.services.systemd-resolved.enable && config.wsl.wslConf.network.generateResolvConf) + "systemd-resolved is enabled, but resolv.conf is managed by WSL" + ); } (mkIf (!cfg.nativeSystemd) { users.users.root.shell = "${syschdemd}/bin/syschdemd"; security.sudo.extraConfig = '' Defaults env_keep+=INSIDE_NAMESPACE ''; - wsl.wslConf.users.default = "root"; + wsl.wslConf.user.default = "root"; # Include Windows %PATH% in Linux $PATH. environment.extraInit = mkIf cfg.interop.includePath ''PATH="$PATH:$WSLPATH"''; |
