Skip to content

Commit

Permalink
wip: start yeeting things
Browse files Browse the repository at this point in the history
  • Loading branch information
K900 committed Aug 27, 2023
1 parent 9300bb4 commit c78cffa
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 687 deletions.
2 changes: 1 addition & 1 deletion checks/rustfmt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
, ...
}:
runCommand "check-rustfmt" { nativeBuildInputs = [ cargo rustfmt ]; } ''
cargo fmt --manifest-path=${./../scripts/native-utils}/Cargo.toml --check
cargo fmt --manifest-path=${./../native-utils}/Cargo.toml --check
touch $out
''
8 changes: 0 additions & 8 deletions checks/shfmt.nix

This file was deleted.

9 changes: 2 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

nixosModules.wsl = {
imports = [
./modules/build-tarball.nix
./modules/docker-desktop.nix
./modules/docker-native.nix
./modules/installer.nix
./modules/interop.nix
./modules/systemd-tarball.nix
./modules/version.nix
Expand Down Expand Up @@ -55,24 +52,22 @@
in
{
nixpkgs-fmt = pkgs.callPackage ./checks/nixpkgs-fmt.nix args;
shfmt = pkgs.callPackage ./checks/shfmt.nix args;
rustfmt = pkgs.callPackage ./checks/rustfmt.nix args;
side-effects = pkgs.callPackage ./checks/side-effects.nix args;
username = pkgs.callPackage ./checks/username.nix args;
test-native-utils = self.packages.${system}.utils;
};

packages = {
utils = pkgs.callPackage ./scripts/native-utils { };
staticUtils = pkgs.pkgsStatic.callPackage ./scripts/native-utils { };
utils = pkgs.callPackage ./native-utils { };
staticUtils = pkgs.pkgsStatic.callPackage ./native-utils { };
};

devShell = pkgs.mkShell {
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";

nativeBuildInputs = with pkgs; [
nixpkgs-fmt
shfmt
rustc
cargo
rustfmt
Expand Down
112 changes: 0 additions & 112 deletions modules/build-tarball.nix

This file was deleted.

34 changes: 0 additions & 34 deletions modules/docker-native.nix

This file was deleted.

72 changes: 0 additions & 72 deletions modules/installer.nix

This file was deleted.

58 changes: 8 additions & 50 deletions modules/interop.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{ lib, pkgs, config, ... }:
{ lib, config, ... }:

with builtins; with lib;
{
imports = [
(mkRenamedOptionModule [ "wsl" "compatibility" "interopPreserveArgvZero" ] [ "wsl" "interop" "preserveArgvZero" ])
];

options.wsl.interop = with types; {
register = mkOption {
type = bool;
Expand All @@ -18,18 +14,6 @@ with builtins; with lib;
default = true;
description = "Include Windows PATH in WSL PATH";
};

preserveArgvZero = mkOption {
type = nullOr bool;
default = null;
description = ''
Register binfmt interpreter for Windows executables with 'preserves argv[0]' flag.
Default (null): autodetect, at some performance cost.
To avoid the performance cost, set this to true for WSL Preview 0.58 and up,
or to false for any older versions, including pre-Microsoft Store and Windows 10.
'';
};
};

config =
Expand All @@ -39,39 +23,13 @@ with builtins; with lib;
mkIf config.wsl.enable {

boot.binfmt.registrations = mkIf cfg.register {
WSLInterop =
let
compat = cfg.preserveArgvZero;

# WSL Preview 0.58 and up registers the /init binfmt interp for Windows executable
# with the "preserve argv[0]" flag, so if you run `./foo.exe`, the interp gets invoked
# as `/init foo.exe ./foo.exe`.
# argv[0] --^ ^-- actual path
#
# Older versions expect to be called without the argv[0] bit, simply as `/init ./foo.exe`.
#
# We detect that by running `/init /known-not-existing-path.exe` and checking the exit code:
# the new style interp expects at least two arguments, so exits with exit code 1,
# presumably meaning "parsing error"; the old style interp attempts to actually run
# the executable, fails to find it, and exits with 255.
compatWrapper = pkgs.writeShellScript "nixos-wsl-binfmt-hack" ''
/init /nixos-wsl-does-not-exist.exe
[ $? -eq 255 ] && shift
exec /init "$@"
'';

# use the autodetect hack if unset, otherwise call /init directly
interpreter = if compat == null then compatWrapper else "/init";

# enable for the wrapper and autodetect hack
preserveArgvZero = if compat == false then false else true;
in
{
magicOrExtension = "MZ";
fixBinary = true;
wrapInterpreterInShell = false;
inherit interpreter preserveArgvZero;
};
WSLInterop = {
magicOrExtension = "MZ";
fixBinary = true;
wrapInterpreterInShell = false;
interpreter = "/init";
preserveArgvZero = true;
};
};

warnings =
Expand Down
11 changes: 2 additions & 9 deletions modules/systemd-tarball.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let
mkdir -m 0700 -p ./root/.nix-defexpr
ln -s /nix/var/nix/profiles/per-user/root/channels ./root/.nix-defexpr/channels
mkdir -p sbin nix/nixos-wsl/entrypoint
mkdir -p sbin
ln -s ${pkgs.wslNativeUtils}/bin/systemd-shim ./sbin/init
${lib.optionalString config.wsl.tarball.includeConfig ''
Expand All @@ -50,13 +50,7 @@ in
{

config = mkIf config.wsl.enable {
assertions = [{
assertion = config.wsl.nativeSystemd;
message = "config.wsl.nativeSystemd must be true in order to build a systemd-tarball!";
}];

system.build.systemd-tarball = pkgs.callPackage "${nixpkgs}/nixos/lib/make-system-tarball.nix" {

system.build.tarball = pkgs.callPackage "${nixpkgs}/nixos/lib/make-system-tarball.nix" {
contents = [
# WSL needs this before first activation
{ inherit (config.environment.etc."wsl.conf") source; target = "/etc/wsl.conf"; }
Expand All @@ -71,7 +65,6 @@ in
];

extraCommands = "${preparer}/bin/wsl-prepare";
extraArgs = "--hard-dereference";

# Use gzip
compressCommand = "gzip";
Expand Down
Loading

0 comments on commit c78cffa

Please sign in to comment.