From c7bcd25914a74e4b2d9fe52ab147679d754c187e Mon Sep 17 00:00:00 2001 From: rocketcamel Date: Tue, 21 Jan 2025 04:32:14 +0000 Subject: [PATCH] Setup WSL Host --- nix/configuration.nix | 26 ++++++++++++++++++++ nix/flake.nix | 37 ++++++++++++++++++++++++++++ nix/users/luca/git.nix | 13 ++++++++++ nix/users/luca/helix.nix | 53 ++++++++++++++++++++++++++++++++++++++++ nix/users/luca/home.nix | 25 +++++++++++++++++++ nix/users/luca/tmux.nix | 16 ++++++++++++ nix/users/luca/zsh.nix | 9 +++++++ nix/wsl.nix | 4 +++ 8 files changed, 183 insertions(+) create mode 100644 nix/configuration.nix create mode 100644 nix/flake.nix create mode 100755 nix/users/luca/git.nix create mode 100755 nix/users/luca/helix.nix create mode 100755 nix/users/luca/home.nix create mode 100755 nix/users/luca/tmux.nix create mode 100644 nix/users/luca/zsh.nix create mode 100644 nix/wsl.nix diff --git a/nix/configuration.nix b/nix/configuration.nix new file mode 100644 index 0000000..b844ac5 --- /dev/null +++ b/nix/configuration.nix @@ -0,0 +1,26 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page, on +# https://search.nixos.org/options and in the NixOS manual (`nixos-help`). + +{ config, lib, pkgs, meta, ... }: + +{ + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + environment.systemPackages = with pkgs; [ wget busybox ]; + programs.nix-ld.enable = true; + networking.hostName = meta.hostname; + + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.luca = import ./users/luca/home.nix; + users.users.luca.shell = pkgs.zsh; + programs.zsh.enable = true; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It's perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "24.05"; # Did you read the comment? +} diff --git a/nix/flake.nix b/nix/flake.nix new file mode 100644 index 0000000..2bc8daa --- /dev/null +++ b/nix/flake.nix @@ -0,0 +1,37 @@ +{ + description = "Top level flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + nixos-wsl.url = "github:nix-community/NixOS-WSL/main"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = inputs@{ nixpkgs, ... }: + let + systems = [ "x86_64-linux" ]; + hosts = [{ + name = "wsl-kumatani"; + isWSL = true; + }]; + in { + nixosConfigurations = builtins.listToAttrs (map (host: { + name = host.name; + value = nixpkgs.lib.nixosSystem { + specialArgs = { + inherit inputs outputs; + meta = { hostname = host.name; }; + }; + system = "x86_64-linux"; + modules = + [ ./configuration.nix home-manager.nixosModules.home-manager ] + ++ (if host.isWSL then [ + ./wsl.nix + nixos-wsl.nixosModules.default + ] else + [ ]); + }; + }) hosts); + }; +} diff --git a/nix/users/luca/git.nix b/nix/users/luca/git.nix new file mode 100755 index 0000000..2ccd69f --- /dev/null +++ b/nix/users/luca/git.nix @@ -0,0 +1,13 @@ +{ + enable = true; + userName = "rocketcamel"; + userEmail = "luca_lise@icloud.com"; + extraConfig = { + init = { + defaultBranch = "main"; + }; + commit.gpgsign = true; + gpg.format = "ssh"; + user.signingkey = "~/.ssh/commits.id_rsa.pub"; + }; +} diff --git a/nix/users/luca/helix.nix b/nix/users/luca/helix.nix new file mode 100755 index 0000000..da12719 --- /dev/null +++ b/nix/users/luca/helix.nix @@ -0,0 +1,53 @@ +{ pkgs, ... }: + +{ + enable = true; + languages.language = [ + { + name = "nix"; + auto-format = true; + formatter.command = "${pkgs.nixfmt}/bin/nixfmt"; + } + { + name = "typescript"; + auto-format = true; + formatter = { + command = "${pkgs.nodePackages_latest.prettier}/bin/prettier"; + args = [ "--parser" "typescript" ]; + }; + } + { + name = "tsx"; + auto-format = true; + formatter = { + command = "${pkgs.nodePackages_latest.prettier}/bin/prettier"; + args = [ "--parser" "typescript" ]; + }; + } + ]; + settings = { + theme = "rose_pine"; + editor = { + true-color = true; + line-number = "relative"; + lsp.display-messages = true; + cursor-shape = { + insert = "block"; + normal = "block"; + }; + }; + keys.normal = { + space.q = ":q"; + w = [ "move_next_word_start" "move_char_right" "collapse_selection" ]; + b = [ "move_prev_word_start" "collapse_selection" ]; + i = [ "insert_mode" "collapse_selection" ]; + a = [ "append_mode" "collapse_selection" ]; + }; + }; + themes = { + rose_pine = { + inherits = "rose_pine"; + "ui.background" = "transparent"; + }; + }; +} diff --git a/nix/users/luca/home.nix b/nix/users/luca/home.nix new file mode 100755 index 0000000..6f6890b --- /dev/null +++ b/nix/users/luca/home.nix @@ -0,0 +1,25 @@ +{ config, pkgs, ... }: + +{ + home.username = "luca"; + home.homeDirectory = "/home/luca"; + + programs = { + git = import ./git.nix; + zsh = import ./zsh.nix; + tmux = import ./tmux.nix { inherit pkgs; }; + helix = import ./helix.nix { inherit pkgs; }; + }; + + home.packages = with pkgs; [ + nodePackages_latest.typescript-language-server + nodejs_22 + pnpm + gh + oh-my-posh + ]; + + home.stateVersion = "24.11"; + + programs.home-manager.enable = true; +} diff --git a/nix/users/luca/tmux.nix b/nix/users/luca/tmux.nix new file mode 100755 index 0000000..cbf6a5c --- /dev/null +++ b/nix/users/luca/tmux.nix @@ -0,0 +1,16 @@ +{ pkgs, ... }: + +{ + enable = true; + prefix = "C-Space"; + mouse = true; + baseIndex = 1; + sensibleOnTop = true; + keyMode = "vi"; + plugins = with pkgs; [{ plugin = tmuxPlugins.tokyo-night-tmux; }]; + extraConfig = '' + bind -n M-H previous-window + bind -n M-L next-window + ''; + escapeTime = 0; +} diff --git a/nix/users/luca/zsh.nix b/nix/users/luca/zsh.nix new file mode 100644 index 0000000..07cc35c --- /dev/null +++ b/nix/users/luca/zsh.nix @@ -0,0 +1,9 @@ +{ + enable = true; + enableCompletion = true; + autosuggestion.enable = true; + envExtra = '' + . "$HOME/.rokit/env" + eval "$(oh-my-posh init zsh -c ~/.config/ohmyposh/zen.toml)" + ''; +} diff --git a/nix/wsl.nix b/nix/wsl.nix new file mode 100644 index 0000000..8439e3a --- /dev/null +++ b/nix/wsl.nix @@ -0,0 +1,4 @@ +{ + wsl.enable = true; + wsl.defaultUser = "luca"; +}