Update wsl work configuration

This commit is contained in:
Michael Thomas 2022-05-23 09:50:59 -04:00
parent 3bd412ef0e
commit 1eea1ceaba
6 changed files with 85 additions and 82 deletions

72
flake.lock generated
View File

@ -1,5 +1,36 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1648199409,
"narHash": "sha256-JwPKdC2PoVBkG6E+eWw3j6BMR6sL3COpYWfif7RVb8Y=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "64a525ee38886ab9028e6f61790de0832aa3ef03",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1649676176,
"narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
@ -21,13 +52,35 @@
"type": "github"
}
},
"nixos-wsl": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1651742999,
"narHash": "sha256-d0q2KpnJCXLLlzbEEEKe5IA2UfMXxwT/S92QwzBGn84=",
"owner": "nix-community",
"repo": "NixOS-WSL",
"rev": "bbf02821ee42fd8aff0568b844a9712cbdf07bb2",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "NixOS-WSL",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1651848520,
"narHash": "sha256-KkJ28fShdd78+zal5HlHsXUICOCtO7Bdvylc5zlp5Mk=",
"lastModified": 1653087707,
"narHash": "sha256-zfno3snrzZTWQ2B7K53QHrGZwrjnJLTRPalymrSsziU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "5656d7f92aa8264eb06ba68ad94c87ac5b5312e8",
"rev": "cbd40c72b2603ab54e7208f99f9b35fc158bc009",
"type": "github"
},
"original": {
@ -39,11 +92,11 @@
},
"nur": {
"locked": {
"lastModified": 1651887110,
"narHash": "sha256-AMQ0A5Osq647zEHWb+GZEIYZeNrZm55kY24uVOqSTzg=",
"lastModified": 1653301395,
"narHash": "sha256-T/RZd2MLugtJtZwXOSSwUIQdf2R95j8mj9LxGvKnvnM=",
"owner": "nix-community",
"repo": "NUR",
"rev": "c7a43bc69e52a636e76ba3d378695c1bd4f0bbbd",
"rev": "2d836739ddb17a69e865c3cc2ca21d3a8bf5db78",
"type": "github"
},
"original": {
@ -55,6 +108,7 @@
"root": {
"inputs": {
"home-manager": "home-manager",
"nixos-wsl": "nixos-wsl",
"nixpkgs": "nixpkgs",
"nur": "nur",
"unstable": "unstable"
@ -62,11 +116,11 @@
},
"unstable": {
"locked": {
"lastModified": 1651726670,
"narHash": "sha256-dSGdzB49SEvdOJvrQWfQYkAefewXraHIV08Vz6iDXWQ=",
"lastModified": 1653060744,
"narHash": "sha256-kfRusllRumpt33J1hPV+CeCCylCXEU7e0gn2/cIM7cY=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "c777cdf5c564015d5f63b09cc93bef4178b19b01",
"rev": "dfd82985c273aac6eced03625f454b334daae2e8",
"type": "github"
},
"original": {

View File

@ -6,6 +6,13 @@
unstable.url = "github:nixos/nixpkgs/nixos-unstable";
nur.url = "github:nix-community/NUR";
nixos-wsl = {
url = "github:nix-community/NixOS-WSL";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
home-manager = {
url = "github:rycee/home-manager/release-21.11";
inputs = {
@ -14,7 +21,7 @@
};
};
outputs = { self, nixpkgs, unstable, nur, home-manager, ... }@inputs: {
outputs = { self, nixpkgs, unstable, nur, nixos-wsl, home-manager, ... }@inputs: {
# This repo's overlay plus any other overlays you use
# If you want to use packages from flakes that are not nixpkgs (such as NUR), add their overlays here.

View File

@ -1,25 +1,29 @@
{ lib, pkgs, config, modulesPath, ... }:
{ lib, pkgs, config, modulesPath, inputs, ... }:
with lib;
let
defaultUser = "michael";
syschdemd = import ./syschdemd.nix { inherit lib pkgs config defaultUser; };
in
{
imports = [
"${modulesPath}/profiles/minimal.nix"
inputs.nixos-wsl.nixosModules.wsl
];
# WSL is closer to a container than anything else
boot.isContainer = true;
wsl = {
enable = true;
automountPath = "/mnt";
defaultUser = defaultUser;
startMenuLaunchers = true;
environment.etc.hosts.enable = false;
environment.etc."resolv.conf".enable = false;
# Enable integration with Docker Desktop (needs to be installed)
# docker.enable = true;
};
time.timeZone = "America/New_York";
programs.adb.enable = true;
networking.dhcpcd.enable = false;
# Required because for some reason WSL kernel doesn't play well with nftables
networking.firewall.package = pkgs.iptables-legacy;
@ -40,29 +44,8 @@ in
};
users.users.${defaultUser} = {
isNormalUser = true;
uid = pkgs.lib.mkForce 1001;
extraGroups = [ "wheel" "docker" "podman" ];
shell = pkgs.zsh;
};
users.users.root = {
shell = "${syschdemd}/bin/syschdemd";
# Otherwise WSL fails to login as root with "initgroups failed 5"
extraGroups = [ "root" ];
};
security.sudo.wheelNeedsPassword = false;
# Disable systemd units that don't make sense on WSL
systemd.services."serial-getty@ttyS0".enable = false;
systemd.services."serial-getty@hvc0".enable = false;
systemd.services."getty@tty1".enable = false;
systemd.services."autovt@".enable = false;
systemd.services.firewall.enable = false;
systemd.services.systemd-resolved.enable = false;
systemd.services.systemd-udevd.enable = false;
# Don't allow emergency mode, because we don't have a console.
systemd.enableEmergencyMode = false;
}

View File

@ -1,15 +0,0 @@
{ lib, pkgs, config, defaultUser, ... }:
pkgs.substituteAll {
name = "syschdemd";
src = ./syschdemd.sh;
dir = "bin";
isExecutable = true;
buildInputs = with pkgs; [ daemonize ];
inherit (pkgs) daemonize;
inherit defaultUser;
inherit (config.security) wrapperDir;
fsPackagesPath = lib.makeBinPath config.system.fsPackages;
}

View File

@ -1,26 +0,0 @@
#! @shell@
set -e
sw="/nix/var/nix/profiles/system/sw/bin"
systemPath=`${sw}/readlink -f /nix/var/nix/profiles/system`
# Needs root to work
if [[ $EUID -ne 0 ]]; then
echo "[ERROR] Requires root! :( Make sure the WSL default user is set to root"
exit 1
fi
if [ ! -e "/run/current-system" ]; then
/nix/var/nix/profiles/system/activate
fi
if [ ! -e "/run/systemd.pid" ]; then
PATH=/run/current-system/systemd/lib/systemd:@fsPackagesPath@ \
LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \
@daemonize@/bin/daemonize /run/current-system/sw/bin/unshare -fp --mount-proc systemd
/run/current-system/sw/bin/pgrep -xf systemd > /run/systemd.pid
fi
userShell=$($sw/getent passwd @defaultUser@ | $sw/cut -d: -f7)
exec $sw/nsenter -t $(< /run/systemd.pid) -p -m --wd="$PWD" -- @wrapperDir@/su -s $userShell @defaultUser@ "$@"

View File

@ -2,10 +2,10 @@
{
nix = {
extraOptions = ''
experimental-features = flakes nix-command
experimental-features = flakes nix-command
'';
# this is required until nix 2.4 is released
package = pkgs.nixUnstable;
package = pkgs.nixFlakes;
autoOptimiseStore = true;
gc = {