From 07ab279d008e251120ed7f20b145c4855f4ac086 Mon Sep 17 00:00:00 2001 From: Tyler Starr Date: Fri, 27 Sep 2024 15:25:33 -0700 Subject: [PATCH] basic wsl config --- provision/flake.lock | 72 +++++++++++++++++++++++++++ provision/flake.nix | 8 ++- provision/hosts/wsl/configuration.nix | 57 +++++++++++++++++++++ provision/hosts/wsl/default.nix | 21 ++++++++ 4 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 provision/hosts/wsl/configuration.nix create mode 100644 provision/hosts/wsl/default.nix diff --git a/provision/flake.lock b/provision/flake.lock index c652a0b5..7509496c 100644 --- a/provision/flake.lock +++ b/provision/flake.lock @@ -43,6 +43,40 @@ "type": "github" } }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -101,6 +135,28 @@ "url": "https://github.com/Jovian-Experiments/Jovian-NixOS" } }, + "nixos-wsl": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1727464323, + "narHash": "sha256-XhiLvnM95aNpRm3qJ9hsVV/prin4GVapn4snMN4Ol6k=", + "owner": "nix-community", + "repo": "NixOS-WSL", + "rev": "4aef94d5afb4a791e5e9a3ee844c68ad01f54a14", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "NixOS-WSL", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1703013332, @@ -138,6 +194,7 @@ "agenix": "agenix", "home-manager": "home-manager_2", "jovian-nixos": "jovian-nixos", + "nixos-wsl": "nixos-wsl", "nixpkgs": "nixpkgs_2" } }, @@ -155,6 +212,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/provision/flake.nix b/provision/flake.nix index d67579b3..25ac2dd9 100644 --- a/provision/flake.nix +++ b/provision/flake.nix @@ -8,9 +8,11 @@ home-manager.inputs.nixpkgs.follows = "nixpkgs"; jovian-nixos.url = "git+https://github.com/Jovian-Experiments/Jovian-NixOS?ref=development"; jovian-nixos.flake = false; + nixos-wsl.url = "github:nix-community/NixOS-WSL"; + nixos-wsl.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = inputs @ { self, nixpkgs, home-manager, jovian-nixos, agenix, ... }: + outputs = inputs @ { self, nixpkgs, home-manager, jovian-nixos, agenix, nixos-wsl, ... }: let system = "x86_64-linux"; user = "tstarr"; @@ -33,6 +35,10 @@ inherit lib; inherit system user inputs agenix home-manager jovian-nixos; }); + wsl = lib.nixosSystem (import ./hosts/wsl { + inherit lib; + inherit system user inputs agenix home-manager nixos-wsl; + }); }; }; } diff --git a/provision/hosts/wsl/configuration.nix b/provision/hosts/wsl/configuration.nix new file mode 100644 index 00000000..7748a008 --- /dev/null +++ b/provision/hosts/wsl/configuration.nix @@ -0,0 +1,57 @@ +{ config, pkgs, user, lib, inputs, nixos-wsl, ... }: +let + defaultUser = user; +in +{ + imports = [ + nixos-wsl.nixosModules.wsl + ]; + + wsl = { + inherit defaultUser; + + enable = true; + wslConf.automount.root = "/mnt"; + }; + + # Set networking options + networking.hostName = "wsl"; + networking.firewall.checkReversePath = "loose"; + networking.firewall.enable = false; + + boot.isContainer = true; + + # configure root + users.users.root = { + 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; + + environment.systemPackages = with pkgs; [ + ]; + + # Modules + modules = { + devel = { + python.enable = true; + tooling.enable = true; + }; + system = { + ssh.enable = true; + terminal.enable = true; + }; + }; +} diff --git a/provision/hosts/wsl/default.nix b/provision/hosts/wsl/default.nix new file mode 100644 index 00000000..474d520a --- /dev/null +++ b/provision/hosts/wsl/default.nix @@ -0,0 +1,21 @@ +{ lib, system, user, inputs, agenix, home-manager, nixos-wsl, ... }: +{ + inherit system; + specialArgs = { inherit user inputs nixos-wsl; }; + modules = [ + ../default # shared by all configs + ./configuration.nix # wsl specific + ../../modules + agenix.nixosModules.default + home-manager.nixosModules.home-manager { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { inherit user; }; + home-manager.users.${user} = { + imports = [ + ../../home-modules + ]; + }; + } + ]; +}