From bf41ee6e0a69522828e37b9cb608d6a072b8ed33 Mon Sep 17 00:00:00 2001 From: yukkop Date: Sat, 28 Feb 2026 01:57:42 +0000 Subject: [PATCH] feat: merge own wsl config --- flake.lock | 38 ++++++ flake.nix | 5 + nixos/module/generic/postgresql.nix | 2 +- nixos/module/hectic/hardware/cloudzy.nix | 2 +- .../module/hectic/hardware/hetzner-cloud.nix | 4 +- nixos/module/hectic/hardware/zombro.nix | 29 ++-- nixos/module/hectic/program/zsh.nix | 48 ++++--- nixos/module/hectic/service/sentinèlla.nix | 2 +- nixos/module/hectic/service/support-bot.nix | 2 +- nixos/module/hectic/user/yukkop.nix | 128 ++++++++---------- nixos/system/bfs/bfs.nix | 27 ++-- nixos/system/neuro/neuro.nix | 2 +- nixos/system/wsl/default.nix | 23 ++++ nixos/system/wsl/wsl.nix | 89 ++++++++++++ 14 files changed, 272 insertions(+), 129 deletions(-) create mode 100644 nixos/system/wsl/default.nix create mode 100644 nixos/system/wsl/wsl.nix diff --git a/flake.lock b/flake.lock index 7e8e0b4..b8c8bfa 100644 --- a/flake.lock +++ b/flake.lock @@ -145,6 +145,22 @@ "type": "github" } }, + "flake-compat_4": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -693,6 +709,27 @@ "type": "github" } }, + "nixos-wsl": { + "inputs": { + "flake-compat": "flake-compat_4", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1771563879, + "narHash": "sha256-vA5hocvdGhr+jfBN7A7ogeZqIz2qx01EixXwdVsQcnE=", + "owner": "nix-community", + "repo": "NixOS-WSL", + "rev": "379d20c55f552e91fb9f3f0382e4a97d3f452943", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "NixOS-WSL", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1748929857, @@ -821,6 +858,7 @@ "nix-minecraft": "nix-minecraft", "nixos-anywhere": "nixos-anywhere", "nixos-hardware": "nixos-hardware", + "nixos-wsl": "nixos-wsl", "nixpkgs": "nixpkgs_2", "nixpkgs-fixed": "nixpkgs-fixed", "nixvim": "nixvim", diff --git a/flake.nix b/flake.nix index f698c52..e93f324 100644 --- a/flake.nix +++ b/flake.nix @@ -32,6 +32,10 @@ url = "github:nix-community/home-manager/release-25.11"; inputs.nixpkgs.follows = "nixpkgs-fixed"; }; + nixos-wsl = { + url = "github:nix-community/NixOS-WSL"; + inputs.nixpkgs.follows = "nixpkgs"; + }; nixos-hardware = { url = "github:NixOS/nixos-hardware"; }; @@ -88,6 +92,7 @@ # FIXME(yukkop): some why I cannot merge nixosConfigurations from `forAllSystemsWithPkgs` with this "neuro|x86_64-linux" = import ./nixos/system/neuro { inherit flake self inputs; system = "x86_64-linux"; }; "games|x86_64-linux" = import ./nixos/system/games { inherit flake self inputs; system = "x86_64-linux"; }; + "wsl|x86_64-linux" = import ./nixos/system/wsl { inherit flake self inputs; system = "x86_64-linux"; }; }; }; } diff --git a/nixos/module/generic/postgresql.nix b/nixos/module/generic/postgresql.nix index 6ffe3a5..2f5c093 100644 --- a/nixos/module/generic/postgresql.nix +++ b/nixos/module/generic/postgresql.nix @@ -9,7 +9,7 @@ lib, ... }: let - system = pkgs.system; + system = pkgs.stdenv.hostPlatform.system; cfg = config.services.postgresql; extensionFlags = { pg_cron = false; diff --git a/nixos/module/hectic/hardware/cloudzy.nix b/nixos/module/hectic/hardware/cloudzy.nix index a4868b4..cd8f881 100644 --- a/nixos/module/hectic/hardware/cloudzy.nix +++ b/nixos/module/hectic/hardware/cloudzy.nix @@ -112,6 +112,6 @@ in { "ata_piix" "uhci_hcd" "xen_blkfront" - ] ++ (if pkgs.system != "aarch64-linux" then [ "vmw_pvscsi" ] else []); + ] ++ (if pkgs.stdenv.hostPlatform.system != "aarch64-linux" then [ "vmw_pvscsi" ] else []); }; } diff --git a/nixos/module/hectic/hardware/hetzner-cloud.nix b/nixos/module/hectic/hardware/hetzner-cloud.nix index 525fe27..2d0a205 100644 --- a/nixos/module/hectic/hardware/hetzner-cloud.nix +++ b/nixos/module/hectic/hardware/hetzner-cloud.nix @@ -71,7 +71,7 @@ in { "ata_piix" "uhci_hcd" "xen_blkfront" - ] ++ (if pkgs.system != "aarch64-linux" then [ "vmw_pvscsi" ] else []); + ] ++ (if pkgs.stdenv.hostPlatform.system != "aarch64-linux" then [ "vmw_pvscsi" ] else []); networking.useDHCP = false; networking.useNetworkd = true; @@ -125,7 +125,7 @@ in { }; }; } - (lib.mkIf (pkgs.system == "aarch64-linux") { + (lib.mkIf (pkgs.stdenv.hostPlatform.system == "aarch64-linux") { boot.initrd.kernelModules = [ "virtio_gpu" ]; boot.kernelParams = [ "console=tty" ]; }) diff --git a/nixos/module/hectic/hardware/zombro.nix b/nixos/module/hectic/hardware/zombro.nix index ca54d1a..a9ca30d 100644 --- a/nixos/module/hectic/hardware/zombro.nix +++ b/nixos/module/hectic/hardware/zombro.nix @@ -35,33 +35,34 @@ in { "ata_piix" "uhci_hcd" "xen_blkfront" - ] ++ (if pkgs.system != "aarch64-linux" then [ "vmw_pvscsi" ] else []); + ] ++ (if pkgs.stdenv.hostPlatform.system != "aarch64-linux" then [ "vmw_pvscsi" ] else []); boot.initrd.kernelModules = ["nvme"]; disko.devices = { disk.master = { device = cfg.device; content = { - type = "table"; - format = "msdos"; - partitions = [ - { - name = "root"; - part-type = "primary"; - fs-type = "ext4"; - bootable = true; + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; + priority = 1; + }; + root = { + size = "100%"; content = { - type = "filesystem"; - format = "ext4"; + type = "filesystem"; + format = "ext4"; mountpoint = "/"; }; - } - ]; + }; + }; }; }; }; } - (lib.mkIf (pkgs.system == "aarch64-linux") { + (lib.mkIf (pkgs.stdenv.hostPlatform.system == "aarch64-linux") { boot.initrd.kernelModules = [ "virtio_gpu" ]; boot.kernelParams = [ "console=tty" ]; }) diff --git a/nixos/module/hectic/program/zsh.nix b/nixos/module/hectic/program/zsh.nix index 07e8c7e..3263539 100644 --- a/nixos/module/hectic/program/zsh.nix +++ b/nixos/module/hectic/program/zsh.nix @@ -21,31 +21,35 @@ in { programs.zsh.enable = true; users.defaultUserShell = pkgs.zsh; - home-manager.users.root = { - home.stateVersion = lib.mkDefault "25.05"; + # Share the same zsh config with all home-manager users + home-manager.sharedModules = [ + { + programs.zsh = { + enable = true; + enableCompletion = true; + autosuggestion.enable = true; + syntaxHighlighting.enable = true; - programs.zsh = { - enable = true; - enableCompletion = true; - autosuggestion.enable = true; - syntaxHighlighting.enable = true; + history = { + size = 10000; + path = "$HOME/.zsh/.zsh_history"; + }; - history = { - size = 10000; - path = "$HOME/.zsh/.zsh_history"; + oh-my-zsh = { + enable = true; + theme = "terminalparty"; + }; + + shellAliases = self.lib.sharedShellAliases; + + initContent = '' + set -ovi + ''; }; + } + ]; - oh-my-zsh = { - enable = true; - theme = "terminalparty"; - }; - - shellAliases = self.lib.sharedShellAliases; - - initContent = '' - set -ovi - ''; - }; - }; + # Still define root for stateVersion; config comes from sharedModules + home-manager.users.root.home.stateVersion = lib.mkDefault "25.05"; }; } diff --git a/nixos/module/hectic/service/sentinèlla.nix b/nixos/module/hectic/service/sentinèlla.nix index 02b3530..f7b22da 100644 --- a/nixos/module/hectic/service/sentinèlla.nix +++ b/nixos/module/hectic/service/sentinèlla.nix @@ -9,7 +9,7 @@ config, ... }: let - system = pkgs.system; + system = pkgs.stdenv.hostPlatform.system; cfg = config.hectic.services."sentinèlla"; # URLS="http://..." # default: none # VOLUMES="/ /home" # default: all from df -P diff --git a/nixos/module/hectic/service/support-bot.nix b/nixos/module/hectic/service/support-bot.nix index 08caa5f..6158b44 100644 --- a/nixos/module/hectic/service/support-bot.nix +++ b/nixos/module/hectic/service/support-bot.nix @@ -1,7 +1,7 @@ { inputs, flake, self }: { config, pkgs, lib, ... }: let cfg = config.hectic.services.support-bot; - system = pkgs.system; + system = pkgs.stdenv.hostPlatform.system; packagesAttr = lib.mapAttrs (packageName: packageConfig: packageConfig // { diff --git a/nixos/module/hectic/user/yukkop.nix b/nixos/module/hectic/user/yukkop.nix index 33d07b2..2dfbda7 100644 --- a/nixos/module/hectic/user/yukkop.nix +++ b/nixos/module/hectic/user/yukkop.nix @@ -1,4 +1,4 @@ -{ +{ self, inputs, ... @@ -8,90 +8,72 @@ pkgs, lib, ... -}: let - name = builtins.baseNameOf ./.; +}: let + name = "yukkop"; + #name = builtins.baseNameOf ./.; home = "/home/${name}"; cfg = config.hectic.user.yukkop; in { + imports = [ + inputs.home-manager.nixosModules.home-manager + ]; + options.hectic.user.yukkop.enable = lib.mkEnableOption "Enable user.yukkop"; config = lib.mkIf cfg.enable { - #home = { - # username = name; - # homeDirectory = home; - # packages = []; - # stateVersion = "25.05"; - #}; + users.users.${name} = { + isNormalUser = true; + initialPassword = "kk"; + extraGroups = [ "wheel" "docker" "owner" ]; + }; - #xdg = { - # enable = true; - # userDirs = { - # enable = true; - # pictures = "${home}/px"; - # videos = "${home}/vd"; - # music = "${home}/mu"; - # documents = "${home}/dc"; - # downloads = "${home}/dw"; - # desktop = "${home}/dx"; - # publicShare = "${home}/pu"; - # templates = "${config.xdg.dataHome}/templates"; - # }; - # mimeApps = { - # enable = true; - # defaultApplications = { + home-manager.users.${name} = { + home.stateVersion = "24.05"; - # # Files - # "application/x-shellscript" = [ "nvim.desktop" ]; - # "text/x-shellscript" = [ "nvim.desktop" ]; - # "text/plain" = [ "nvim.desktop" ]; - # "inode/directory" = [ "pcmanfm.desktop" ]; + home.packages = with pkgs; [ + pinentry-tty + ]; - # # Images - # "image/png" = [ "sxiv.desktop" ]; - # "image/jpeg" = [ "sxiv.desktop" ]; - # "image/gif" = [ "sxiv.desktop" ]; - # "image/webp" = [ "sxiv.desktop" ]; - # "image/x-xcf" = [ "gimp.desktop" ]; + programs.password-store = { + enable = true; + package = (pkgs.pass.override { + x11Support = false; + waylandSupport = false; + dmenuSupport = false; + }).withExtensions (exts: with exts; [ + pass-otp + ]); + settings.PASSWORD_STORE_DIR = "${home}/.pass"; + }; - # # Videos - # "video/x-matroska" = [ "mpv.desktop" ]; + programs.gpg = { + enable = true; + homedir = "${home}/.gnupg"; + }; - # # # Application-specific - # # "application/postscript" = [ "pdf.desktop" ]; - # # "application/pdf" = [ "pdf.desktop" ]; - # # "application/rss+xml" = [ "rss.desktop" ]; - # # "application/x-bittorrent" = [ "torrent.desktop" ]; + services.gpg-agent = { + enable = true; + pinentryPackage = pkgs.pinentry-tty; + enableZshIntegration = true; + defaultCacheTtl = 60 * 60; + maxCacheTtl = 60 * 60 * 24; + }; - # # Protocols - # "x-scheme-handler/http" = [ "firefox.desktop" ]; - # "x-scheme-handler/https" = [ "firefox.desktop" ]; - # # "x-scheme-handler/magnet" = [ "torrent.desktop" ]; - # # "x-scheme-handler/mailto" = [ "mail.desktop" ]; - # # "x-scheme-handler/lbry" = [ "lbry.desktop" ]; - # # "x-scheme-handler/tg" = [ "telegram.desktop" ]; + programs.bash.shellAliases = { + dev = "nix develop -c zsh"; + # system-specific rebuild aliases can be added per-system + }; - # # text/x-shellscript=text.desktop; - # # x-scheme-handler/magnet=torrent.desktop; - # # application/x-bittorrent=torrent.desktop; - # # x-scheme-handler/mailto=mail.desktop; - # # text/plain=text.desktop; - # # application/postscript=pdf.desktop; - # # application/pdf=pdf.desktop; - # # image/png=img.desktop; - # # image/jpeg=img.desktop; - # # image/gif=img.desktop; - # # image/webp=img.desktop; - # # application/rss+xml=rss.desktop; - # # video/x-matroska=video.desktop; - # # x-scheme-handler/lbry=lbry.desktop; - # # inode/directory=file.desktop; - # # text/html=chromium.desktop; - # # x-scheme-handler/http=chromium.desktop; - # # x-scheme-handler/https=chromium.desktop; - # # x-scheme-handler/about=chromium.desktop; - # # x-scheme-handler/unknown=chromium.desktop; - # }; - # }; - #}; + programs.git = { + enable = true; + lfs.enable = true; + userName = "yukkop"; + userEmail = "hectic.yukkop@gmail.com"; + extraConfig = { + push.autoSetupRemote = true; + init.defaultBranch = "master"; + }; + }; + }; }; } diff --git a/nixos/system/bfs/bfs.nix b/nixos/system/bfs/bfs.nix index 6cb4381..8ceaf98 100644 --- a/nixos/system/bfs/bfs.nix +++ b/nixos/system/bfs/bfs.nix @@ -54,28 +54,29 @@ in { "ata_piix" "uhci_hcd" "xen_blkfront" - ] ++ (if pkgs.system != "aarch64-linux" then [ "vmw_pvscsi" ] else []); + ] ++ (if pkgs.stdenv.hostPlatform.system != "aarch64-linux" then [ "vmw_pvscsi" ] else []); boot.initrd.kernelModules = ["nvme"]; disko.devices = { disk.vda = { device = lib.mkDefault "/dev/vda"; content = { - type = "table"; - format = "msdos"; - partitions = [ - { - name = "root"; - part-type = "primary"; - fs-type = "ext4"; - bootable = true; + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; + priority = 1; + }; + root = { + size = "100%"; content = { - type = "filesystem"; - format = "ext4"; + type = "filesystem"; + format = "ext4"; mountpoint = "/"; }; - } - ]; + }; + }; }; }; }; diff --git a/nixos/system/neuro/neuro.nix b/nixos/system/neuro/neuro.nix index 6e29c90..9bea8c5 100644 --- a/nixos/system/neuro/neuro.nix +++ b/nixos/system/neuro/neuro.nix @@ -8,7 +8,7 @@ modulesPath, config, ... -}: let system = pkgs.system; in { +}: let system = pkgs.stdenv.hostPlatform.system; in { imports = [ self.nixosModules.hectic inputs.sops-nix.nixosModules.sops diff --git a/nixos/system/wsl/default.nix b/nixos/system/wsl/default.nix new file mode 100644 index 0000000..831c67b --- /dev/null +++ b/nixos/system/wsl/default.nix @@ -0,0 +1,23 @@ +{ + flake, + self, + inputs, + system, + ... +}: let + # Use folder name as system name + name = builtins.baseNameOf ./.; + +in self.lib.nixpkgs-lib.nixosSystem { + pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ self.overlays.default ]; + config.allowUnfree = true; + }; + modules = [ + { networking.hostName = name; } + inputs.nixos-wsl.nixosModules.default + { wsl.enable = true; } + (import ./${name}.nix { inherit flake self inputs; }) + ]; +} diff --git a/nixos/system/wsl/wsl.nix b/nixos/system/wsl/wsl.nix new file mode 100644 index 0000000..4fd995a --- /dev/null +++ b/nixos/system/wsl/wsl.nix @@ -0,0 +1,89 @@ +{ + inputs, + flake, + self, +}: { + lib, + pkgs, + config, + ... +}: { + imports = [ + self.nixosModules.hectic + ]; + + hectic = { + archetype.base.enable = true; + program.zsh.enable = true; + program.nixvim.enable = true; + user.yukkop.enable = true; + }; + + wsl.defaultUser = "yukkop"; + + # 16 GiB swap + swapDevices = [{ + device = "/var/lib/swapfile"; + size = 16 * 1024; + }]; + + users.groups.owner = {}; + + services.openssh = { + enable = true; + settings = { + PasswordAuthentication = false; + UseDns = true; + X11Forwarding = false; + PermitRootLogin = "no"; + }; + }; + + virtualisation.docker.enable = true; + + hardware.opengl.enable = true; + + console.keyMap = "us"; + + environment.systemPackages = with pkgs; [ + ripgrep + man-pages + man-pages-posix + man-db + ffmpeg + ]; + + documentation.dev.enable = true; + documentation.man.man-db.enable = false; + documentation.man.mandoc.enable = true; + + services.samba = { + enable = true; + shares.sshfs = { + path = "/home/yukkop/umbriel/vproxy"; + browseable = true; + "read only" = false; + "guest ok" = true; + }; + }; + + networking.firewall.allowedTCPPorts = [ 139 445 ]; + networking.firewall.allowedUDPPorts = [ 137 138 ]; + + fonts.packages = with pkgs; [ + nerd-fonts.jetbrains-mono + ]; + + environment.variables = { + EDITOR = "nvim"; + VISUAL = "nvim"; + }; + + # WSL-local shell aliases + programs.bash.shellAliases = { + nrs = "sudo nixos-rebuild switch --flake /home/yukkop/pj/util.nix#wsl"; + }; + + # WSL: keep imperative stateVersion in the system module + system.stateVersion = "25.05"; +}