From 4f066986f02c3874d8fab20d57ab976c8d591f19 Mon Sep 17 00:00:00 2001 From: xinyangli <lixinyang411@gmail.com> Date: Wed, 29 Mar 2023 21:14:37 +0800 Subject: [PATCH] laptop: initial commit --- LICENSE | 24 ++ flake.lock | 43 +++ flake.nix | 19 ++ machines/clash.nix | Bin 0 -> 1276 bytes machines/dnscrypt.nix | 28 ++ machines/laptop/configuration.nix | 356 +++++++++++++++++++++ machines/laptop/hardware-configuration.nix | 42 +++ machines/laptop/secret.nix | Bin 0 -> 494 bytes machines/vscode.nix | 36 +++ 9 files changed, 548 insertions(+) create mode 100644 LICENSE create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 machines/clash.nix create mode 100644 machines/dnscrypt.nix create mode 100644 machines/laptop/configuration.nix create mode 100644 machines/laptop/hardware-configuration.nix create mode 100644 machines/laptop/secret.nix create mode 100644 machines/vscode.nix diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to <https://unlicense.org> diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3b6fe86 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1679944645, + "narHash": "sha256-e5Qyoe11UZjVfgRfwNoSU57ZeKuEmjYb77B9IVW7L/M=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "4bb072f0a8b267613c127684e099a70e1f6ff106", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nur": { + "locked": { + "lastModified": 1680080610, + "narHash": "sha256-e5GOM6FHXXPu4byNAiLQDKu/REVM2MtDH5QJ/C/JQbI=", + "owner": "nix-community", + "repo": "NUR", + "rev": "a9ac1b12b58122c9c1ba4cbdfd444f5ba080fe36", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "NUR", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "nur": "nur" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..492e415 --- /dev/null +++ b/flake.nix @@ -0,0 +1,19 @@ +{ + inputs = { + # Pin nixpkgs to a specific commit + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + # nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11"; + + nur.url = "github:nix-community/NUR"; + }; + + outputs = { self, nixpkgs, nur }: { + nixosConfigurations.xin-laptop = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + nur.nixosModules.nur + machines/laptop/configuration.nix + ]; + }; + }; +} diff --git a/machines/clash.nix b/machines/clash.nix new file mode 100644 index 0000000000000000000000000000000000000000..db254ceecf516f815c098221acb4e1bbb65e490a GIT binary patch literal 1276 zcmV<Y1Oxj3M@dveQdv+`00Hx81O65-uQd9DdwYGm`Mdi9S1o9*;=s>XeJ-?aEA3ME z@u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nEH;s+JPZQwLi2%N9)I&HjU|H zEF*%Xe=&NC^%U-*2lLmSQHu`6yKffw|BQ%h9QNw}#bQ5=#6K&`QIokITw%3;bt(f= zpJOS*{}jm0W1IZ~m9F#l!}aHC&-MQ6&RmXh^3z!2gPKe3shra+d|)s=bc%Vy3UzX& zQ?h{ozZ1MpGW}~$JBJe(4R_v{plpH7CPS`yFTMMTmBA6{j*s7|7Qp_}E+;*gNH~gR z6XaUgMcPT)mQdUfrIJxHfulr;tDhrUzd~gt?ZJ^4g}Ef~;2l<~4UlV9BnsItij11= zkdz<jvD6d(iqa10g>IMVJgiCp`^IW>!08<C979|2Z|*pO-Wrr68~^F-D|sCVoXel{ z*Z<Uf+KXv17W%^F-CN5%Xxw|yC=|MCi3_NC^)oKf+C6BfX3|;V%3wt83)Iycxjc+! z_gDil%H+JIP2;U2CL9rVit_6uQ$2!xu(#lqx=d=&x&X>sIpnpkW$O3i5sYO=ke!A_ mA60y(1eZlA;FT%rD^mhJ8|N>8%meV3eTy0J0Sy1<fjXExfPbC< literal 0 HcmV?d00001 diff --git a/machines/dnscrypt.nix b/machines/dnscrypt.nix new file mode 100644 index 0000000..3ecdcb8 --- /dev/null +++ b/machines/dnscrypt.nix @@ -0,0 +1,28 @@ +{ config, lib, pkgs, ... }: +{ + services.dnscrypt-proxy2 = { + enable = true; + settings = { + ipv6_servers = false; + require_dnssec = true; + sources = { + public-resolvers = { + urls = [ + "https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v3/public-resolvers.md" + "https://download.dnscrypt.info/resolvers-list/v3/public-resolvers.md" + ]; + cache_file = "/var/lib/dnscrypt-proxy2/public-resolvers.md"; + minisign_key = "RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3"; + }; + }; + server_names = [ "cloudflare" "tuna-doh-ipv4" ]; + }; + }; + + networking.networkmanager.dns = "none"; + + # dns + systemd.services.dnscrypt-proxy2.serviceConfig = { + StateDirectory = "dnscrypt-proxy"; + }; +} diff --git a/machines/laptop/configuration.nix b/machines/laptop/configuration.nix new file mode 100644 index 0000000..cb416cc --- /dev/null +++ b/machines/laptop/configuration.nix @@ -0,0 +1,356 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, ... }: + +{ + imports = + [ + # Include the results of the hardware scan. + ./hardware-configuration.nix + ../clash.nix + ../vscode.nix + # ../dnscrypt.nix + ./secret.nix + ]; + + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + boot.loader.efi.efiSysMountPoint = "/boot/efi"; + # boot.kernelPackages = pkgs.linuxPackages_latest; + boot.kernelModules = [ "nvidia" "nvidia_modeset" "nvidia_uvm" ]; + + networking.hostName = "xin-laptop"; # Define your hostname. + + # Enable networking + networking = { + nameservers = [ "127.0.0.1" "::1" ]; + networkmanager = { + enable = true; + }; + resolvconf.useLocalResolver = true; + }; + + # Setup wireguard + # Set your time zone. + time.timeZone = "Asia/Shanghai"; + + # Select internationalisation properties. + i18n.defaultLocale = "en_US.utf8"; + + # Chinese Input Method + i18n.inputMethod = { + enabled = "fcitx5"; + fcitx5.addons = with pkgs; [ fcitx5-rime ]; + fcitx5.enableRimeData = true; + }; + + i18n.extraLocaleSettings = { + LC_ADDRESS = "zh_CN.utf8"; + LC_IDENTIFICATION = "zh_CN.utf8"; + LC_MEASUREMENT = "zh_CN.utf8"; + LC_MONETARY = "zh_CN.utf8"; + LC_NAME = "zh_CN.utf8"; + LC_NUMERIC = "zh_CN.utf8"; + LC_PAPER = "zh_CN.utf8"; + LC_TELEPHONE = "zh_CN.utf8"; + LC_TIME = "en_US.utf8"; + }; + + # Enable the X11 windowing system. + services.xserver.enable = true; + # services.xserver.dpi = 96; + + # Enable the GNOME Desktop Environment. + services.xserver.displayManager.gdm.enable = true; + services.xserver.desktopManager.gnome.enable = true; + + # Configure keymap in X11 + services.xserver = { + layout = "us"; + xkbVariant = ""; + }; + + # Enable CUPS to print documents. + services.printing.enable = true; + services.printing.drivers = [ pkgs.hplip ]; + + # Enable sound with pipewire. + sound.enable = true; + hardware.pulseaudio.enable = false; + security.rtkit.enable = true; + services.pipewire = { + enable = true; + wireplumber.enable = true; + alsa.enable = true; + #alsa.support32Bit = true; + pulse.enable = true; + # If you want to use JACK applications, uncomment this + jack.enable = true; + + # use the example session manager (no others are packaged yet so this is enabled by default, + # no need to redefine it in your config for now) + #media-session.enable = true; + }; + + # Enable touchpad support (enabled default in most desktopManager). + # services.xserver.libinput.enable = true; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.xin = { + isNormalUser = true; + description = "xin"; + extraGroups = [ "networkmanager" "wheel" "wireshark" ]; + }; + + # Enable automatic login for the user. + services.xserver.displayManager.autoLogin.enable = true; + services.xserver.displayManager.autoLogin.user = "xin"; + + # Workaround for GNOME autologin: https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229 + systemd.services."getty@tty1".enable = false; + systemd.services."autovt@tty1".enable = false; + + # Allow unfree packages + nixpkgs.config.allowUnfree = true; + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + # Filesystem + nfs-utils + + winetricks + wineWowPackages.waylandFull + faudio + + man-pages + # ==== CLI tools ==== # + rust-analyzer + leetcode-cli + + tree + wget + tmux + # ffmpeg + tealdeer + neofetch + rclone + clash + # tesseract5 # ocr + # ocrmypdf # pdfocr + + grc + fishPlugins.pisces + fishPlugins.bass + fishPlugins.done + + hyperfine # benchmarking tool + grex # generate regex from example + delta # diff viewer + zoxide # autojumper + du-dust # du + rust + alacritty # terminal emulator + zellij # modern multiplexer + + # ==== Development ==== # + # VCS + git + + jetbrains.jdk # patch jetbrain runtime java + # jetbrains.clion + jetbrains.pycharm-professional + jetbrains.idea-ultimate + android-studio + + # Language server + clang-tools + rnix-lsp + + # C/C++ + gcc + gdb + + # Python + # reference: https://nixos.wiki/wiki/Python + ( + let + my-python-packages = python-packages: with python-packages; [ + pandas + requests + numpy + pyyaml + ]; + python-with-my-packages = python3.withPackages my-python-packages; + in + python-with-my-packages + ) + + # Tex + texlive.combined.scheme-full + + # ==== GUI Softwares ==== # + # Gnome tweaks + gnomeExtensions.dash-to-dock + gnomeExtensions.hide-top-bar + gnomeExtensions.tray-icons-reloaded + gnome.gnome-tweaks + gthumb + + steam + + # Multimedia + vlc + obs-studio + spotify + netease-cloud-music-gtk + + digikam + + # IM + tdesktop + qq + + # Mail + thunderbird + + # Password manager + keepassxc + + # Browser + firefox + chromium + microsoft-edge + + # Writting + obsidian + zotero + wpsoffice + + config.nur.repos.linyinfeng.wemeet + + virt-manager + ]; + # use vim for editor + programs.vim = { + defaultEditor = true; + }; + + # use fish as default shell + environment.shells = [ pkgs.fish ]; + users.defaultUserShell = pkgs.fish; + programs.fish = { + enable = true; + }; + + programs.wireshark = { + enable = true; + package = pkgs.wireshark-qt; + }; + + # Add gsconnect, open firewall + programs.kdeconnect = { + enable = true; + package = pkgs.gnomeExtensions.gsconnect; + }; + + programs.steam = { + enable = true; + remotePlay.openFirewall = true; + }; + # Some programs need SUID wrappers, can be configured further or are + # started in user sessions. + # programs.mtr.enable = true; + # programs.gnupg.agent = { + # enable = true; + # enableSSHSupport = true; + # }; + + # List services that you want to enable: + + # Enable the OpenSSH daemon. + # services.openssh.enable = true; + + # services.gnome.gnome-remote-desktop.enable = true; + + # Open ports in the firewall. + # networking.firewall.allowedTCPPorts = [ ... ]; + # networking.firewall.allowedUDPPorts = [ ... ]; + # Or disable the firewall altogether. + # networking.firewall.enable = false; + + # 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 = "22.05"; # Did you read the comment? + + # Use mirror for binary cache + nix.settings.substituters = [ + "https://mirrors.ustc.edu.cn/nix-channels/store" + # "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" + ]; + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + + # MTP support + services.gvfs.enable = true; + + # Enable Tailscale + services.tailscale.enable = true; + + # Setup Nvidia driver + services.xserver.videoDrivers = [ "nvidia" ]; + hardware.opengl = { + enable = true; + # driSupport = true; + }; + hardware.nvidia.modesetting.enable = true; + hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable; + # hardware.nvidia.open = true; + hardware.nvidia.prime = { + offload.enable = true; + # offload.enableOffloadCmd = true; + nvidiaBusId = "PCI:1:0:0"; + amdgpuBusId = "PCI:4:0:0"; + }; + + # Fonts + fonts = { + fonts = with pkgs; [ + noto-fonts + noto-fonts-emoji + liberation_ttf + fira-code + fira-code-symbols + mplus-outline-fonts.githubRelease + dina-font + proggyfonts + ubuntu_font_family + # Chinese + wqy_microhei + wqy_zenhei + noto-fonts-cjk-sans + noto-fonts-cjk-serif + source-han-sans + source-han-serif + ]; + fontconfig = { + defaultFonts = { + serif = [ "Noto Serif CJK SC" "Ubuntu" ]; + sansSerif = [ "Noto Sans CJK SC" "Ubuntu" ]; + monospace = [ "FiraCode" "Ubuntu" ]; + }; + }; + }; + # Virtualization + virtualisation = { + libvirtd.enable = true; + podman = { + enable = true; + enableNvidia = true; + }; + }; +} diff --git a/machines/laptop/hardware-configuration.nix b/machines/laptop/hardware-configuration.nix new file mode 100644 index 0000000..6c5f7e1 --- /dev/null +++ b/machines/laptop/hardware-configuration.nix @@ -0,0 +1,42 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "xhci_pci" "nvme" "ahci" "usbhid" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/73ff3986-ff55-4e9b-a857-9fc3878ea94f"; + fsType = "ext4"; + }; + + fileSystems."/boot/efi" = + { device = "/dev/disk/by-uuid/5A85-9129"; + fsType = "vfat"; + }; + + swapDevices = + [ { device = "/dev/disk/by-uuid/ccf8e837-d9c6-4e59-a36d-6bbd4836d11a"; } + ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.tailscale0.useDHCP = lib.mkDefault true; + # networking.interfaces.virbr0.useDHCP = lib.mkDefault true; + # networking.interfaces.wg0.useDHCP = lib.mkDefault true; + # networking.interfaces.wlp2s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/machines/laptop/secret.nix b/machines/laptop/secret.nix new file mode 100644 index 0000000000000000000000000000000000000000..15bc5d55d29ffc24f1f59c615d0b39a6134d634a GIT binary patch literal 494 zcmV<K0TKQHM@dveQdv+`0G`O}%6*vLCKvNf-I<jBsD^<m{4U1FG;Q7Kztk#*sbP{} zJrE9%y7Wq5M{D9gFBfPFf=pnd0A^}SiFa#`0I4F#8N~R$o&C9QvcxX@<btSV)Sq_J z-wEl#2xCJmpQ_gK%_cRCJTvw0AWqn!v&DDuwlEdOersc1XHdGe;+-UoEND6-mQZ}( zwf@g|O0)>fd!cj|NH7(&y0vzR(DM%s&qwt@$dq>F#mHZ84=7~kLng{46YcA9bW$Ab z3|UTv>25SBNvTmlFH(bc56^31m#&=lqw8w~9K8HAj%?k+AxISo*qTk?W_~PhmNkrJ z95v7s9Fp;0BlTAGCv}u=pHKr*)!MTf)ImI5SPH_p{UdIO@F<q#<9`Z`Bq|I4VbKvq zBR9U*KiE~6at4%D#{`hi|1ct&I|^I*fLZad!*O$i(3t8ARldSMU;9PnNHZ9CvzeZx z<8OB=gvF<bXRLHDk9~p7N=tGd!gY)DDJaxI91?q+gC!37L*J=Lp8M*2(V!)8>GayA zuscPE0L8I5DlwBJK0?^YO$A*fzB-$cvhJZ41n*=^&%c6WU@rFD<I2~+UC3BrK`Euv k_+V1z`elvrzc5FWowfCu>Im3EuD`o5!6t}etQBd|FKux3+5i9m literal 0 HcmV?d00001 diff --git a/machines/vscode.nix b/machines/vscode.nix new file mode 100644 index 0000000..0ec1e87 --- /dev/null +++ b/machines/vscode.nix @@ -0,0 +1,36 @@ +{ config, lib, pkgs, ... }: +{ + environment.systemPackages = [ + (pkgs.vscode-with-extensions.override { + vscodeExtensions = with pkgs.vscode-extensions; [ + arrterian.nix-env-selector + + bbenoist.nix + ms-azuretools.vscode-docker + ms-vscode-remote.remote-ssh + vscodevim.vim + github.copilot + github.vscode-pull-request-github + eamodio.gitlens + gruntfuggly.todo-tree # todo highlight + + vadimcn.vscode-lldb # debugger + + # Language support + ms-python.python + davidanson.vscode-markdownlint + llvm-vs-code-extensions.vscode-clangd + jnoortheen.nix-ide + james-yu.latex-workshop + rust-lang.rust-analyzer + ] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [ + { + name = "remote-ssh-edit"; + publisher = "ms-vscode-remote"; + version = "0.47.2"; + sha256 = "1hp6gjh4xp2m1xlm1jsdzxw9d8frkiidhph6nvl24d0h8z34w49g"; + } + ]; + }) + ]; +}