summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2023-02-02 16:18:02 +0100
committerGitHub <noreply@github.com>2023-02-02 16:18:02 +0100
commit52cadf92e1bfdef235d5cd77b9a4b2ab848baa8a (patch)
tree7405d882a9ec03a37aa481a73255f23fb7a21aff /modules
parente110ed426e1823b32a2409227560af88348f7e24 (diff)
parent8bd5b2b968bfbf44b69aa268d6a0184b61f8e4d6 (diff)
Merge pull request #211 from SuperSandro2000/envfs
Add wsl.binShPkg and wsl.populateBin options to make envfs easily pos…
Diffstat (limited to 'modules')
-rw-r--r--modules/wsl-distro.nix56
1 files changed, 42 insertions, 14 deletions
diff --git a/modules/wsl-distro.nix b/modules/wsl-distro.nix
index 3fe0574..9b93fa1 100644
--- a/modules/wsl-distro.nix
+++ b/modules/wsl-distro.nix
@@ -1,9 +1,27 @@
{ lib, pkgs, config, options, ... }:
-with lib; {
+with lib;
+
+let
+ bashWrapper = pkgs.runCommand "nixos-wsl-bash-wrapper"
+ {
+ nativeBuildInputs = [ pkgs.makeWrapper ];
+ } ''
+ makeWrapper ${pkgs.bashInteractive}/bin/sh $out/bin/sh \
+ --prefix PATH ':' ${lib.makeBinPath (with pkgs; [ systemd gnugrep ])}
+ '';
+
+ cfg = config.wsl;
+in
+{
options.wsl = with types; {
enable = mkEnableOption "support for running NixOS as a WSL distribution";
+ binShPkg = mkOption {
+ type = lib.types.package;
+ internal = true;
+ description = "Package to be linked to /bin/sh. Mainly useful to be re-used by other modules like envfs.";
+ };
nativeSystemd = mkOption {
type = bool;
default = false;
@@ -14,25 +32,29 @@ with lib; {
default = "nixos";
description = "The name of the default user";
};
+ populateBin = mkOption {
+ type = bool;
+ default = true;
+ internal = true;
+ description = ''
+ Dangerous! Things might break. Use with caution!
+
+ Do not populate /bin.
+
+ This is mainfly useful if another module populates /bin like envfs.
+ '';
+ };
startMenuLaunchers = mkEnableOption "shortcuts for GUI applications in the windows start menu";
};
config =
let
- cfg = config.wsl;
-
syschdemd = pkgs.callPackage ../scripts/syschdemd.nix {
automountPath = cfg.wslConf.automount.root;
defaultUser = config.users.users.${cfg.defaultUser};
};
nativeUtils = pkgs.callPackage ../scripts/native-utils { };
-
- bashWrapper = pkgs.runCommand "nixos-wsl-bash-wrapper" { nativeBuildInputs = [ pkgs.makeWrapper ]; } ''
- makeWrapper ${pkgs.bashInteractive}/bin/sh $out/bin/sh --prefix PATH ':' ${lib.makeBinPath [pkgs.systemd pkgs.gnugrep]}
- '';
-
- bash = if cfg.nativeSystemd then bashWrapper else pkgs.bashInteractive;
in
mkIf cfg.enable (
mkMerge [
@@ -92,12 +114,12 @@ with lib; {
done
''
);
- populateBin = stringAfter [ ] ''
+ populateBin = lib.mkIf cfg.populateBin (stringAfter [ ] ''
echo "setting up /bin..."
ln -sf /init /bin/wslpath
- ln -sf ${bash}/bin/sh /bin/sh
+ ln -sf ${cfg.binShPkg}/bin/sh /bin/sh
ln -sf ${pkgs.util-linux}/bin/mount /bin/mount
- '';
+ '');
update-entrypoint.text = ''
mkdir -p /nix/nixos-wsl
ln -sfn ${config.users.users.root.shell} /nix/nixos-wsl/entrypoint
@@ -127,6 +149,12 @@ with lib; {
# Start a systemd user session when starting a command through runuser
security.pam.services.runuser.startSession = true;
+ # require people to use lib.mkForce to make it harder to brick their installation
+ wsl = {
+ binShPkg = if cfg.nativeSystemd then bashWrapper else pkgs.bashInteractive;
+ populateBin = true;
+ };
+
warnings = flatten [
(optional (config.services.resolved.enable && config.wsl.wslConf.network.generateResolvConf)
"systemd-resolved is enabled, but resolv.conf is managed by WSL (wsl.wslConf.network.generateResolvConf)"
@@ -161,11 +189,11 @@ with lib; {
mkdir -p /sbin
ln -sf ${nativeUtils}/bin/systemd-shim /sbin/init
'';
- setupLogin = stringAfter [ ] ''
+ setupLogin = lib.mkIf cfg.populateBin (stringAfter [ ] ''
echo "setting up /bin/login..."
mkdir -p /bin
ln -sf ${pkgs.shadow}/bin/login /bin/login
- '';
+ '');
};
environment = {