├── .envrc ├── .genSUMMARY.sh ├── .gitattributes ├── .github └── workflows │ └── gh-pages.yml ├── .gitignore ├── .markcode_progress.sh ├── .parent_dirs.sh ├── Makefile ├── README-en.md ├── README.md ├── book.toml ├── config.nix ├── docs ├── explanation │ ├── index.md │ ├── modules.md │ └── nixpkgs.md ├── howto │ ├── 32bit.md │ ├── auto_push_to_cachix │ │ ├── cachix-package.nix │ │ ├── index.md │ │ └── test.nix │ ├── backup_binary_cache.md │ ├── cross.md │ ├── images │ │ ├── cpu_isCompatible.dot │ │ └── cpu_isCompatible.dot.svg │ ├── index.md │ ├── install_nixos.md │ └── kernel_config.md └── slides │ ├── 2023.nix-env.md │ ├── 2023.nix-env.slides.html │ ├── 2023.nix-env.slides.mkd │ ├── images │ ├── Moby-logo.png │ ├── efi-background.png │ ├── multi-versions.drawio │ ├── multi-versions.svg │ ├── nix-snowflake.svg │ ├── nix-wallpaper-nineish.src.svg │ ├── ohhh.mp4 │ ├── slides_location.drawio │ ├── slides_location.svg │ └── ubuntu-icon.svg │ └── index.md ├── home.nix ├── modules └── cachix.nix ├── nix-on-droid.nix ├── nix └── nix.conf ├── opt.nix ├── overlays.nix ├── scripts ├── fhs-shell │ ├── dynamorio.nix │ ├── hello.nix │ ├── index.md │ ├── pin.nix │ ├── spec.nix │ ├── x11.nix │ └── xilinx.nix ├── pkgs │ ├── 7z.nix │ ├── android.md │ ├── android.nix │ ├── appimage_runtime.nix │ ├── coremarks.nix │ ├── cross_mips.nix │ ├── cross_static_hello.nix │ ├── fhs_helloworld.nix │ ├── fhs_spec2000_perl.nix │ ├── index.md │ ├── nix-binary-tarballs-new.nix │ ├── nix-binary-tarballs.nix │ ├── nix-docker-isa │ │ ├── default.nix │ │ ├── dockers.nix │ │ └── imageFiles │ │ │ └── etc │ │ │ ├── group │ │ │ ├── nix │ │ │ └── nix.conf │ │ │ ├── nsswitch.conf │ │ │ ├── passwd │ │ │ └── profile │ ├── nvchad.nix │ ├── qemu-sys-static.nix │ ├── qemu-sys_riscv64_static.nix │ ├── qemu-v1.0.patch │ ├── qemu_riscv64_static.nix │ ├── qemu_static.nix │ ├── qemu_tests_tcg.nix │ ├── qemus.nix │ └── shellinabox.nix └── shell │ ├── ccache.nix │ ├── chipyard.nix │ ├── cross_mips.nix │ ├── cross_platform.nix │ ├── devshell_hello.nix │ ├── gcc.nix │ ├── hello.nix │ ├── index.md │ ├── pygame.nix │ ├── python_fhs_venv.nix │ ├── python_mach.nix │ ├── python_venv.nix │ ├── qemu_plugins.nix │ ├── qemu_tests_tcg.nix │ ├── riscv-tests.nix │ ├── spike.nix │ ├── texlive.nix │ ├── ucasproposal.nix │ ├── v8.nix │ ├── venv.nix │ ├── wine6.nix │ └── xiangshan.nix ├── shell.nix ├── sys ├── cli.nix ├── gui.nix ├── index.md ├── modules │ └── cachix.nix └── wayland.md ├── system.nix ├── theme ├── highlight.js └── index.hbs └── usr ├── cli-extra.nix ├── cli.nix ├── cli ├── clash.nix ├── clashctl.nix ├── ctags.nix ├── gdb.nix ├── index.md ├── kaleido.nix ├── ld.md ├── node.md ├── python.md ├── searxng.nix ├── static_qemu.md ├── tailscale.md ├── tailscale.nix ├── tmux.nix └── vim │ ├── README.md │ ├── close-windows.nix │ ├── codecompanion-nvim.nix │ ├── color-scheme.nix │ ├── conform-nvim.nix │ ├── default.nix │ ├── deprecated.DrawIt.nix │ ├── deprecated.image-nvim.nix │ ├── fold.nix │ ├── git-wip.nix │ ├── gitsigns-nvim.nix │ ├── hbac-nvim.nix │ ├── leap-nvim.nix │ ├── markdown-preview-nvim.nix │ ├── mini-nvim.nix │ ├── nvim-cmp.nix │ ├── nvim-config-local.nix │ ├── nvim-lspconfig │ ├── bash.nix │ ├── c.nix │ ├── default.nix │ ├── deprecated.ltex.nix │ ├── html.nix │ ├── lua.nix │ ├── nix.nix │ ├── python.nix │ ├── typos.nix │ └── xml.nix │ ├── nvim-metals │ ├── default.nix │ └── jre_with_proxy.nix │ ├── nvim-nav.nix │ ├── nvim-treesitter.nix │ ├── nvim-window-picker.nix │ ├── outline-nvim.nix │ ├── reject.avante-nvim.nix │ ├── reject.distant-nvim.nix │ ├── reject.remote-sshfs-nvim.nix │ ├── smartyank-nvim.nix │ ├── telescope-nvim.nix │ ├── vim-easy-align.nix │ ├── vim-floaterm.nix │ ├── vim-hexokinase.nix │ ├── vim-mark.nix │ ├── vim-matchup.nix │ └── winshift-nvim.nix ├── gui.nix ├── gui ├── feishu.md ├── firefox │ ├── apps │ │ ├── default.nix │ │ └── module.nix │ ├── default.nix │ └── extensions │ │ ├── darkreader.nix │ │ ├── default.nix │ │ ├── module.nix │ │ ├── sidebery.nix │ │ ├── smart-toc.nix │ │ └── smartproxy.nix ├── gnome │ ├── calendar │ │ ├── default.nix │ │ ├── module.nix │ │ └── template.nix │ ├── default.nix │ └── extensions │ │ ├── advanced-alttab-window-switcher.nix │ │ ├── auto-accent-colour.nix │ │ ├── bing-wallpaper-changer.nix │ │ ├── bluetooth-battery-meter.nix │ │ ├── customize-ibus.nix │ │ ├── dash-to-dock.nix │ │ ├── default.nix │ │ ├── gtile.nix │ │ ├── hide-top-bar.nix │ │ ├── lunar-calendar.nix │ │ ├── pano.nix │ │ ├── system-monitor.nix │ │ ├── transparent-top-bar.nix │ │ └── unite.nix ├── index.md ├── kdeconnect.nix ├── kitty │ ├── default.nix │ ├── search.nix │ └── timer.nix ├── mime.nix ├── rofi.nix ├── rustdesk.nix ├── singleton_web_apps.nix ├── typora.md ├── warpd.nix ├── waydroid.md ├── weixin.nix ├── wrapWine.nix ├── xcolor.nix ├── xdot.nix └── xelfviewer.nix └── modules └── cachix.nix /.envrc: -------------------------------------------------------------------------------- 1 | use nix 2 | -------------------------------------------------------------------------------- /.genSUMMARY.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | getTitle() { 4 | PATHMD=$1 5 | head -n 3 "${PATHMD}" | awk '/^# / {$1=""; print substr($0,2); exit;}' 6 | } 7 | genDir() { 8 | Dir=$1 9 | for PATHMD in $(find $Dir -name "*.md" -exec ./.parent_dirs.sh {} \; | sort -n | uniq); do 10 | 11 | # remove tailing slash for dir 12 | PATHMD=${PATHMD%/} 13 | 14 | # README.md & index.md belongs to current folder 15 | NAMEMD=${PATHMD##*/} 16 | if [[ ${NAMEMD} =~ README.*md || ${NAMEMD} == "index.md" || ${NAMEMD} == "SUMMARY.md" ]]; then 17 | continue 18 | fi 19 | 20 | # ignore . 21 | if [[ ${PATHMD} == "." ]]; then 22 | continue 23 | fi 24 | 25 | # count indentation # $PATHMD = ./miao/wang/x.md 26 | TMP1=${PATHMD#./} # TMP1 = miao/wang/x.md 27 | TMP2=${TMP1//[^\/]} # TMP2 = // 28 | INDENT=${#TMP2} # INDENT = 2 29 | 30 | for (( i=0; i<${INDENT}; i++ )); do 31 | echo -n " " 32 | done 33 | 34 | if [[ -f ${PATHMD} ]]; then 35 | TITLE=$(getTitle "${PATHMD}") 36 | if [[ -n ${TITLE} ]]; then 37 | echo "* [${TITLE}](${PATHMD})" 38 | else 39 | echo "* [${NAMEMD}](${PATHMD})" 40 | fi 41 | elif [[ -f ${PATHMD}/index.md ]]; then 42 | TITLE=$(getTitle "${PATHMD}/index.md") 43 | if [[ -n ${TITLE} ]]; then 44 | echo "* [${TITLE}](${PATHMD}/index.md)" 45 | else 46 | echo "* [${NAMEMD}/](${PATHMD}/index.md)" 47 | fi 48 | elif [[ -f ${PATHMD}/README.md ]]; then 49 | TITLE=$(getTitle "${PATHMD}/README.md") 50 | if [[ -n ${TITLE} ]]; then 51 | echo "* [${TITLE}](${PATHMD}/README.md)" 52 | else 53 | echo "* [${NAMEMD}/](${PATHMD}/README.md)" 54 | fi 55 | elif [[ -d ${PATHMD} ]]; then 56 | echo "* [${NAMEMD}/]()" 57 | else 58 | echo "* [${NAMEMD}]()" 59 | fi 60 | done 61 | } 62 | 63 | echo "# Summary" 64 | echo 65 | echo "# 🏠主页" 66 | echo 67 | echo "* [📔README.md](./README.md)" 68 | echo 69 | echo "# 🌏全局配置" 70 | echo 71 | echo "* [config.nix](./config.nix.md)" 72 | echo "* [TODO: nix/nix.conf](./nix/nix.conf.md)" 73 | echo "* [opt.nix](./opt.nix.md)" 74 | echo 75 | echo "# 🖥️系统配置(需sudo,用于NixOS)" 76 | echo 77 | echo "* [system.nix](./system.nix.md)" 78 | genDir ./sys/ 79 | echo 80 | echo "# 😺用户配置(无需sudo,用于Nix/NixOS)" 81 | echo 82 | echo "* [home.nix](./home.nix.md)" 83 | genDir ./usr/ 84 | echo 85 | echo "# 🤖安卓配置(无需sudo,复用\"用户配置\")" 86 | echo 87 | echo "* [nix-on-droid.nix](./nix-on-droid.nix.md)" 88 | echo 89 | echo "# 🔩通用模块" 90 | echo 91 | genDir ./modules/ 92 | echo 93 | echo "# 📝文档和心得体会" 94 | echo 95 | genDir ./docs/ 96 | echo 97 | echo "# 📃Nix脚本(nix-shell和打包)" 98 | echo 99 | genDir ./scripts/ 100 | echo 101 | echo "# 📌其他" 102 | echo 103 | echo "* [shell.nix](./shell.nix.md)" 104 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | theme/* linguist-vendored 2 | -------------------------------------------------------------------------------- /.github/workflows/gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: deploy-github-pages 2 | on: [push] 3 | jobs: 4 | deploy-github-pages: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v4 8 | - uses: cachix/install-nix-action@v23 9 | with: 10 | nix_path: nixpkgs=channel:nixos-24.05 11 | - run: nix-shell --run "make -j" 12 | - uses: peaceiris/actions-gh-pages@v3 13 | if: ${{ github.ref == 'refs/heads/main' }} 14 | with: 15 | github_token: ${{ secrets.GITHUB_TOKEN }} 16 | publish_dir: ./book 17 | force_orphan: true 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | result* 2 | .direnv 3 | book/ 4 | SUMMARY.md 5 | *.nix.md 6 | nix/nix.conf.md 7 | opt-local.nix 8 | .ccache/ 9 | -------------------------------------------------------------------------------- /.markcode_progress.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | n=$(grep "#MC" -rl --include="*.nix" | grep -v "book/" | wc -l) 4 | d=$(find -name "*.nix" | grep -v "book/" | wc -l) 5 | 6 | sed -i '1 s,[0-9]\+/[0-9]\+,'$n'/'$d',' ./README.md 7 | -------------------------------------------------------------------------------- /.parent_dirs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | path="$1" 4 | echo $path 5 | dir=$(dirname "$path") 6 | while true; do 7 | echo $dir/ 8 | 9 | dirdir=$(dirname "$dir") 10 | if [[ "$dir" != "$dirdir" ]]; then 11 | dir="$dirdir" 12 | else 13 | break 14 | fi 15 | done 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: SUMMARY.md 2 | mdbook build 3 | 4 | NIXs = $(shell find . -name "*.nix" -not -path "./book*") 5 | NIX_MDs = $(addsuffix .md,${NIXs}) 6 | %.md: % 7 | markcode $< > $@ 8 | 9 | # update markcode progross 10 | README.md: ./.markcode_progress.sh ${NIXs} 11 | ./$< 12 | 13 | ALL_MDs = $(shell find . -name "*.md" -not -name "SUMMARY.md") 14 | SUMMARY.md: .genSUMMARY.sh ${NIX_MDs} ${ALL_MDs} 15 | ./$< > $@ 16 | -------------------------------------------------------------------------------- /book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | authors = ["xieby1"] 3 | language = "en" 4 | multilingual = false 5 | src = "." 6 | title = "Xieby1's Nix/NixOS Config" 7 | 8 | [output.html] 9 | git-repository-url = "https://github.com/xieby1/nix_config" 10 | -------------------------------------------------------------------------------- /config.nix: -------------------------------------------------------------------------------- 1 | #MC # config.nix 2 | #MC 3 | #MC 当初始化`nixpkgs`时,例如`pkgs = import {}`, 4 | #MC `nixpkgs`的初始化代码会读取`~/.config/nixpkgs/config.nix`作为`nixpkgs.config`参数。 5 | #MC 如果你对`nixpkgs`的初始化感兴趣,可以去看看这部分的源代码`/pkgs/top-level/impure.nix`。 6 | #MC 7 | #MC `config.nix`文件(即`nixpkgs.config`)接受的参数可以参考nixpkgs的官方文档的 8 | #MC [config Options Reference](https://nixos.org/manual/nixpkgs/stable/#sec-config-options-reference)章节, 9 | #MC 或是去看nixpkgs这部分的源码`/pkgs/top-level/config.nix`。 10 | #MC 11 | #MC 下面是添加了注解的我的`config.nix`: 12 | { 13 | #MC 禁用安装非本地的包,比如禁止x86_64-linux的包被安装到aarch64-linux上。 14 | allowUnsupportedSystem = false; 15 | allowUnfree = true; 16 | packageOverrides = pkgs: rec { 17 | #MC 添加nix user repository (NUR)到nixpkgs里。 18 | nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") { 19 | pkgs = pkgsu; 20 | }; 21 | #MC 添加非稳定版的nixpkgs到nixpkgs里, 22 | #MC 比如非稳定版的hello可以通过`pkgs.pkgsu.hello`来访问。 23 | pkgsu = import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/master.tar.gz") {}; 24 | #MC 添加flake-compat,用于在nix expression中使用flake的包 25 | flake-compat = import (builtins.fetchTarball { 26 | url = "https://github.com/edolstra/flake-compat/archive/0f9255e01c2351cc7d116c072cb317785dd33b33.tar.gz"; 27 | sha256 = "0m9grvfsbwmvgwaxvdzv6cmyvjnlww004gfxjvcl806ndqaxzy4j"; 28 | }); 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /docs/explanation/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xieby1/nix_config/eecf06aa8a787aaaaa4bdfca7984d45d768f812a/docs/explanation/index.md -------------------------------------------------------------------------------- /docs/explanation/modules.md: -------------------------------------------------------------------------------- 1 | # Module 2 | 3 | nixpkgs/lib/modules.nix: 4 | 从`loadModule`可以看出,imports可以接受Function、Attr、路径,不能够嵌套List。 5 | -------------------------------------------------------------------------------- /docs/explanation/nixpkgs.md: -------------------------------------------------------------------------------- 1 | # Nixpkgs 2 | 3 | ## nixpkgs crossSystem 4 | 5 | * default.nix 6 | * pkgs/top-level/impure.nix 7 | * pkgs/top-level/default.nix 8 | * lib.systems.elaborate crossSystem0; 9 | * lib/systems/default.nix: elaborate 10 | * parsed = parse.mkSystemFromString ... args.system; // args.system = crossSystem 11 | * lib/systems/parse.nix 12 | * mkSystemFromString = s: mkSystemFromSkeleton (mkSkeletonFromList (lib.splitString "-" s)); 13 | * mkSkeletonFromList 14 | 15 | 注意mkSkeletonFromList通过 16 | `${toString (length l)}` 17 | 实现了一个根据l长度的switch case。 18 | 19 | crossSystem的4个域分别为cpu-vendor-kernel-abi 20 | 21 | ## import nixpkgs 22 | 23 | `import {}` 24 | 的加载流程 25 | 26 | * default.nix 27 | * pkgs/top-level/impure.nix 28 | * pkgs/top-level/default.nix 29 | * stdenvStages import pkgs/stdenv/default.nix 30 | * stagesLinux = import pkgs/stdenv/linux/ 31 | * thisStdenv, stdenv = import pkgs/stdenv/generic/default.nix 32 | * import lib/default.nix 33 | # this is where customisation.nix come from 34 | * allPackages import pkgs/top-level/stage.nix 35 | * allPackages import pkgs/top-level/all-packages.nix 36 | * boot = import pkgs/stdenv/booter.nix 37 | 38 | vim_configurable.override {python = python3} 39 | vimUtils.makeCustomizable (vim.override {python = python3}) 40 | vimUtils.makeCustomizable (vim.override {python = python3}) 41 | 42 | 似乎是一个浮现override变量的最小集 43 | f = a:{res = a+1;} 44 | fo = pkgsMiao.makeOverride f 45 | f 2 46 | -------------------------------------------------------------------------------- /docs/howto/32bit.md: -------------------------------------------------------------------------------- 1 | # 打包/编译32位程序 2 | 3 | 参考[Packaging/32bit Applications](https://nixos.wiki/wiki/Packaging/32bit_Applications)。 4 | 5 | ## 仅32位 6 | 7 | 打包使用pkgs.pkgsi686Linux.stdenv.mkDerivation 8 | 9 | 编译使用pkgs.pkgsi686Linux.gcc 10 | 11 | ## 32位且64位 12 | 13 | 打包使用pkgs.multiStdenv.mkDerivation。 14 | 15 | 编译使用pkgs.gcc_multi。 16 | 17 | -------------------------------------------------------------------------------- /docs/howto/auto_push_to_cachix/cachix-package.nix: -------------------------------------------------------------------------------- 1 | #MC # cachixPackage 2 | #MC 3 | #MC This file try to implement a package wrapper, which will automatically push `pkg` to cachix upon building. 4 | #MC However, this method seems not work, due to limited resources in nix-build environment. 5 | #MC For more details, see [here](./index.md). 6 | { cachix 7 | , stdenv 8 | , writeShellScript 9 | }: 10 | 11 | { pkg 12 | , sha256 13 | , cachix_dhall 14 | , cachix_name 15 | , name ? "cachixed" 16 | }: 17 | 18 | builtins.derivation { 19 | inherit name; 20 | system = builtins.currentSystem; 21 | builder = writeShellScript "cachix-package-builder" '' 22 | source ${stdenv}/setup 23 | echo ${pkg} > $out 24 | if [[ -f "${cachix_dhall}" ]]; then 25 | ${cachix}/bin/cachix -c ${cachix_dhall} push ${cachix_name} ${pkg} 26 | result=$? 27 | echo result $result 28 | exit $result 29 | fi 30 | ''; 31 | 32 | outputHashMode = "flat"; 33 | outputHashAlgo = "sha256"; 34 | outputHash = sha256; 35 | } 36 | -------------------------------------------------------------------------------- /docs/howto/auto_push_to_cachix/index.md: -------------------------------------------------------------------------------- 1 | # Auto Push Packages to Cachix 2 | 3 | **Objective**: 4 | Automatically push specific built packages to cachix during `home-manager switch`/`nixos-rebuild switch`/`nix-shell`. 5 | 6 | Although there are several existing ways to achieve this: 7 | 8 | * cachix's [watch-exec and watch-store](https://docs.cachix.org/pushing) 9 | * nix-build's [post-build-hook](https://nixos.org/manual/nix/stable/advanced-topics/post-build-hook) 10 | 11 | However, the granularity of these methods is coarse; they push all packages to cachix. 12 | Is there a way to allow users to control which packages are pushed? 13 | 14 | ## Conclusion First 15 | 16 | Use **hooks** to push the selected packages to cachix: 17 | 18 | | Scenario | Hook | Example | 19 | |---------------|----------------------------|--------------------------------------------------------------------------------------------------------------------| 20 | | home-manager | `home.activation` | [modules/cachix.nix](../../../modules/cachix.nix.md), [usr/modules/cachix.nix](../../../usr/modules/cachix.nix.md) | 21 | | nixos-rebuild | `system.activationScripts` | [modules/cachix.nix](../../../modules/cachix.nix.md), [sys/modules/cachix.nix](../../../sys/modules/cachix.nix.md) | 22 | | nix-shell | `shellHook` | [openc910/shell.nix](https://github.com/xieby1/openc910/blob/main/shell.nix) | 23 | 24 | --- 25 | 26 | ## My Explorations 27 | 28 | **Possible solutions**: 29 | Add a wrapper called `cachixPackages`, which recives the packages to be pushed and cachix information. 30 | This `cachixPackages` is a dummy package whose build stages will push the packages to cachix. 31 | However, normal nix packages are not allowed network access during building. 32 | To tackle this, like how fetch* series functions are implemented, the [fixed-output derivation](https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-outputHash) can be utilized to allow network access. 33 | 34 | However, the above method seems not work as below, 35 | because cachix needs accesses to some resources beyond nix-build process (such as nix-build's sandbox). 36 | 37 | ```bash 38 | nix-build test.nix 39 | ... 40 | cachix: CppStdException e "\ESC[31;1merror:\ESC[0m creating directory '\ESC[35;1m/nix/var\ESC[0m': \ESC[35;1mPermission denied\ESC[0m"(Just "nix::SysError") 41 | result 1 42 | ... 43 | ``` 44 | 45 | Even though I disable the nix-build sandbox by using `--no-sandbox`, 46 | the cachix still does not satisfy as below. 47 | 48 | ```bash 49 | $ nix-build test.nix --no-sandbox 50 | ... 51 | cachix: CppStdException e "\ESC[31;1merror:\ESC[0m cannot open connection to remote store '\ESC[35;1mdaemon\ESC[0m': \ESC[35;1m\ESC[31;1merror:\ESC[0m reading from file: \ESC[35;1mConnection reset by peer\ESC[0m\ESC[0m"(Just "nix::Error") 52 | ... 53 | ``` 54 | 55 | If you curious about my demo of `cachixPackages` and its test, 56 | see [cachix-package.nix](./cachix-package.nix.md) and [test.nix](./test.nix.md). 57 | -------------------------------------------------------------------------------- /docs/howto/auto_push_to_cachix/test.nix: -------------------------------------------------------------------------------- 1 | #MC # Test for cachixPackage 2 | #MC 3 | #MC To run the test: 4 | #MC 5 | #MC ```bash 6 | #MC # run with nix-build sandbox 7 | #MC nix-build test.nix 8 | #MC # run without nix-build sandbox 9 | #MC nix-build test.nix --no-sandbox 10 | #MC ``` 11 | let 12 | pkgs = import {}; 13 | cachixPackage = import ./cachix-package.nix {inherit (pkgs) cachix stdenv writeShellScript;}; 14 | in cachixPackage { 15 | pkg = pkgs.hello; 16 | sha256 = "01vm275n169r0ly8ywgq0shgk8lrzg79d1aarshwybwxwffj4q0q"; 17 | cachix_dhall = /home/xieby1/Gist/Config/cachix.dhall; 18 | cachix_name = "xieby1"; 19 | } 20 | -------------------------------------------------------------------------------- /docs/howto/backup_binary_cache.md: -------------------------------------------------------------------------------- 1 | # 备份binary cache 2 | 3 | ## 场景 4 | 5 | 官方binary cache没有的包, 自己花了很长时间编译出来。 6 | 值得把编译出来的的包及其依赖全部保存下来。 7 | 8 | ## 目前的问题 9 | 10 | nix copy --to 备份的/nix/store如何使用? 11 | -------------------------------------------------------------------------------- /docs/howto/images/cpu_isCompatible.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | 3 | node[ 4 | shape=box, 5 | style="filled, solid", 6 | color=black, 7 | fillcolor=white, 8 | ] 9 | 10 | subgraph cluster_x86 { 11 | label="x86"; 12 | i386 -> i486 -> i586 -> i686; 13 | } 14 | i686 -> x86_64 [style=dashed;]; 15 | 16 | subgraph cluster_arm32 17 | { 18 | label="arm32"; 19 | arm -> armv5tel -> armv6l -> armv6m -> armv7l; 20 | armv7l -> {armv7a; armv7r; armv7m;} -> {armv8a; armv8r; armv8m;}; 21 | {armv8r; armv8m;} -> armv8a; 22 | {rank=same; armv8a; armv8r; armv8m;} 23 | } 24 | aarch64 -> armv8a -> aarch64 [style=dashed;]; 25 | aarch64 -> aarch64_be -> aarch64; 26 | 27 | powerpc -> powerpc64; 28 | powerpcle -> powerpc -> powerpcle; 29 | powerpc64le -> powerpc64 -> powerpc64le; 30 | 31 | mips -> mips64; 32 | mips -> mipsel -> mips; 33 | mips64 -> mips64el -> mips64; 34 | 35 | riscv32 -> riscv64; 36 | 37 | sparc -> sparc64; 38 | 39 | wasm32 -> wasm64; 40 | 41 | label="x86 → x86_64 not true in some cases. Like in WSL mode\naarch64 ↔ arm32 not always true! Some arm64 cpus don’t support arm32 mod"; 42 | } 43 | -------------------------------------------------------------------------------- /docs/howto/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xieby1/nix_config/eecf06aa8a787aaaaa4bdfca7984d45d768f812a/docs/howto/index.md -------------------------------------------------------------------------------- /docs/howto/install_nixos.md: -------------------------------------------------------------------------------- 1 | # 安装NixOS 2 | 3 | 安装过程采用[官方安装文档](https://nixos.org/manual/nixos/stable/#sec-installation)。 4 | 若已安装NixOS,则可跳过该步骤,直接看安装我的配置。 5 | 6 | ## 准备镜像 7 | 8 | QEMU: 9 | 10 | ```bash 11 | # 下载minimal ISO镜像:https://nixos.org/download.html 12 | # 创建qemu硬盘(大小32GB) 13 | qemu-img create -f qcow2 32G 14 | # 将ISO安装到qemu硬盘 15 | qemu-system-x86_64 -display gtk,window-close=off -vga virtio -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5556-:22,smb=/home/xieby1/ -m 4G -smp 3 -enable-kvm -hda -cdrom -boot d & 16 | ``` 17 | 18 | 物理机: 19 | 20 | ```bash 21 | # 暂时未探究命令行连接wifi的方法 22 | # 所以目前使用gnome版ISO,而非minimal ISO。 23 | # 下载gnome ISO镜像:https://nixos.org/download.html 24 | # 启动U盘制作 25 | sudo dd if= of= 26 | sync 27 | # 重启进入U盘系统 28 | # 注:需要在BIOS中取消secure boot,否则U盘无法启动。 29 | ``` 30 | 31 | ## 分区 32 | 33 | 进入ISO系统后,创建分区。 34 | 一共需要3个分区:启动分区,操作系统分区,swap分区。 35 | QEMU和物理机单系统需要创建这3个分区。 36 | 物理机双系统中启动分区已有,只需创建剩下2个分区。 37 | 38 | QEMU: 39 | 40 | ```bash 41 | sudo bash 42 | parted /dev/sda -- mklabel msdos 43 | parted /dev/sda -- mkpart primary 1MiB -8GiB 44 | parted /dev/sda -- mkpart primary linux-swap -8GiB 100% 45 | ``` 46 | 47 | 物理机单系统: 48 | 49 | ```bash 50 | parted /dev/sda -- mklabel gpt 51 | parted /dev/sda -- mkpart primary 512MiB -8GiB 52 | parted /dev/sda -- mkpart primary linux-swap -8GiB 100% 53 | parted /dev/sda -- mkpart ESP fat32 1MiB 512MiB 54 | parted /dev/sda -- set 3 esp on 55 | ``` 56 | 57 | 物理机双系统: 58 | 59 | 还未探索parted详细用法,目前使用disk软件可视化分区。 60 | 61 | * 创建Ext4分区,取名为nixos 62 | * 创建Other->swap分区 63 | 64 | ## 文件系统 65 | 66 | ```bash 67 | mkfs.ext4 -L nixos /dev/<系统分区> 68 | mkswap -L swap /dev/ 69 | swapon /dev/ 70 | mkfs.fat -F 32 -n boot /dev/<启动分区> # 物理机单系统 71 | mount /dev/disk/by-label/nixos /mnt 72 | mkdir -p /mnt/boot # 物理机单系统&双系统 73 | mount /dev/disk/by-label/boot /mnt/boot # 物理机单系统&双系统 74 | ``` 75 | 76 | ## 基础配置 77 | 78 | * 生成配置文件 79 | ```bash 80 | nixos-generate-config --root /mnt 81 | ``` 82 | * 修改/mnt/etc/nixos/configuration.nix, 83 | * 修改名字`networking.hostName` 84 | * 启用代理 85 | * QEMU中宿主机器的ip为10.0.2.2 86 | * 安装过程中需要借助别的计算机或宿主机的的代理服务 87 | * 部署完我的nixos配置后,将会有clash服务,可以用虚拟机的代理服务 88 | * `networking.proxy.default = "http://user:password@proxy:port/";` 89 | * `networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";` 90 | * (QEMU和物理机单系统)取消以下注释以开启grub支持 91 | * `boot.loader.grub.device = "/dev/sda";` 92 | * 取消防火墙,以便kdeconnect正常运行 93 | * `networking.firewall.enable = false;` 94 | * (物理机双系统)自动探测操作系统启动项 95 | * `boot.loader.grub.useOSProber = true;` 96 | * 添加用户 97 | * `users.users.xieby1` 98 | * 添加软件 99 | * `environment.systemPackages = with pkgs; [vim git];` 100 | 101 | 最后 102 | 103 | ```bash 104 | nixos-install 105 | reboot 106 | ``` 107 | 108 | 重启之后,进入NixOS。 109 | -------------------------------------------------------------------------------- /docs/howto/kernel_config.md: -------------------------------------------------------------------------------- 1 | # How To Config Linux Kernel in Nix 2 | 3 | Basic configuration tricks referring to [nixos.wiki: Linux Kernel](https://nixos.wiki/wiki/Linux_kernel). 4 | 5 | ## The Override System in Kernel 6 | 7 | What do the `pkgs.linux.override`, `pkgs.linux.overrideAttrs` override? 8 | 9 | To answer these questions, we need first to explore how kernel derivation is generated. 10 | When we type `pkgs.linux`, how this derivation is generated by nix? 11 | 12 | ``` 13 | * pkgs.linux 14 | * pkgs/top-level/all-packages: 15 | * linuxPackages.kernel; 16 | * (linuxPackages = linuxKernel.packageAliases.linux_default).kernel; 17 | * (linuxPackages = (linuxKernel = recurseIntoAttrs (callPackage ./linux-kernels.nix { });).packageAliases.linux_default).kernel; 18 | * (recurseIntoAttrs (callPackage ./linux-kernels.nix { });).packageAliases.linux_default.kernel; 19 | * pkgs/top-level/linux-kernels.nix: 20 | * packages.linux_6_6.kernel; 21 | * (recurseIntoAttrs (vanillaPackages // rtPackages // rpiPackages // { ... })).linux_6_6.kernel 22 | * (recurseIntoAttrs ({...; linux_6_6 = recurseIntoAttrs (packagesFor kernels.linux_6_6);...} // rtPackages // rpiPackages // { ... })).linux_6_6.kernel 23 | * (packagesFor kernels.linux_6_6).kernel 24 | * ((kernel_: {kernel = kernel_;}) kernels.linux_6_6).kernel 25 | * kernels.linux_6_6 26 | * ❶callPackage ../os-specific/linux/kernel/mainline.nix { 27 | branch = "6.6"; 28 | kernelPatches = [ 29 | kernelPatches.bridge_stp_helper 30 | kernelPatches.request_key_helper 31 | ]; 32 | }; 33 | * pkgs/os-specific/linux/kernel/mainline.nix 34 | * buildLinux args' 35 | * ❷buildLinux ((builtins.removeAttrs args [ "branch" ]) 36 | // { 37 | inherit src version; 38 | 39 | modDirVersion = lib.versions.pad 3 version; 40 | extraMeta.branch = branch; 41 | } 42 | // (args.argsOverride or { })) 43 | * (callPackage pkgs/os-specific/linux/kernel/generic.nix {}) args' 44 | * overridableKernel args' 45 | * (lib.makeOverridable ({...}: kernel.overrideAttrs (...))) args' 46 | * kernel.overrideAttrs (...) 47 | * ❸((callPackage ./manual-config.nix { inherit lib stdenv buildPackages; }) (basicArgs // { ... })).overrideAttrs (...) 48 | ``` 49 | 50 | 因此 51 | 52 | * ❶ `override` is applied to `pkgs/os-specific/linux/kernel/mainline.nix` 53 | * ❷ `argsOverride` in `override (old: {argsOverride = {...} })` is applied to `pkgs/os-specific/linux/kernel/generic.nix` 54 | * ❸ `overrideAttrs` is applied to `pkgs/os-specific/linux/kernel/manual-config.nix` 55 | -------------------------------------------------------------------------------- /docs/slides/2023.nix-env.md: -------------------------------------------------------------------------------- 1 | # Nix让你的团队成员不再受环境问题困扰 2 | 3 | 注:左下角菜单里可切换全屏 4 | 5 | 6 | -------------------------------------------------------------------------------- /docs/slides/images/Moby-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xieby1/nix_config/eecf06aa8a787aaaaa4bdfca7984d45d768f812a/docs/slides/images/Moby-logo.png -------------------------------------------------------------------------------- /docs/slides/images/efi-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xieby1/nix_config/eecf06aa8a787aaaaa4bdfca7984d45d768f812a/docs/slides/images/efi-background.png -------------------------------------------------------------------------------- /docs/slides/images/multi-versions.drawio: -------------------------------------------------------------------------------- 1 | 7VnRkpowFP2aPOoYEIRHdXHbTjvTme1MO32LECFb4DIhrtqHfnsTCSLG7brtgttpXxxySC7knJPkXkT2PNveclIkHyCiKbJG0RbZN8iyXGckfxWwqwBnpIGYs6iCcAPcse9Ug3W3NYtoWWEaEgCpYEXZGh1CntNQtDDCOWza3VaQtp9akJgawF1IUhP9zCKRVKhXT0vhbyiLk/rJuJ5fRurOGigTEsHmCLIDZM85gKiusu2cpoq7mpdq3OKRu4cX4zQXlwxYfIH7d28Xt8DdT5+/fB1v8AYGOsoDSdd6wn48HA4HOYUHlg1GQ2+IVchqBmJX08JhnUdURR4he7ZJmKB3BQnV3Y30gcQSkaWyheXlCnKxIBlLlQcyyEFiJGVxLpspXcm3n3EQRDDIdcAVS9M5pMD3T7NXXkjDUOKl4PCNHt1Zes7YUSP0PCgXdPsoQfhAu7QrhYwKvpNd9ACrlu5g1aq5aXS3xhpLjjSvBSbaavEhcqOGvNCCPEMcyxAnzpQ4S1ImA5YLykko2AMdOEM8KLB7faEiQr3VWaHc0KPLVTdC4asrZRtKrUaPKGVJpZwrKNUF7/a1eR+b25fzCravDrieXJtqx6BaEm0QKycs2uzVTIVULQMJKFqYPGCn+kbGokgNn3Fasu9kuQ+lWCxArpz9NJwZcm5UrLWAskoRsLHJ5JDTkx2phs4I2IFiflsx31TMOSOY3ZVg7n/BnicYPrPGelVs8l+x5ylmXVkw3xDsh4wzzNl2UHCQNFHZXLK8kyPoiN6B/0IEuycrYmQSjHs9dbBlEEcjWaDpJnCRQAw5SYMGnbWpbfq8Byg0ofdUiJ2uNpXln6b7d0sS9bq/VkPODtY8pL+ioeonCI+peMqQprqcpkSln62HntNqP3TKOdkdddCbRBP5owIa0xz2zV3LRIsLu9cma2xSvUBjmsNM/sBH+JX66OKK6UV8ZP1NPsLPNZLVh5HMUk8VeZ1u71crtL0TgrF5HPR7Gpj1nizz+ua+n69R3pPVRL/Um8npx+mnNwb3ZnZ6aQp5eRZ7TtG25n3lSxg77RXiO4ZMdp8yeYZKMozMR+VvKYDTvyYTPa3NzmSih08k/XyMNb/GomCCpnM0dVHgIG+BZhMU+Mi30SxAgYu8AE2df32B2E/r6PYqo3mEGBKVCSn2CV0oFP+/syRegDqrzZx32QHgdkac+T1J+d8fo6m3d7u397+HphPkufrCN8l9vf5/CbufuH3cmdtls/nrsEpum/9f7eAn -------------------------------------------------------------------------------- /docs/slides/images/ohhh.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xieby1/nix_config/eecf06aa8a787aaaaa4bdfca7984d45d768f812a/docs/slides/images/ohhh.mp4 -------------------------------------------------------------------------------- /docs/slides/images/slides_location.drawio: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /docs/slides/images/ubuntu-icon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/slides/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xieby1/nix_config/eecf06aa8a787aaaaa4bdfca7984d45d768f812a/docs/slides/index.md -------------------------------------------------------------------------------- /home.nix: -------------------------------------------------------------------------------- 1 | #MC # home.nix 2 | #MC 3 | #MC `home.nix`是home-manager的入口配置文件,它导入了3个nix文件: 4 | #MC 5 | #MC * [`./opt.nix`](./opt.nix.md):我定义的全局变量 6 | #MC * [`./usr/cli.nix`](./usr/cli.nix.md):我的所有CLI程序的配置 7 | #MC * [`./usr/gui.nix`](./usr/gui.nix.md):我的所有GUI程序的配置 8 | #MC 9 | #MC 因为部分系统不需要GUI程序,比如安卓手机nix-on-droid或是树莓派等。 10 | #MC 我利用环境变量`DISPLAY`用于判断是否导入GUI程序的配置。 11 | 12 | { config, pkgs, stdenv, lib, ... }: 13 | let 14 | opt = import ./opt.nix; 15 | in { 16 | imports = [ 17 | ./usr/modules/cachix.nix 18 | ./usr/cli.nix 19 | ] ++ lib.optionals opt.isGui [ 20 | ./usr/gui.nix 21 | ]; 22 | 23 | home.stateVersion = "19.09"; 24 | programs.home-manager.enable = true; 25 | news.display = "silent"; 26 | } 27 | -------------------------------------------------------------------------------- /modules/cachix.nix: -------------------------------------------------------------------------------- 1 | #MC 用于自动push包到cachix的模块。 2 | #MC 尽管cachix watch-store能自动push,但是我想更细粒度地管理需要push的包,所以有了这个模块。 3 | { config, pkgs, lib, ...}: 4 | 5 | { 6 | options = { 7 | cachix_packages = lib.mkOption { 8 | type = lib.types.listOf lib.types.package; 9 | default = []; 10 | description = '' 11 | This list of packages. 12 | 13 | If the the cachix.dhall file exists and cachix_packages is not empty, 14 | then the packages in cachix_packages will be pushed to cachix. 15 | ''; 16 | }; 17 | cachix_dhall = lib.mkOption { 18 | type = lib.types.str; 19 | default = "/home/xieby1/Gist/Config/cachix.dhall"; 20 | description = '' 21 | The path of cachix.dhall. 22 | ''; 23 | }; 24 | cachix_name = lib.mkOption { 25 | type = lib.types.str; 26 | default = "xieby1"; 27 | description = '' 28 | The cachix name. 29 | ''; 30 | }; 31 | _cachix_push = lib.mkOption { 32 | type = lib.types.str; 33 | default = '' 34 | echo Pushing packages to cachix: 35 | ${lib.concatMapStrings (x: "echo 📦"+x+"\n") config.cachix_packages} 36 | ${pkgs.cachix}/bin/cachix -c ${config.cachix_dhall} push ${config.cachix_name} ${builtins.toString config.cachix_packages} 37 | ''; 38 | description = '' 39 | (Internal usage) The script of pushing packages to cachix. 40 | ''; 41 | }; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /nix/nix.conf: -------------------------------------------------------------------------------- 1 | # see `man nix.conf` for details 2 | 3 | experimental-features = nix-command flakes 4 | substituters = https://cache.nixos.org/ https://nix-on-droid.cachix.org/ https://xieby1.cachix.org 5 | trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= xieby1.cachix.org-1:hVhQjWqdV3oGsSnyXSvzPgmDqcKm+EeKFtqsNK+eRew= 6 | # make builtins.fetchurl expire in a long time 7 | # although `man nix.conf` says tarball-ttl default is 4294967295 8 | # `nix show-config` show default is 3600 (1 hour) 9 | tarball-ttl = 4294967295 # max 32bit integer 10 | -------------------------------------------------------------------------------- /opt.nix: -------------------------------------------------------------------------------- 1 | #MC # opt.nix 2 | #MC 3 | #MC nix语言中只有`let ... in`来定义局部变量,没有提供全局变量的语法支持。 4 | #MC 但在我的nix配置中又很需要一些“全局变量”来方便统一的管理多个配置文件。 5 | #MC 有2种可行的方案来实现全局变量:module和import。 6 | #MC 7 | #MC ## module 8 | #MC 9 | #MC nixpkgs的module能够还不错地实现“全局变量”。 10 | #MC 想了解module?可以去看看[NixOS wikiL modules](https://nixos.wiki/wiki/NixOS_modules)。 11 | #MC 或者看看nixpkgs源码关于modules.nix的部分`/lib/modules.nix`。 12 | #MC 13 | #MC 要注意的是,基于module的“全局变量”也会有**局限**的。 14 | #MC module是用过imports变量导入的,若在imports语句访问“全局变量”,nix的lazy evaluation的特性会导致死循环。 15 | #MC 这也是为什么老版本的[home.nix](./home.nix.md)中判断是否需要导入[./usr/gui.nix](./usr/gui.nix.md), 16 | #MC 我没有使用`config.isGui`而是再次使用getEnv访问环境变量。 17 | #MC 当然这个不足也是我放弃使用的module主要原因。 18 | #MC 19 | #MC ## import 20 | #MC 21 | #MC 通过在配置文件中import opt.nix也能还不错的实现“全局变量”。 22 | #MC import方法的最大优势是能够在module imports语句中避免死循环。 23 | #MC 24 | #MC 这个方法的不足之处在于每个需要使用全局变量的文件都需要import opt.nix。 25 | #MC 但这个不方便之处,相对imports死循环,没那么让人难受。 26 | { 27 | isMinimalConfig = false; 28 | #MC `proxyPort`:代理端口号,诸多网络程序需要用,比如clash和tailscale。 29 | proxyPort = 8889; 30 | #MC `isCli`和`isGui`:通过环境变量`DISPLAY`来判断是否是CLI或GUI环境。 31 | #MC 这个方法有**局限**,比如ssh连接到一台有GUI的电脑上,ssh里是没有设置环境变量`DISPLAY`的。 32 | #MC 因此更好的方法是在opt-local.nix中写入固定的isCli和isGui值。 33 | isCli = (builtins.getEnv "DISPLAY")==""; 34 | isGui = (builtins.getEnv "DISPLAY")!=""; 35 | #MC `isNixOnDroid`:通过用户名来判断是否是nix-on-droid。 36 | isNixOnDroid = (builtins.getEnv "USER")=="nix-on-droid"; 37 | #MC `isWSL2`:通过环境变量`WSL_DISTRO_NAME`来判断是否是WSL2。 38 | isWSL2 = (builtins.getEnv "WSL_DISTRO_NAME")!=""; 39 | } 40 | #MC ### 本地配置 41 | #MC 42 | #MC 引入opt-local.nix,方便本地进行自定义,避免我的nix配置中出现过多设备特定代码(即一堆if else判断语句)。 43 | #MC 为了减少设备特定代码,每个设备都有自己的opt-local.nix。 44 | #MC 目前的想法是不将opt-local.nix加入git仓库,以实现“设备特定”。 45 | #MC 相比opt.nix,opt-local.nix的配置具备更高的优先级。 46 | // ( 47 | if (builtins.pathExists ./opt-local.nix) 48 | then import ./opt-local.nix 49 | else {} 50 | ) 51 | -------------------------------------------------------------------------------- /overlays.nix: -------------------------------------------------------------------------------- 1 | #MC # nixpkgs overlays 2 | #MC 3 | [ 4 | #MC ## nixpkgs overlays for RISC-V 5 | #MC This file could be treated as a todo list of porting nixpkgs to RISC-V Linux. 6 | (self: super: super.lib.optionalAttrs (builtins.currentSystem == "riscv64-linux") { 7 | bison = super.bison.overrideAttrs (old: { 8 | doInstallCheck = false; 9 | }); 10 | coreutils = super.coreutils.overrideAttrs (old: { 11 | doCheck = false; 12 | }); 13 | diffutils = super.diffutils.overrideAttrs (old: { 14 | doCheck = false; 15 | }); 16 | findutils = super.findutils.overrideAttrs (old: { 17 | doCheck = false; 18 | }); 19 | gnugrep = super.gnugrep.overrideAttrs (old: { 20 | doCheck = false; 21 | }); 22 | hello = super.hello.overrideAttrs (old: { 23 | doCheck = false; 24 | }); 25 | cmakeMinimal = super.cmakeMinimal.overrideAttrs (old: { 26 | configureFlags = [ 27 | # https://gitlab.kitware.com/cmake/cmake/-/issues/20895 28 | "LDFLAGS=-latomic" 29 | ] ++ old.configureFlags; 30 | }); 31 | cmake = super.cmake.overrideAttrs (old: { 32 | configureFlags = [ 33 | "LDFLAGS=-latomic" 34 | ] ++ old.configureFlags; 35 | }); 36 | libuv = super.libuv.overrideAttrs (old: { 37 | # hangs 38 | doCheck = false; 39 | }); 40 | libseccomp = super.libseccomp.overrideAttrs (old: { 41 | # failed 42 | doCheck = false; 43 | }); 44 | #MC My attempt of overlaying psutil in llvm: 45 | #MC 46 | #MC Overlay below is not work currently, due to llvmPackages and python3Packages cannot be esaily override. 47 | #MC The best way could be patch the nixpkgs source code. 48 | #MC 49 | #MC ```nix 50 | #MC llvmPackages = super.llvmPackages.overrideDerivation (oldllvmPackages: rec { 51 | #MC libllvm = oldllvmPackages.libllvm.overrideAttrs (old: { 52 | #MC # psutil check failed 53 | #MC doCheck = false; 54 | #MC }); 55 | #MC llvm = libllvm; 56 | #MC llvm-manpages = super.lowPrio (libllvm.override { 57 | #MC enableManpages = true; 58 | #MC python3 = super.python3; # don't use python-boot 59 | #MC }); 60 | #MC }); 61 | #MC python3Packages = super.python3Packages.overrideScope (final: prev: { 62 | #MC psutil = prev.psutil.overrideAttrs (old: { 63 | #MC # failed 64 | #MC doInstallCheck = false; 65 | #MC }); 66 | #MC }); 67 | #MC ``` 68 | #MC 69 | #MC To bypass the doInstallCheck of psutil (libbpf -> libllvm -> python3Packages.psutil), 70 | #MC I disable the libpbf support in systemd as below. 71 | systemd = super.systemd.override { 72 | withLibBPF = false; 73 | }; 74 | e2fsprogs = super.e2fsprogs.overrideAttrs (old: { 75 | # failed 76 | doCheck = false; 77 | }); 78 | libarchive = super.libarchive.overrideAttrs (old: { 79 | # failed 80 | doCheck = false; 81 | }); 82 | elfutils = super.elfutils.overrideAttrs (old: { 83 | # failed 84 | doCheck = false; 85 | doInstallCheck = false; 86 | }); 87 | }) 88 | ] 89 | -------------------------------------------------------------------------------- /scripts/fhs-shell/dynamorio.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | { pkgs ? import {} }: 3 | (pkgs.buildFHSUserEnv { 4 | name = "dynamoRIO"; 5 | targetPkgs = pkgs: with pkgs; [ 6 | (hiPrio gcc) 7 | snappy 8 | zlib 9 | zlib.dev 10 | lz4 11 | lz4.dev 12 | libunwind 13 | libunwind.dev 14 | ]; 15 | profile = '' 16 | export CC=gcc 17 | export CXX=g++ 18 | ''; 19 | }).env 20 | -------------------------------------------------------------------------------- /scripts/fhs-shell/hello.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | let 3 | pkgs = import {}; 4 | fhs = pkgs.buildFHSUserEnv { 5 | name = "hello"; 6 | targetPkgs = p: with p; [ 7 | hello 8 | ]; 9 | profile = '' 10 | export MIAO=1 11 | ''; 12 | }; 13 | in 14 | fhs.env 15 | -------------------------------------------------------------------------------- /scripts/fhs-shell/index.md: -------------------------------------------------------------------------------- 1 | See all fhs-shell scripts on [Github repo: scripts/fhs-shell]({{ site.repo_url }}/scripts/fhs-shell) 2 | -------------------------------------------------------------------------------- /scripts/fhs-shell/pin.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | { pkgs ? import {} }: 3 | let 4 | pin = builtins.derivation { 5 | name = "pin-3.25"; 6 | system = builtins.currentSystem; 7 | src = pkgs.fetchurl { 8 | url = "https://software.intel.com/sites/landingpage/pintool/downloads/pin-3.25-98650-g8f6168173-gcc-linux.tar.gz"; 9 | hash = "sha256-Q8D0QSNLDly2XK+XFOYdMxbx5N33eGVzESGTCgWGX6E="; 10 | }; 11 | builder = pkgs.writeShellScript "pin-builder" '' 12 | # make mkdir and tar and other useful tools added to PATH 13 | source ${pkgs.stdenv}/setup 14 | mkdir -p $out 15 | # strip leading directory 16 | tar -xf $src --strip-components=1 --directory=$out 17 | ''; 18 | }; 19 | in 20 | (pkgs.buildFHSUserEnv { 21 | name = "pin"; 22 | targetPkgs = pkgs: with pkgs; [ 23 | ]; 24 | profile = '' 25 | PATH+=":${pin}" 26 | ''; 27 | }).env 28 | -------------------------------------------------------------------------------- /scripts/fhs-shell/spec.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | { pkgs ? import {} }: 3 | let 4 | zigenv = import /home/xieby1/Codes/nix-zig-stdenv { 5 | target = "x86_64-unknown-linux-musl"; 6 | }; 7 | noPrefixStaticStdenvCC = pkgs.runCommand "linkCC" {} '' 8 | mkdir -p $out/bin 9 | for file in ${pkgs.pkgsStatic.stdenv.cc}/bin/*; do 10 | ln -s $file $out/bin/''${file##*-} 11 | done 12 | ''; 13 | in 14 | (pkgs.buildFHSUserEnv { 15 | name = "spec"; 16 | targetPkgs = pkgs: with pkgs; [ 17 | # (hiPrio zigenv.pkgs.stdenv.cc) 18 | # (hiPrio clangStdenv.cc) 19 | # (hiPrio gcc) 20 | # (hiPrio pkgsStatic.stdenv.cc) 21 | # noPrefixStaticStdenvCC 22 | gfortran 23 | # uclibc 24 | # musl 25 | # musl.dev 26 | glibc.static 27 | glibc.dev 28 | ]; 29 | }).env 30 | -------------------------------------------------------------------------------- /scripts/fhs-shell/x11.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | # https://ryantm.github.io/nixpkgs/builders/special/fhs-environments/ 3 | 4 | { pkgs ? import {} }: 5 | 6 | (pkgs.buildFHSUserEnv { 7 | name = "simple-x11-env"; 8 | targetPkgs = pkgs: (with pkgs; 9 | [ udev 10 | alsa-lib 11 | ]) ++ (with pkgs.xorg; 12 | [ libX11 13 | libXcursor 14 | libXrandr 15 | ]); 16 | multiPkgs = pkgs: (with pkgs; 17 | [ udev 18 | alsa-lib 19 | ]); 20 | runScript = "bash"; 21 | }).env 22 | -------------------------------------------------------------------------------- /scripts/fhs-shell/xilinx.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | # based on https://github.com/nix-community/nix-environments 3 | # git commit: 40d9d98bab7750bb5a1a9a3b5bcc1c91a652f3be 4 | { pkgs ? import {} }: 5 | let 6 | name = "xilinx-fhs"; 7 | h_content = builtins.toFile "h_content" '' 8 | # ${pkgs.lib.toUpper "${name} usage"} 9 | 10 | **Commands** 11 | 12 | * Show this help: `h` 13 | * Start Vitis HLS IDE: `vitis_hls` 14 | * Start Vitis HLS REPL: `vitis_hls -i` 15 | 16 | **Files** 17 | 18 | * Vitis HLS Doc: `2022.vitis_hls.ug1399.pdf` 19 | * Local command doc: `Xilinx/Vitis/2022.2/doc/eng/man/` 20 | * TODO: `ug871-vivado-high-level-synthesis-tutorial.pdf` 21 | * TODO: `ug902-vivado-high-level-synthesis.pdf` 22 | 23 | **Examples** 24 | 25 | * [Vitis HLS examples](https://github.com/Xilinx/Vitis-HLS-Introductory-Examples) 26 | * Run an example: `vitis_hls -f run_hls.tcl` 27 | ''; 28 | _h_ = pkgs.writeShellScriptBin "h" '' 29 | ${pkgs.glow}/bin/glow ${h_content} 30 | ''; 31 | in 32 | (pkgs.buildFHSUserEnv { 33 | inherit name; 34 | targetPkgs = pkgs: with pkgs; [ 35 | _h_ 36 | 37 | bash 38 | coreutils 39 | zlib 40 | lsb-release 41 | stdenv.cc.cc 42 | ncurses5 43 | xorg.libXext 44 | xorg.libX11 45 | xorg.libXrender 46 | xorg.libXtst 47 | xorg.libXi 48 | xorg.libXft 49 | xorg.libxcb 50 | xorg.libxcb 51 | # common requirements 52 | freetype 53 | fontconfig 54 | glib 55 | gtk2 56 | gtk3 57 | # vitis_hls gcc needs 58 | glibc.dev 59 | 60 | # to compile some xilinx examples 61 | opencl-clhpp 62 | ocl-icd 63 | opencl-headers 64 | 65 | # from installLibs.sh 66 | graphviz 67 | (lib.hiPrio gcc) 68 | unzip 69 | nettools 70 | ]; 71 | multiPkgs = null; 72 | profile = '' 73 | export LC_NUMERIC="en_US.UTF-8" 74 | source ~/Xilinx/Vitis_HLS/*/settings64.sh 75 | h 76 | ''; 77 | }).env 78 | -------------------------------------------------------------------------------- /scripts/pkgs/7z.nix: -------------------------------------------------------------------------------- 1 | # TODO: 7z need dynamical link 7z.so 2 | # but static compilation prevents this behavior? 3 | {pkgs ? import {}}: 4 | let cross = import /home/xieby1/Codes/nix-zig-stdenv { 5 | inherit pkgs; 6 | target = "x86_64-unknown-linux-musl"; 7 | }; 8 | in 9 | cross.pkgs.p7zip.overrideAttrs (old: { 10 | postPatch = old.postPatch + '' 11 | sed -i '/CC=/d' makefile.machine 12 | sed -i '/CXX=/d' makefile.machine 13 | ''; 14 | }) 15 | -------------------------------------------------------------------------------- /scripts/pkgs/android.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nix-build 2 | 3 | # https://nixos.wiki/wiki/Android 4 | # Building Android applications with the Nix package manager: https://sandervanderburg.blogspot.com/2014/02/reproducing-android-app-deployments-or.html 5 | let 6 | # current nixpkgs-unstable 7 | pkgs = import (with import {}; fetchFromGitHub { 8 | owner = "NixOS"; 9 | repo = "nixpkgs"; 10 | rev = "1c851e8c92b76a00ce84167984a7ec7ba2b1f29c"; 11 | hash = "sha256-vRxti8pOuXS0rJmqjbD8ueEEFXWSK22ISHoCWkhgzzg="; 12 | }){ 13 | config.android_sdk.accept_license = true; 14 | config.allowUnfree = true; 15 | }; 16 | in pkgs.androidenv.emulateApp { 17 | name = "androidEmuApp"; 18 | app = pkgs.fetchurl { 19 | url = "https://github.com/SimpleMobileTools/Simple-Calendar/releases/download/6.13.5/calendar-release.apk"; 20 | sha256 = "12vzcd6klnk38b55szmd5a8ydc70fk6aak31qvlild83jy9z21zk"; 21 | }; 22 | enableGPU = false; 23 | # get these info by `pkgs/development/mobile/androidenv/repo.json` 24 | # see if installed `sdkmanager --list` 25 | platformVersion = "32"; 26 | abiVersion = "x86"; 27 | systemImageType = "google_apis"; 28 | 29 | package = "com.simplemobiletools.calendar.pro"; 30 | 31 | avdHomeDir = "$HOME/.android"; 32 | sdkExtraArgs = { 33 | includeSystemImages = true; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /scripts/pkgs/appimage_runtime.nix: -------------------------------------------------------------------------------- 1 | let 2 | pkgs = import {}; 3 | squashfuse-with-headers = pkgs.pkgsStatic.squashfuse.overrideAttrs (old: { 4 | src = pkgs.fetchurl { 5 | url = "https://github.com/vasi/squashfuse/archive/e51978c.tar.gz"; 6 | hash = "sha256-9UQCmtMNj73k5FQMV0uM3G04uU3wJamNhVGpRB8H00E="; 7 | }; 8 | postInstall = '' 9 | mkdir -p $out/include/squashfuse 10 | cp *.h $out/include/squashfuse 11 | ''; 12 | }); 13 | srcRev = "c1ea7509bc179a05d907baca64f41875662f35f2"; 14 | in pkgs.stdenv.mkDerivation { 15 | name = "appimage-runtime"; 16 | src = pkgs.fetchFromGitHub { 17 | owner = "AppImage"; 18 | repo = "type2-runtime"; 19 | rev = "${srcRev}"; 20 | sha256 = "1gr853iz1x6pgyav3w1kqaaaz2ybbx67dcg74kj54yrwlakrh165"; 21 | }; 22 | nativeBuildInputs = with pkgs; [ 23 | pkg-config 24 | ]; 25 | buildInputs = (with pkgs.pkgsStatic; [ 26 | squashfuse-with-headers 27 | fuse 28 | zstd 29 | zlib 30 | 31 | lz4.out 32 | lzo 33 | lzma.out 34 | ]) ++ (with pkgs; [ 35 | glibc.static 36 | ]); 37 | sourceRoot = "source/src/runtime"; 38 | buildPhase = '' 39 | export CFLAGS="-std=gnu99 -s -Os -D_FILE_OFFSET_BITS=64 -DGIT_COMMIT=\"${srcRev}\" -T data_sections.ld -ffunction-sections -fdata-sections -Wl,--gc-sections -static" 40 | export LIBS="-lsquashfuse -lsquashfuse_ll -lzstd -lz -llz4 -llzo2 -llzma" 41 | $CC -I${squashfuse-with-headers}/include/squashfuse -I${pkgs.pkgsStatic.fuse}/include/fuse -o runtime-fuse2.o -c $CFLAGS runtime.c 42 | $CC $CFLAGS runtime-fuse2.o $LIBS -lfuse -o runtime-fuse2 43 | ''; 44 | installPhase = '' 45 | mkdir -p $out/bin 46 | cp runtime-fuse2 $out/bin/ 47 | ''; 48 | } 49 | 50 | # in pkgs.mkShell { 51 | # name = "appimage-runtime"; 52 | # packages = (with pkgs.pkgsStatic; [ 53 | # squashfuse-with-headers 54 | # fuse 55 | # zstd 56 | # zlib 57 | 58 | # lz4.out 59 | # lzo 60 | # lzma.out 61 | # ]) ++ (with pkgs; [ 62 | # glibc.static 63 | # pkg-config 64 | # ]); 65 | # } 66 | 67 | # in (pkgs.buildFHSUserEnv { 68 | # name = "appimage-runtime-fhs"; 69 | # targetPkgs = pkgs: (with pkgs.pkgsStatic; [ 70 | # squashfuse-with-headers 71 | # fuse 72 | # zstd 73 | # zlib 74 | 75 | # lz4.out 76 | # lzo 77 | # lzma.out 78 | # ]) ++ (with pkgs; [ 79 | # glibc.static 80 | # pkg-config 81 | # ]); 82 | # }).env 83 | -------------------------------------------------------------------------------- /scripts/pkgs/coremarks.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-build -o coremarks 2 | {pkgs ? import {}}: 3 | let 4 | # function mkCoremark 5 | mkCoremark = { 6 | pkgs ? import {}, 7 | stdenv ? pkgs.stdenv, 8 | simple ? false, 9 | }: 10 | let 11 | name = "coremark"; 12 | variant = pkgs.lib.concatStrings [ 13 | "${stdenv.targetPlatform.config}" 14 | # TODO: all zig-env are static? 15 | # (if stdenv.targetPlatform.isStatic then ".static" else "") 16 | (if simple then ".simple" else "") 17 | ]; 18 | in 19 | stdenv.mkDerivation { 20 | inherit name; 21 | src = pkgs.fetchFromGitHub { 22 | owner = "eembc"; 23 | repo = "coremark"; 24 | rev = "d26d6fdcefa1f9107ddde70024b73325bfe50ed2"; 25 | sha256 = "0kd6bnrnd3f325ypxzn0w5ii4fmc98h16sbvvjikvzhm78y60wz3"; 26 | }; 27 | preBuild = '' 28 | # no float point insts 29 | export CFLAGS="-DHAS_FLOAT=0" 30 | 31 | # simple assumes CC = gcc, this is a bug! 32 | sed -i '/CC =/d' simple/core_portme.mak 33 | ${if simple 34 | then "export PORT_DIR=simple" 35 | else ""} 36 | ''; 37 | buildFlags = ["compile"]; 38 | installPhase = '' 39 | mkdir -p $out/bin 40 | mv coremark.exe $out/bin/${name}.${variant}.exe 41 | ''; 42 | }; 43 | zig-env-src = pkgs.fetchFromGitHub { 44 | owner = "Cloudef"; 45 | repo = "nix-zig-stdenv"; 46 | rev = "6de72ec32ecf0cfb9ad9dab5a8400d532e17f8c5"; 47 | hash = "sha256-hQHOzjkHWO5YxQb3mgZJOfyIuvbiLFocVCMK/A9HTic="; 48 | }; 49 | in 50 | pkgs.symlinkJoin { 51 | name = "coremarks"; 52 | paths = [ 53 | # x86_64 linux 54 | (mkCoremark { 55 | inherit (import zig-env-src { 56 | target = "x86_64-unknown-linux-gnu"; 57 | }) stdenv; 58 | }) 59 | # x86_64 linux static 60 | (mkCoremark { 61 | inherit (import zig-env-src { 62 | target = "x86_64-unknown-linux-musl"; 63 | }) stdenv; 64 | }) 65 | # aarch64 linux 66 | (mkCoremark { 67 | inherit (import zig-env-src { 68 | target = "aarch64-unknown-linux-gnu"; 69 | }) stdenv; 70 | }) 71 | # aarch64 linux static 72 | (mkCoremark { 73 | inherit (import zig-env-src { 74 | target = "aarch64-unknown-linux-musl"; 75 | }) stdenv; 76 | }) 77 | # riscv64 linux 78 | # (mkCoremark { 79 | # inherit (import zig-env-src { 80 | # target = "riscv64-unknown-linux-gnu"; 81 | # }) stdenv; 82 | # }) 83 | # riscv64 linux static 84 | (mkCoremark { 85 | inherit (import zig-env-src { 86 | target = "riscv64-unknown-linux-musl"; 87 | }) stdenv; 88 | }) 89 | # x86_64 windows 90 | (mkCoremark { 91 | inherit (import zig-env-src { 92 | target = "x86_64-w64-mingw32"; 93 | }) stdenv; 94 | simple = true; 95 | }) 96 | # x86_64 darwin can only compiled on x86_64/aarch64 darwin 97 | # https://github.com/NixOS/nixpkgs/issues/165804 98 | # while it is possible compile manually inside darling 99 | #(mkCoremark { 100 | # stdenv = pkgs.pkgsCross.x86_64-darwin.stdenv; 101 | #}) 102 | ]; 103 | } 104 | -------------------------------------------------------------------------------- /scripts/pkgs/cross_mips.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-env -i -f 2 | # xieby1: 2022.05.16 3 | with (import {crossSystem = "mips-linux";}); { 4 | gdb = lib.lowPrio buildPackages.gdb; 5 | gcc = lib.lowPrio buildPackages.gcc; 6 | } 7 | -------------------------------------------------------------------------------- /scripts/pkgs/cross_static_hello.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nix-build 2 | let 3 | pkgs = import (builtins.fetchTarball { 4 | url = "https://github.com/NixOS/nixpkgs/archive/e60c3e2abb8ae9df3d89820c706cc736fad01ff7.tar.gz"; 5 | sha256 = "0vyjpf1jw4cvw7kfbk055faq08q4swz6v1h2mf9zw4r8frhqa73w"; 6 | }) {}; 7 | in 8 | pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic.glib 9 | -------------------------------------------------------------------------------- /scripts/pkgs/fhs_helloworld.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-build -o fhs_helloworld 2 | 3 | # xieby1: 2022.11.17 4 | # inspired by 5 | # https://discourse.nixos.org/t/derivation-that-builds-standard-linux-binaries/21557/4 6 | # https://github.com/NixOS/nixpkgs/compare/master...ElvishJerricco:nixpkgs:run-in-fhs 7 | # TODO-1: 8 | # I have copy all dependencies to a directory (ld-linux-x86-64.so.2, libc.so) 9 | # But result cannot run in chroot, error message is `cannot find libc.so`. 10 | # TODO-2: 11 | # I didn't find a proper package/bundle tool 12 | # * nix-bundle: not work 13 | # * appimage: depends on libfuse.so, cannot run directly on nixos 14 | 15 | { pkgs ? import {} }: 16 | let 17 | name = "helloworld"; 18 | fhsEnv = pkgs.buildFHSUserEnv { 19 | name = "${name}-fhs"; 20 | targetPkgs = pkgs: with pkgs; [ 21 | gcc 22 | # gcc-unwrapped binutils-unwrapped 23 | glibc 24 | glibc.dev 25 | ]; 26 | # refer to https://discourse.nixos.org/t/using-a-raw-gcc-inside-buildfhsuserenv/12864 27 | runScript = (pkgs.writeShellScript "${name}-fhsbuilder" '' 28 | # For gcc-unwrapped and binutils-unwrapped 29 | # export LIBRARY_PATH=/usr/lib 30 | # export C_INCLUDE_PATH=/usr/include 31 | # export CPLUS_INCLUDE_PATH=/usr/include 32 | # export CMAKE_LIBRARY_PATH=/usr/lib 33 | # export CMAKE_INCLUDE_PATH=/usr/include 34 | ## TODO: not work? have to add gcc -Wl,--dynamic-linker=/usr/lib64/ld-linux-x86-64.so.2 ? 35 | # export LDFLAGS=--dynamic-linker=/usr/lib64/ld-linux-x86-64.so.2 36 | 37 | # For gcc 38 | export NIX_LDFLAGS="--dynamic-linker=/usr/lib64/ld-linux-x86-64.so.2" 39 | gcc $src -o $out 40 | ''); 41 | }; 42 | in 43 | builtins.derivation { 44 | inherit name; 45 | system = builtins.currentSystem; 46 | src = builtins.toFile "${name}.c" '' 47 | #include 48 | int main(void) { 49 | printf("Hello, world! \n"); 50 | return 0; 51 | } 52 | ''; 53 | builder = "${fhsEnv}/bin/${fhsEnv.name}"; 54 | } 55 | -------------------------------------------------------------------------------- /scripts/pkgs/fhs_spec2000_perl.nix: -------------------------------------------------------------------------------- 1 | let 2 | name = "perl"; 3 | pkgs = import {}; 4 | fhsEnv = pkgs.buildFHSUserEnv { 5 | name = "${name}-fhs"; 6 | targetPkgs = pkgs: with pkgs; [ 7 | gnumake 8 | ]; 9 | runScript = (pkgs.writeShellScript "${name}-fhsbuilder" '' 10 | ls 11 | cd $src/tools/src 12 | ls 13 | DOPERL=1 ./buildtools 14 | ''); 15 | }; 16 | in builtins.derivation { 17 | inherit name; 18 | system = builtins.currentSystem; 19 | src = /home/xieby1/Codes/spec2000; 20 | builder = "${fhsEnv}/bin/${fhsEnv.name}"; 21 | } 22 | -------------------------------------------------------------------------------- /scripts/pkgs/index.md: -------------------------------------------------------------------------------- 1 | See all fhs-shell scripts on [Github repo: scripts/pkgs]({{ site.repo_url }}/scripts/pkgs) 2 | -------------------------------------------------------------------------------- /scripts/pkgs/nix-binary-tarballs-new.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-build -o nix-binary-tarballs 2 | #MC # Nix official installer (new) 3 | #MC 4 | #MC Use nix (>2.18) binary-tarball script, which has not been merged into mainline nixpkgs. 5 | #MC 6 | #MC See [nix-binary-tarballs.nix](./nix-binary-tarballs.nix.md) for current nix binary-tarball script. 7 | let 8 | pkgs = import {}; 9 | nix_src = pkgs.fetchFromGitHub { 10 | owner = "NixOS"; 11 | repo = "nix"; 12 | rev = "d0c7da131fb64526bc72144949b6955c25367d92"; 13 | hash = "sha256-Z4RlluZjNXH5BdJiXoe0k43Ry9ptK3jHAsKjlQ3jVZg="; 14 | }; 15 | in pkgs.symlinkJoin { 16 | name = "nix-binary-tarballs"; 17 | paths = [ 18 | (pkgs.callPackage "${nix_src}/scripts/binary-tarball.nix" {}) 19 | (pkgs.callPackage "${nix_src}/scripts/binary-tarball.nix" { 20 | nix = pkgs.pkgsCross.riscv64.nix; 21 | system = pkgs.pkgsCross.riscv64.nix.stdenv.system; 22 | }) 23 | (pkgs.callPackage "${nix_src}/scripts/binary-tarball.nix" { 24 | nix = pkgs.pkgsCross.loongarch64-linux.nix; 25 | system = pkgs.pkgsCross.loongarch64-linux.nix.stdenv.system; 26 | }) 27 | ]; 28 | } 29 | -------------------------------------------------------------------------------- /scripts/pkgs/nix-docker-isa/default.nix: -------------------------------------------------------------------------------- 1 | #MC # 🐳Nix Docker🐋 for Multiple ISAs 2 | #MC 3 | #MC This script is inspired by https://github.com/nix-community/docker-nixpkgs/images/nix 4 | #MC 5 | #MC currently: this riscv64 nix docker can `nix-env -iA nixpkgs.hello/tmux` and so on, 6 | #MC which is completely built from source including toolchains (stdenv) in x86/aarch64/riscv64/... 7 | { pkgs ? import {} 8 | , pkgsCross ? pkgs 9 | , useTmux ? true 10 | }: 11 | let 12 | name = "nix-docker-${pkgsCross.stdenv.system}"; 13 | image = pkgs.dockerTools.buildImageWithNixDb { 14 | inherit name; 15 | copyToRoot = pkgs.buildEnv { 16 | name = "image-root"; 17 | paths = (with pkgsCross; [ 18 | bashInteractive 19 | cacert 20 | coreutils 21 | file 22 | gitMinimal 23 | gnutar 24 | nix 25 | openssh 26 | vim 27 | wget 28 | ] 29 | ++ lib.optional useTmux (tmux.override {withSystemd=false;}) 30 | ) ++ [ 31 | ./imageFiles 32 | ]; 33 | }; 34 | extraCommands = '' 35 | # for /usr/bin/env 36 | mkdir usr 37 | ln -s bin usr/bin 38 | 39 | # make sure /tmp exists 40 | mkdir -m 1777 tmp 41 | 42 | # need a HOME 43 | mkdir -vp root 44 | ''; 45 | config = { 46 | Cmd = if useTmux 47 | then [ "/bin/tmux" ] 48 | else [ "/bin/bash" ]; 49 | Env = [ 50 | "NIX_BUILD_SHELL=/bin/bash" 51 | "PAGER=cat" 52 | "PATH=/bin" 53 | "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" 54 | "USER=root" 55 | ]; 56 | }; 57 | }; 58 | in pkgs.writeShellScriptBin name '' 59 | command -v podman &> /dev/null || echo "podman not found TODO: install" || exit 1 60 | 61 | outName="$(basename ${image})" 62 | outHash=$(echo "$outName" | cut -d - -f 1) 63 | imageName=localhost/${name}:$outHash 64 | 65 | # check whether image has been loaded 66 | podman images $imageName | grep ${name} | grep $outHash &> /dev/null 67 | # image has not been loaded, then load it 68 | if [[ $? != 0 ]]; then 69 | podman load -i ${image} 70 | fi 71 | 72 | BINFMTS="" 73 | for binfmt in /run/binfmt/*; do 74 | BINFMTS+=" -v $(realpath $binfmt):$binfmt" 75 | done 76 | 77 | containerName=${name}-$outHash 78 | # run container 79 | OPTS=( 80 | "--name=$containerName" 81 | "$BINFMTS" 82 | "--network=host" 83 | "-it" 84 | "$imageName" 85 | ) 86 | eval "podman run ''${OPTS[@]}" 87 | podman commit $containerName $imageName 88 | podman rm $containerName 89 | '' 90 | -------------------------------------------------------------------------------- /scripts/pkgs/nix-docker-isa/dockers.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nix-build 2 | #MC # Instantiatio of nix dockers 3 | #MC 4 | #MC For more details, see [default.nix](./default.nix.md) 5 | { pkgs ? import {} 6 | , ... 7 | }: [ 8 | #MC ## x86_64 docker 9 | (import ./. {inherit pkgs; pkgsCross=pkgs.pkgsCross.gnu64;}) 10 | #MC ## aarhc64 docker 11 | (import ./. {inherit pkgs; pkgsCross=pkgs.pkgsCross.aarch64-multiplatform;}) 12 | #MC ## riscv64 docker 13 | (import ./. {inherit pkgs; pkgsCross=pkgs.pkgsCross.riscv64;}) 14 | ] 15 | -------------------------------------------------------------------------------- /scripts/pkgs/nix-docker-isa/imageFiles/etc/group: -------------------------------------------------------------------------------- 1 | root:x:0: 2 | wheel:x:1: 3 | kmem:x:2: 4 | tty:x:3: 5 | messagebus:x:4: 6 | disk:x:6: 7 | audio:x:17: 8 | floppy:x:18: 9 | uucp:x:19: 10 | lp:x:20: 11 | cdrom:x:24: 12 | tape:x:25: 13 | video:x:26: 14 | dialout:x:27: 15 | utmp:x:29: 16 | adm:x:55: 17 | keys:x:96: 18 | users:x:100: 19 | input:x:174: 20 | nixbld:x:30000:nixbld1,nixbld10,nixbld11,nixbld12,nixbld13,nixbld14,nixbld15,nixbld16,nixbld17,nixbld18,nixbld19,nixbld2,nixbld20,nixbld21,nixbld22,nixbld23,nixbld24,nixbld25,nixbld26,nixbld27,nixbld28,nixbld29,nixbld3,nixbld30,nixbld31,nixbld32,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9 21 | nogroup:x:65534: 22 | -------------------------------------------------------------------------------- /scripts/pkgs/nix-docker-isa/imageFiles/etc/nix/nix.conf: -------------------------------------------------------------------------------- 1 | # To bypass the problem of "unable to load seccomp BPF program: Invalid argument" 2 | # See: https://github.com/NixOS/nix/issues/5258 3 | filter-syscalls = false 4 | 5 | require-sigs = true 6 | substituters = https://cache.nixos.org/ 7 | trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= 8 | trusted-users = root 9 | -------------------------------------------------------------------------------- /scripts/pkgs/nix-docker-isa/imageFiles/etc/nsswitch.conf: -------------------------------------------------------------------------------- 1 | passwd: files mymachines systemd 2 | group: files mymachines systemd 3 | shadow: files 4 | 5 | hosts: files mymachines dns myhostname 6 | networks: files 7 | 8 | ethers: files 9 | services: files 10 | protocols: files 11 | rpc: files 12 | -------------------------------------------------------------------------------- /scripts/pkgs/nix-docker-isa/imageFiles/etc/passwd: -------------------------------------------------------------------------------- 1 | root:x:0:0:System administrator:/root:/bin/bash 2 | nixbld1:x:30001:30000:Nix build user 1:/var/empty:/run/current-system/sw/bin/nologin 3 | nixbld2:x:30002:30000:Nix build user 2:/var/empty:/run/current-system/sw/bin/nologin 4 | nixbld3:x:30003:30000:Nix build user 3:/var/empty:/run/current-system/sw/bin/nologin 5 | nixbld4:x:30004:30000:Nix build user 4:/var/empty:/run/current-system/sw/bin/nologin 6 | nixbld5:x:30005:30000:Nix build user 5:/var/empty:/run/current-system/sw/bin/nologin 7 | nixbld6:x:30006:30000:Nix build user 6:/var/empty:/run/current-system/sw/bin/nologin 8 | nixbld7:x:30007:30000:Nix build user 7:/var/empty:/run/current-system/sw/bin/nologin 9 | nixbld8:x:30008:30000:Nix build user 8:/var/empty:/run/current-system/sw/bin/nologin 10 | nixbld9:x:30009:30000:Nix build user 9:/var/empty:/run/current-system/sw/bin/nologin 11 | nixbld10:x:30010:30000:Nix build user 10:/var/empty:/run/current-system/sw/bin/nologin 12 | nixbld11:x:30011:30000:Nix build user 11:/var/empty:/run/current-system/sw/bin/nologin 13 | nixbld12:x:30012:30000:Nix build user 12:/var/empty:/run/current-system/sw/bin/nologin 14 | nixbld13:x:30013:30000:Nix build user 13:/var/empty:/run/current-system/sw/bin/nologin 15 | nixbld14:x:30014:30000:Nix build user 14:/var/empty:/run/current-system/sw/bin/nologin 16 | nixbld15:x:30015:30000:Nix build user 15:/var/empty:/run/current-system/sw/bin/nologin 17 | nixbld16:x:30016:30000:Nix build user 16:/var/empty:/run/current-system/sw/bin/nologin 18 | nixbld17:x:30017:30000:Nix build user 17:/var/empty:/run/current-system/sw/bin/nologin 19 | nixbld18:x:30018:30000:Nix build user 18:/var/empty:/run/current-system/sw/bin/nologin 20 | nixbld19:x:30019:30000:Nix build user 19:/var/empty:/run/current-system/sw/bin/nologin 21 | nixbld20:x:30020:30000:Nix build user 20:/var/empty:/run/current-system/sw/bin/nologin 22 | nixbld21:x:30021:30000:Nix build user 21:/var/empty:/run/current-system/sw/bin/nologin 23 | nixbld22:x:30022:30000:Nix build user 22:/var/empty:/run/current-system/sw/bin/nologin 24 | nixbld23:x:30023:30000:Nix build user 23:/var/empty:/run/current-system/sw/bin/nologin 25 | nixbld24:x:30024:30000:Nix build user 24:/var/empty:/run/current-system/sw/bin/nologin 26 | nixbld25:x:30025:30000:Nix build user 25:/var/empty:/run/current-system/sw/bin/nologin 27 | nixbld26:x:30026:30000:Nix build user 26:/var/empty:/run/current-system/sw/bin/nologin 28 | nixbld27:x:30027:30000:Nix build user 27:/var/empty:/run/current-system/sw/bin/nologin 29 | nixbld28:x:30028:30000:Nix build user 28:/var/empty:/run/current-system/sw/bin/nologin 30 | nixbld29:x:30029:30000:Nix build user 29:/var/empty:/run/current-system/sw/bin/nologin 31 | nixbld30:x:30030:30000:Nix build user 30:/var/empty:/run/current-system/sw/bin/nologin 32 | nixbld31:x:30031:30000:Nix build user 31:/var/empty:/run/current-system/sw/bin/nologin 33 | nixbld32:x:30032:30000:Nix build user 32:/var/empty:/run/current-system/sw/bin/nologin 34 | nobody:x:65534:65534:Unprivileged account (don't use!):/var/empty:/run/current-system/sw/bin/nologin 35 | -------------------------------------------------------------------------------- /scripts/pkgs/nix-docker-isa/imageFiles/etc/profile: -------------------------------------------------------------------------------- 1 | if [[ -e /etc/profile.d/nix.sh ]]; then 2 | . /etc/profile.d/nix.sh 3 | fi 4 | -------------------------------------------------------------------------------- /scripts/pkgs/nvchad.nix: -------------------------------------------------------------------------------- 1 | let 2 | flake-compat = import (builtins.fetchTarball { 3 | url = "https://github.com/edolstra/flake-compat/archive/0f9255e01c2351cc7d116c072cb317785dd33b33.tar.gz"; 4 | sha256 = "0m9grvfsbwmvgwaxvdzv6cmyvjnlww004gfxjvcl806ndqaxzy4j"; 5 | }); 6 | nix2nvchad = flake-compat { 7 | src= builtins.fetchTarball { 8 | url = "https://github.com/nix-community/nix4nvchad/archive/360ff667893eab066b3db906a856de2956fc710e.tar.gz"; 9 | sha256 = "01gvcg7nhzpizp4yzvww2x42i1ifsb7sygfwmqzrshqz47p1ir5y"; 10 | }; 11 | }; 12 | in nix2nvchad.defaultNix.packages."${builtins.currentSystem}".default 13 | -------------------------------------------------------------------------------- /scripts/pkgs/qemu_tests_tcg.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nix-build 2 | # TODO 3 | # Ref: ~/Documents/Tech/BT/QEMU/test.md 4 | let 5 | pkgs = import {}; 6 | in 7 | pkgs.stdenv.mkDerivation { 8 | buildInputs = with pkgs; [ 9 | # configure needs 10 | ninja 11 | pkg-config 12 | glib 13 | # make needs 14 | glibc.static # TODO: this will cause configure failed 15 | ]; 16 | buildFlags = [ 17 | "CFLAGS=-O" # override CFLAGS 18 | "build-tcg-tests-x86_64-linux-user" 19 | ]; 20 | } 21 | -------------------------------------------------------------------------------- /scripts/pkgs/qemus.nix: -------------------------------------------------------------------------------- 1 | # build by version 2 | # nix-build pkgs_qemu.nix -A v1_0 3 | # build by date 4 | # nix-build pkgs_qemu.nix -A d2011_12_01 5 | { pkgs ? import {} }: 6 | let 7 | pname = "qemu"; 8 | in rec { 9 | v1_0 = let 10 | version = "1.0"; 11 | in pkgs.gcc49Stdenv.mkDerivation { 12 | inherit pname version; 13 | src = pkgs.fetchurl { 14 | url = "https://download.qemu.org/qemu-${version}.tar.xz"; 15 | sha256 = "0y1018xia238pcqb7ad9v299b478c0838fiayl6qkzyd95gk0xbb"; 16 | }; 17 | buildInputs = with pkgs; [ 18 | zlib 19 | pkg-config 20 | glib 21 | python2 22 | ]; 23 | patches = [ 24 | ./qemu-v1.0.patch 25 | ]; 26 | configureFlags = [ 27 | "--target-list=x86_64-linux-user" 28 | "--disable-docs" 29 | ]; 30 | }; 31 | d2011_12_01 = v1_0; 32 | } 33 | -------------------------------------------------------------------------------- /scripts/pkgs/shellinabox.nix: -------------------------------------------------------------------------------- 1 | # https://github.com/NixOS/nixpkgs/issues/185773 2 | { lib, callPackage, fetchFromGitHub, fetchurl, openssl_1_1 }: 3 | 4 | ((callPackage (import (fetchFromGitHub { 5 | owner = "NixOS"; 6 | repo = "nixpkgs"; 7 | rev = "363ef08971726937cd6a63de0efef7f8ba657b18"; 8 | sha256 = "sha256-QRKAn5yLMyohZKsK72Vkd6HQUh3t5tDpFyI/Y7T3ASg="; 9 | }) { }).shellinabox.override) { openssl = openssl_1_1; }).overrideAttrs 10 | ({ patches, ... }: { 11 | patches = patches ++ [ 12 | # OpenSSL 1.1 13 | (fetchurl { 14 | url = 15 | "https://github.com/shellinabox/shellinabox/commit/c32f3d365a0848eb6b3350ec521fcd4d1d098295.patch"; 16 | hash = "sha256-Q8otJUip1YQJb0ZSF89BjSvrCh4PQe4R7Rb7mtm33tk="; 17 | }) 18 | ]; 19 | }) 20 | -------------------------------------------------------------------------------- /scripts/shell/ccache.nix: -------------------------------------------------------------------------------- 1 | let 2 | pkgs = import {}; 3 | ccache_dir = toString ./. + "/.ccache"; 4 | ccache14Stdenv = pkgs.ccacheStdenv.override { 5 | stdenv = pkgs.gcc14Stdenv; 6 | extraConfig = '' 7 | export CCACHE_COMPRESS=1 8 | export CCACHE_DIR="${ccache_dir}" 9 | export CCACHE_UMASK=007 10 | if [ ! -d "$CCACHE_DIR" ]; then 11 | echo "=====" 12 | echo "Directory '$CCACHE_DIR' does not exist" 13 | echo "Please create it with:" 14 | echo " mkdir -m0770 '$CCACHE_DIR'" 15 | echo "=====" 16 | exit 1 17 | fi 18 | if [ ! -w "$CCACHE_DIR" ]; then 19 | echo "=====" 20 | echo "Directory '$CCACHE_DIR' is not accessible for user $(whoami)" 21 | echo "Please verify its access permissions" 22 | echo "=====" 23 | exit 1 24 | fi 25 | ''; 26 | }; 27 | ccacheMkShell = pkgs.mkShell.override { 28 | stdenv = ccache14Stdenv; 29 | }; 30 | in ccacheMkShell { 31 | name = "ccache-shell"; 32 | shellHook = '' 33 | mkdir -m0770 -p ${ccache_dir} 34 | ''; 35 | } 36 | -------------------------------------------------------------------------------- /scripts/shell/chipyard.nix: -------------------------------------------------------------------------------- 1 | let 2 | name = "chipyard"; 3 | pkgs = import {}; 4 | pkgsCirct1_30_0 = import (builtins.fetchTarball { 5 | url = "https://github.com/NixOS/nixpkgs/archive/0aca8f43c8dba4a77aa0c16fb0130237c3da514c.tar.gz"; 6 | }) {}; 7 | 8 | # currently latest spike 9 | my-spike = pkgs.spike.overrideAttrs (old: { 10 | version = "1.1.1-dev"; 11 | src = pkgs.fetchFromGitHub { 12 | owner = "riscv"; 13 | repo = "riscv-isa-sim"; 14 | rev = "4f916978cd17bd2e83cfca233d0fa40153fda5f4"; 15 | sha256 = "sha256-84YY9YMIa4YO5mVJ0gGMOWnD2/CnpEjIbB9EjA5+Glc="; 16 | }; 17 | }); 18 | 19 | h_content = builtins.toFile "h_content" '' 20 | # ${pkgs.lib.toUpper "${name} usage tips"} 21 | 22 | The conda cannot gracefully manage the dependencies, e.g. gcc's dynamic libraries. 23 | Instead, I replace conda with nix to manage the dependencies. 24 | 25 | * Show this help: `h` 26 | 27 | Init Repos 28 | 29 | * edit common.mk:1 `SHELL=bash` 30 | * `./scripts/init-submodules-no-riscv-tools-nolog.sh` 31 | 32 | Compiling Verilator 33 | 34 | * `make -C sims/verilator` 35 | 36 | Run Verilator 37 | 38 | * `./sims/verilator/simulator-chipyard.harness-RocketConfig ` 39 | ''; 40 | _h_ = pkgs.writeShellScriptBin "h" '' 41 | ${pkgs.glow}/bin/glow ${h_content} 42 | ''; 43 | in pkgs.mkShell { 44 | inherit name; 45 | packages = with pkgs; [ 46 | verilator 47 | dtc 48 | jq 49 | pkgsCirct1_30_0.circt 50 | my-spike 51 | 52 | _h_ 53 | ]; 54 | shellHook = '' 55 | export RISCV=${pkgs.pkgsCross.riscv64-embedded.stdenv.cc} 56 | 57 | h 58 | ''; 59 | } 60 | -------------------------------------------------------------------------------- /scripts/shell/cross_mips.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | # xieby1: 2022.07.03 3 | # let 4 | # pkgs = import {}; 5 | # in 6 | # pkgs.mkShell { 7 | # buildInputs = [ 8 | # pkgs.pkgsCross.mipsel-linux-gnu.stdenv.cc 9 | # ]; 10 | # } 11 | 12 | # xieby1: 2022.05.16 13 | let 14 | pkgs_mips_cross = import { 15 | crossSystem = "mips-linux"; 16 | }; 17 | pkgs = import {}; 18 | in 19 | pkgs.mkShell { 20 | buildInputs = (with pkgs_mips_cross; [ 21 | buildPackages.gdb 22 | buildPackages.gcc 23 | ]) ++ (with pkgs; [ 24 | qemu 25 | ]); 26 | } 27 | -------------------------------------------------------------------------------- /scripts/shell/cross_platform.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | # xieby1: 2022.04.26 3 | 4 | let 5 | pkgs_arm_cross = import { 6 | # get this config on my android 7 | # nix repl 8 | # builtins.currentSystem 9 | crossSystem = "aarch64-linux"; 10 | }; 11 | pkgs_arm_native = import { 12 | localSystem = "aarch64-linux"; 13 | crossSystem = "aarch64-linux"; 14 | }; 15 | pkgs = import {}; 16 | in 17 | pkgs.mkShell { 18 | buildInputs = with pkgs_arm_cross; [ 19 | # packages for cross compiling, run on local system (x86_64) 20 | stdenv.cc 21 | # here stdenv.cc is the same with buildPackages.gcc 22 | ] ++ (with pkgs_arm_native; [ 23 | # packages run on aarch64 24 | figlet 25 | ]) ++ (with pkgs; [ 26 | # packages run on local system (x86_64) 27 | qemu 28 | ]); 29 | } 30 | -------------------------------------------------------------------------------- /scripts/shell/devshell_hello.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | { system ? builtins.currentSystem }: 3 | let 4 | src = fetchTarball { 5 | url = "https://github.com/numtide/devshell/archive/9fddc998b4522694caaf4056e93154d2c11752cd.tar.gz"; 6 | sha256 = "0d7ra00843n4iyadhdxcr9m0vcn6fz54hfymms6nbdz0d2pjff06"; 7 | }; 8 | devshell = import src { inherit system; }; 9 | in 10 | devshell.mkShell { 11 | commands = [{ 12 | name = "hello"; 13 | command = "echo hello"; 14 | help = "print hello miao"; 15 | }]; 16 | } 17 | -------------------------------------------------------------------------------- /scripts/shell/gcc.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | let 3 | pkgs = import {}; 4 | in pkgs.mkShellNoCC { 5 | name = "gcc11"; 6 | packages = with pkgs; [ 7 | gcc11 8 | ]; 9 | } 10 | -------------------------------------------------------------------------------- /scripts/shell/hello.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | with import {}; 3 | # You will get a shell with hello executable, 4 | # and environment variable $name, $miao. 5 | mkShell { 6 | packages = [ 7 | hello 8 | ]; 9 | name = "test-env"; 10 | miao = "miao!"; 11 | } 12 | -------------------------------------------------------------------------------- /scripts/shell/index.md: -------------------------------------------------------------------------------- 1 | See all fhs-shell scripts on [Github repo: scripts/shell]({{ site.repo_url }}/scripts/shell) 2 | -------------------------------------------------------------------------------- /scripts/shell/pygame.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | #2022.05.18 3 | # pip install is usable in venv 4 | # e.g. 5 | # $ nix-shell 6 | # $ pip install [--user] graphviz2drawio 7 | let 8 | pkgs = import {}; 9 | in 10 | pkgs.mkShell { 11 | propagatedBuildInputs = with pkgs.python3Packages; [ 12 | pip 13 | venvShellHook 14 | ipython 15 | pygame 16 | ] ++ (with pkgs; [ 17 | ]); 18 | venvDir = "pygame"; 19 | } 20 | -------------------------------------------------------------------------------- /scripts/shell/python_fhs_venv.nix: -------------------------------------------------------------------------------- 1 | # https://nixos.wiki/wiki/Python 2 | # Python virtual environment 3 | 4 | # Execute this commands after entering fhs env 5 | # python -m venv .venv 6 | # source .venv/bin/activate 7 | 8 | let 9 | pkgs = import {}; 10 | in (pkgs.buildFHSUserEnv { 11 | name = "venv"; 12 | targetPkgs = p: (with p.python3Packages; [ 13 | pip 14 | virtualenv 15 | ipython 16 | ]); 17 | }).env 18 | -------------------------------------------------------------------------------- /scripts/shell/python_mach.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | let 3 | mach-nix = import (builtins.fetchGit { 4 | url = "https://github.com/DavHau/mach-nix"; 5 | ref = "refs/tags/3.4.0"; 6 | }) { 7 | pkgs = import {}; 8 | }; 9 | in 10 | mach-nix.mkPythonShell { 11 | requirements = '' 12 | expmcc 13 | ''; 14 | } 15 | -------------------------------------------------------------------------------- /scripts/shell/python_venv.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | #2022.05.18 3 | # pip install is usable in venv 4 | # e.g. 5 | # $ nix-shell 6 | # $ pip install [--user] graphviz2drawio 7 | let 8 | pkgs = import {}; 9 | in 10 | pkgs.mkShell { 11 | propagatedBuildInputs = with pkgs.python3Packages; [ 12 | pip 13 | pygraphviz 14 | venvShellHook 15 | ipython 16 | ] ++ (with pkgs; [ 17 | graphviz 18 | ]); 19 | venvDir = "venv"; 20 | } 21 | -------------------------------------------------------------------------------- /scripts/shell/qemu_plugins.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | # lxy's qemu plugins: http://172.17.103.58/lixinyu/qemu_plugins 3 | 4 | let 5 | pkgs = import {}; 6 | in pkgs.mkShell { 7 | packages = with pkgs; [ 8 | zlib.dev 9 | pkg-config 10 | glib.dev 11 | ]; 12 | QEMU_DIR = "~/Codes/qemu"; 13 | } 14 | -------------------------------------------------------------------------------- /scripts/shell/qemu_tests_tcg.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | # --pure: start a pure reproducible shell 3 | # 2022.04.24 4 | # Compile qemu/tests/tcg/x86_64/ 5 | # env CFLAGS=-O make -e build-tcg-tests-x86_64-linux-user 6 | { pkgs ? import {} }: 7 | let 8 | name = "nix"; 9 | in 10 | pkgs.mkShell { 11 | inherit name; 12 | buildInputs = with pkgs; [ 13 | glibc.static 14 | ]; 15 | inputsFrom = with pkgs; [ 16 | qemu 17 | ]; 18 | } 19 | -------------------------------------------------------------------------------- /scripts/shell/riscv-tests.nix: -------------------------------------------------------------------------------- 1 | let 2 | name = "riscv-tests"; 3 | pkgs = import {}; 4 | h_content = builtins.toFile "h_content" '' 5 | # ${pkgs.lib.toUpper "${name} compiling tips"} 6 | 7 | * `git submodule update --init --recursive` 8 | * `autoconf` 9 | * `./configure` 10 | * `make -j` 11 | ''; 12 | _h_ = pkgs.writeShellScriptBin "h" '' 13 | ${pkgs.glow}/bin/glow ${h_content} 14 | ''; 15 | in pkgs.mkShell { 16 | inherit name; 17 | packages = with pkgs; [ 18 | autoconf 19 | pkgsCross.riscv64-embedded.stdenv.cc 20 | 21 | _h_ 22 | ]; 23 | shellHook = '' 24 | export RISCV_PREFIX=${pkgs.pkgsCross.riscv64-embedded.stdenv.cc}/bin/riscv64-none-elf- 25 | h 26 | ''; 27 | } 28 | -------------------------------------------------------------------------------- /scripts/shell/spike.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | with import {}; 3 | mkShell { 4 | packages = [ 5 | dtc 6 | pkgsCross.riscv64-embedded.stdenv.cc 7 | ]; 8 | name = "spike"; 9 | } 10 | -------------------------------------------------------------------------------- /scripts/shell/texlive.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | # --pure: start a pure reproducible shell 3 | { pkgs ? import {} 4 | }: 5 | pkgs.mkShell { 6 | name="dev-environment"; 7 | buildInputs = with pkgs; [ 8 | texlive.combined.scheme-full # HUGE SIZE! 9 | 10 | tmux 11 | ]; 12 | shellHook = '' 13 | # install texlive permenant 14 | nix-env -q "texlive.*" 15 | if [[ ''$? -ne 0 ]] 16 | then 17 | nix-env -f '' -iA texlive.combined.scheme-full 18 | fi 19 | 20 | tmux 21 | exit 22 | ''; 23 | } 24 | -------------------------------------------------------------------------------- /scripts/shell/ucasproposal.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | {pkgs ? import {}}: 3 | let 4 | name = "ucasproposal"; 5 | myTexlive = pkgs.texlive.combine { 6 | inherit (pkgs.texlive) 7 | scheme-basic 8 | 9 | xetex 10 | ctex 11 | checkcites 12 | 13 | # sty 14 | newtx 15 | xstring 16 | realscripts 17 | jknapltx 18 | mathalpha 19 | caption 20 | placeins 21 | enumitem 22 | listings 23 | algpseudocodex 24 | algorithms 25 | algorithmicx 26 | chemfig 27 | mhchem 28 | float 29 | 30 | # tex 31 | simplekv 32 | 33 | rsfs 34 | ; 35 | }; 36 | myPython = pkgs.python3.withPackages (p: with p; [ 37 | ipython 38 | matplotlib 39 | pandas 40 | numpy 41 | openpyxl 42 | ]); 43 | in 44 | pkgs.mkShell { 45 | inherit name; 46 | packages = with pkgs; [ 47 | myTexlive 48 | myPython 49 | librsvg 50 | ]; 51 | shellHook = '' 52 | # env 53 | export PYTHONPATH=${myPython}/${myPython.sitePackages} 54 | export debian_chroot=${name} 55 | ''; 56 | } 57 | -------------------------------------------------------------------------------- /scripts/shell/v8.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | { pkgsX86 ? import { 3 | localSystem.system="aarch64-linux"; 4 | crossSystem="aarch64-linux"; 5 | } }: 6 | pkgsX86.v8 7 | -------------------------------------------------------------------------------- /scripts/shell/venv.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | #2022.05.18 3 | # pip install is usable in venv 4 | # e.g. 5 | # $ nix-shell 6 | # $ pip install [--user] graphviz2drawio 7 | let 8 | pkgs = import {}; 9 | in 10 | pkgs.mkShell { 11 | propagatedBuildInputs = with pkgs.python3Packages; [ 12 | pip 13 | venvShellHook 14 | ipython 15 | ]; 16 | venvDir = "${builtins.getEnv "HOME"}/.venv"; 17 | } 18 | -------------------------------------------------------------------------------- /scripts/shell/wine6.nix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S nix-shell --keep miao 2 | let 3 | pkgs = import (builtins.fetchTarball { 4 | url = "https://github.com/NixOS/nixpkgs/archive/5e15d5da4abb74f0dd76967044735c70e94c5af1.tar.gz"; 5 | sha256 = "0mk86mlxamjxhywdfp5asylqb39z7w18dcy8ds6qvl8gqjrijmq9"; 6 | }) { 7 | system = "x86_64-linux"; 8 | }; 9 | in pkgs.mkShell { 10 | name = "wine6"; 11 | packages = with pkgs; [ 12 | wine64 13 | ]; 14 | } 15 | -------------------------------------------------------------------------------- /scripts/shell/xiangshan.nix: -------------------------------------------------------------------------------- 1 | let 2 | name = "xiangshan"; 3 | pkgs = import {}; 4 | in pkgs.mkShell { 5 | inherit name; 6 | 7 | buildInputs = let 8 | h_content = builtins.toFile "h_content" '' 9 | # ${pkgs.lib.toUpper "${name} usage tips"} 10 | ''; 11 | _h_ = pkgs.writeShellScriptBin "h" '' 12 | ${pkgs.glow}/bin/glow ${h_content} 13 | ''; 14 | mill_0_11_8 = (import (pkgs.fetchFromGitHub { 15 | owner = "NixOS"; 16 | repo = "nixpkgs"; 17 | rev = "05bbf675397d5366259409139039af8077d695ce"; 18 | sha256 = "1r26vjqmzgphfnby5lkfihz6i3y70hq84bpkwd43qjjvgxkcyki0"; 19 | }){}).mill; 20 | in [ 21 | _h_ 22 | mill_0_11_8 23 | ] ++ (with pkgs; [ 24 | espresso 25 | verilator 26 | 27 | # libs 28 | sqlite 29 | zlib 30 | zstd 31 | ]); 32 | 33 | shellHook = let 34 | circt_1_62_0 = (import (pkgs.fetchFromGitHub { 35 | owner = "NixOS"; 36 | repo = "nixpkgs"; 37 | rev = "771b079bb84ac2395f3a24a5663ac8d1495c98d3"; 38 | sha256 = "0l1l9ms78xd41xg768pkb6xym200zpf4zjbv4kbqbj3z7rzvhpb7"; 39 | }){}).circt; 40 | in '' 41 | h 42 | export CHISEL_FIRTOOL_PATH=${circt_1_62_0}/bin/ 43 | export NOOP_HOME=$(realpath .) 44 | ''; 45 | } 46 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | #MC # shell.nix 2 | #MC 3 | #MC 这个shell.nix用于创建编译我的[nix_config仓库](https://github.com/xieby1/nix_config)的 4 | #MC [GitHub Pages](https://xieby1.github.io/nix_config/)的环境。 5 | #MC GitHub Pages的构建主要由`markcode`和`mdbook`这两个工具支持。 6 | #MC 7 | #MC * [`markcode`](https://github.com/xieby1/markcode) 8 | #MC 是我为了方便在源文件里内嵌文档,写的一个小工具。 9 | #MC 它能将源文件中带有特殊标记的注释抽取出,成为markdown文件。 10 | #MC nix_config仓库的几乎所有文档都内嵌在.nix文件中, 11 | #MC 并都是通过`markcode`从.nix文件抽取出来。 12 | #MC * [`mdbook`](https://github.com/rust-lang/mdBook) 13 | #MC 是一个非常纯粹且好用的静态网页生成框架,负责将markdown转换成网页。 14 | #MC 因为第一次阅读[nix官方文档](https://nixos.org/manual/nix/stable/introduction.html)时就喜欢上了这个文档框架, 15 | #MC 所以我也采用的`mdbook`作为我的nix_config的文档框架。 16 | 17 | let 18 | name = "nix_config"; 19 | pkgs = import {}; 20 | markcode = pkgs.callPackage ( 21 | pkgs.fetchFromGitHub { 22 | owner = "xieby1"; 23 | repo = "markcode"; 24 | rev = "1c414aca28db7f2727f6da118f4e914743780ad0"; 25 | hash = "sha256-B5kmpAIyUihlBqk7oNAdqBmdfCajCmleKBTgLyy0NqU="; 26 | } 27 | ) {}; 28 | in pkgs.mkShell { 29 | inherit name; 30 | buildInputs = with pkgs; [ 31 | mdbook 32 | markcode 33 | ]; 34 | } 35 | -------------------------------------------------------------------------------- /sys/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xieby1/nix_config/eecf06aa8a787aaaaa4bdfca7984d45d768f812a/sys/index.md -------------------------------------------------------------------------------- /sys/modules/cachix.nix: -------------------------------------------------------------------------------- 1 | { config, lib, ...}: 2 | 3 | { 4 | imports = [../../modules/cachix.nix]; 5 | config = lib.mkIf ( 6 | (builtins.pathExists config.cachix_dhall) && 7 | (config.cachix_packages != []) 8 | ) { 9 | system.activationScripts = { 10 | cachix_push = config._cachix_push; 11 | }; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /sys/wayland.md: -------------------------------------------------------------------------------- 1 | # Currently, Not Wayland, But X11 2 | 3 | Here list wayland problems I have met. 4 | 5 | ## warpd not work 6 | 7 | ## fcitx input method not work 8 | 9 | ## waydroid 10 | 11 | waydroid tile not work 12 | 13 | ## tabbed not work 14 | 15 | 16 | ## gnome terminal headerbar cannot be hidden 17 | 18 | Both gnome extension unite and gtk-title-bar 19 | cannot hide gnome terminal(kitty and alacritty)'s headerbar. 20 | 21 | * https://github.com/velitasali/gtktitlebar/issues/25 22 | * https://github.com/velitasali/gtktitlebar/issues/14 23 | 24 | ## autokey and espanso not work in wayland 25 | 26 | Autokey only works in X11, 27 | while espanso officially disclaim it support wayland. 28 | But my wayland experience is, espanso does not work either. 29 | 30 | -------------------------------------------------------------------------------- /system.nix: -------------------------------------------------------------------------------- 1 | #MC # system.nix 2 | #MC 3 | #MC 本文件`system.nix`存放喆我的NixOS的配置。 4 | #MC NixOS的配置通过命令`sudo nixos-rebuid switch`生效。 5 | #MC 因为NixOS的配置入口是`/etc/nixos/configuration.nix`, 6 | #MC 所以需要在`/etc/nixos/configuration.nix`中import本文件,例如 7 | #MC 8 | #MC ```nix 9 | #MC # /etc/nixos/configuration.nix: 10 | #MC { config, pkgs, ... }: { 11 | #MC imports = [ 12 | #MC ./hardware-configuration.nix 13 | #MC # import my system.nix here! 14 | #MC /home/xieby1/.config/nixpkgs/system.nix 15 | #MC ]; 16 | #MC # other configs ... 17 | #MC } 18 | #MC ``` 19 | #MC 20 | #MC NixOS配置可以使用的参数可参考configuration.nix的manpage,即`man configuration.nix`。 21 | #MC 下面是我的NixOS的配置源码及注解: 22 | 23 | # add this file to /etc/nixos/configuration.nix: imports 24 | { config, pkgs, ... }: 25 | 26 | { 27 | #MC 让NixOS的nixpkgs使用和home-manager的nixpkgs采用相同的nixpkgs config 28 | nixpkgs.config = import ./config.nix; 29 | 30 | #MC 导入我的NixOS的CLI和GUI配置, 31 | #MC 详细内容见文档[./sys/cli.nix](./sys/cli.nix.md)和[./sys/gui.nix](./sys/gui.nix.md)。 32 | imports = [ 33 | ./sys/modules/cachix.nix 34 | ./sys/cli.nix 35 | ./sys/gui.nix 36 | ]; 37 | 38 | #MC Nix binary cache的地址。 39 | #MC 越靠前优先级越高。 40 | #MC 由于cache.nixos.org需要梯子, 41 | #MC 这里使用了清华Tuna提供的Nix binary cache镜像来加速。 42 | nix.settings.substituters = [ 43 | "https://cache.nixos.org/" 44 | "https://xieby1.cachix.org" 45 | ]; 46 | 47 | #MC 设置时区。 48 | time.timeZone = "Asia/Shanghai"; 49 | time.hardwareClockInLocalTime = true; 50 | 51 | #MC 设置Linux账户信息。 52 | users.mutableUsers = false; 53 | #MC 当然GitHub上当然不能明文存储密码,这里使用hash过的密码。 54 | #MC 可以使用命令行工具`mkpasswd`来生成hash过的密码。 55 | #MC 给`root`用户设置hash过的密码。 56 | users.users.root.hashedPassword = "$6$wRBpbr4zSTA/nh$XI/KUASw3mELIqyAxN1hUTWizz9ZBzPhP2u4HNDCA49h4KOWkZsyuiextyXkUti7jYsUHE9fTiRjGAoxBg0Gq/"; 57 | users.users.xieby1 = { 58 | isNormalUser = true; 59 | createHome = true; 60 | #MC 同上,给`xieby1`用户设置hash过的密码。 61 | hashedPassword = "$6$Y4KJxhdaJTT$RSolbCpaUKK2UW1cdnuH.8n1Ky9p0Lnx0MP36BxGX9Q2AeVMjCp.bZOsZ11w689je/785TFRQoVgicMiOfA9B."; 62 | #MC 给用户`xieby1`启用sudo。 63 | extraGroups = [ "wheel" ]; 64 | #MC ssh授权的公钥。这样设置后,我的所有的NixOS都相当于“自动授权”了。 65 | #MC 我的`/home/xieby1/Gist/`文件夹存放着一些不方便放入Git仓库的文件,比如二进制文件,或是隐私文件。 66 | #MC 该文件由[syncthing](https://github.com/syncthing/syncthing)进行多设备同步。 67 | #MC 简单的说,我的备份理念是“git备份配置,syncthing备份数据”。 68 | #MC “配置”即指这个[nix_config仓库](https://github.com/xieby1/nix_config),“数据”指`~/Gist/`、`~/Documents/`等文件夹。 69 | #MC 有了这些备份就能轻松还原/复现我的整个工作环境。 70 | #MC TODO:单独专门介绍我的备份理念。 71 | openssh.authorizedKeys.keyFiles = [] ++ ( 72 | if builtins.pathExists /home/xieby1/Gist/Vault/y50_70.pub 73 | then [/home/xieby1/Gist/Vault/y50_70.pub] 74 | else [] 75 | ) ++ ( 76 | if builtins.pathExists /home/xieby1/Gist/Vault/yoga14s.pub 77 | then [/home/xieby1/Gist/Vault/yoga14s.pub] 78 | else [] 79 | ); 80 | }; 81 | 82 | #MC 让TTY自动登录我的账户,这样就可以自动启动用户级(user)的systemd服务了。 83 | #MC 这样就可以在**非NixOS**中(比如Ubuntu服务器、WSL2、Debian树莓派等) 84 | #MC 自动拉起systemd**用户**服务(比如syncthing、clash、tailscale等)。 85 | services.getty.autologinUser = "xieby1"; 86 | #MC 有关systemd用户服务的配置,详细可见参考: 87 | #MC 88 | #MC * home-manager配置的manpage的services词条, 89 | #MC 比如`man home-configuration.nix`搜索`services.syncthing` 90 | #MC * 我的syncthing配置[./usr/cli.nix: syncthing](./usr/cli.nix.md#syncthing) 91 | #MC * 我的clash配置[./usr/cli/clash.nix](./usr/cli/clash.nix.md) 92 | #MC * 我的tailscale配置[./usr/cli/tailscale.nix](./usr/cli/tailscale.nix.md) 93 | } 94 | -------------------------------------------------------------------------------- /usr/cli-extra.nix: -------------------------------------------------------------------------------- 1 | #MC # cli-extra.nix: Extra CLI configs (added to minial cli.nix) 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | opt = import ../opt.nix; 5 | in { 6 | imports = [{ 7 | home.packages = [ 8 | pkgs.act 9 | (pkgs.writeShellScriptBin "act-podman" '' 10 | export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/podman/podman.sock 11 | CMD=( 12 | "${pkgs.act}/bin/act" 13 | "--bind" 14 | 15 | # use podman 16 | "--container-daemon-socket" "unix://$XDG_RUNTIME_DIR/podman/podman.sock" 17 | 18 | # use host proxy 19 | "--container-options" "--network=host" 20 | "--env" "HTTPS_PROXY='http://127.0.0.1:${toString opt.proxyPort}'" 21 | "--env" "HTTP_PROXY='http://127.0.0.1:${toString opt.proxyPort}'" 22 | "--env" "FTP_PROXY='http://127.0.0.1:${toString opt.proxyPort}'" 23 | "--env" "https_proxy='http://127.0.0.1:${toString opt.proxyPort}'" 24 | "--env" "http_proxy='http://127.0.0.1:${toString opt.proxyPort}'" 25 | "--env" "ftp_proxy='http://127.0.0.1:${toString opt.proxyPort}'" 26 | 27 | "$@" 28 | ) 29 | eval "''${CMD[@]}" 30 | '') 31 | ]; 32 | }]; 33 | 34 | home.packages = with pkgs; [ 35 | # tools 36 | imagemagick 37 | 38 | # programming 39 | ## c 40 | cling # c/cpp repl 41 | ## javascript 42 | nodePackages.typescript 43 | ### node 44 | nodejs 45 | ## java 46 | openjdk 47 | 48 | ### pdfcrop 49 | (texlive.combine {inherit (pkgs.texlive) scheme-minimal pdfcrop;}) 50 | # runXonY 51 | qemu 52 | ] ++ lib.optional (builtins.currentSystem == "x86_64-linux") quickemu; 53 | } 54 | -------------------------------------------------------------------------------- /usr/cli/clash.nix: -------------------------------------------------------------------------------- 1 | { config, pkgs, stdenv, lib, ... }: 2 | let 3 | opt = import ../../opt.nix; 4 | clashctl = pkgs.callPackage ./clashctl.nix {}; 5 | in { 6 | imports = [{ 7 | home.packages = [ 8 | pkgs.clash-meta 9 | ] ++ lib.optional (!opt.isNixOnDroid) clashctl; 10 | cachix_packages = lib.optional (!opt.isNixOnDroid) clashctl; 11 | 12 | systemd.user.services.clash = { 13 | Unit = { 14 | Description = "Auto start clash"; 15 | After = ["network.target"]; 16 | }; 17 | Install = { 18 | WantedBy = ["default.target"]; 19 | }; 20 | Service = { 21 | ExecStart = "${pkgs.clash-meta.outPath}/bin/clash-meta -d ${config.home.homeDirectory}/Gist/clash"; 22 | }; 23 | }; 24 | programs.bash.bashrcExtra = lib.mkBefore (lib.optionalString (!opt.isNixOnDroid) '' 25 | # proxy 26 | ## default 27 | HTTP_PROXY="http://127.0.0.1:${toString opt.proxyPort}/" 28 | ## microsoft wsl 29 | # if [[ $(uname -r) == *"microsoft"* ]]; then 30 | # hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }') 31 | # export HTTP_PROXY="http://$hostip:${toString opt.proxyPort}" 32 | # fi 33 | export HTTPS_PROXY="$HTTP_PROXY" 34 | export HTTP_PROXY="$HTTP_PROXY" 35 | export FTP_PROXY="$HTTP_PROXY" 36 | export http_proxy="$HTTP_PROXY" 37 | export https_proxy="$HTTP_PROXY" 38 | export ftp_proxy="$HTTP_PROXY" 39 | ''); 40 | }]; 41 | } 42 | -------------------------------------------------------------------------------- /usr/cli/clashctl.nix: -------------------------------------------------------------------------------- 1 | { lib 2 | , rustPlatform 3 | , fetchFromGitHub 4 | }: 5 | rustPlatform.buildRustPackage { 6 | name = "clashctl"; 7 | 8 | src = fetchFromGitHub { 9 | # owner = "https://github.com/George-Miao/clashctl"; 10 | owner = "George-Miao"; 11 | repo = "clashctl"; 12 | rev = "b09e1faf80f1a25fa855499d8b34d36491e5a081"; 13 | hash = "sha256-c7y64SsZEKdC8+umCY8+XBwxAHxn4YpqR48ASbHpkdM="; 14 | }; 15 | 16 | cargoHash = "sha256-Dt8AikjIaNTZ03vT/zV6ZTQ5QNoOjVxYYIc1AB/3De8="; 17 | 18 | doCheck = false; 19 | 20 | meta = with lib; { 21 | description = "CLI for interacting with clash"; 22 | homepage = "https://github.com/George-Miao/clashctl"; 23 | license = licenses.mit; 24 | maintainers = with maintainers; [ xieby1 ]; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /usr/cli/gdb.nix: -------------------------------------------------------------------------------- 1 | #MC # GDB configurations 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | pkgs.gdb 5 | ]; 6 | home.file.gdbinit = { 7 | source = pkgs.fetchFromGitHub { 8 | owner = "cyrus-and"; 9 | repo = "gdb-dashboard"; 10 | rev = "616ed5100d3588bb70e3b86737ac0609ce0635cc"; 11 | hash = "sha256-xoBkAFwkbaAsvgPwGwe1JxE1C8gPR6GP1iXeNKK5Z70="; 12 | } + /.gdbinit; 13 | target = ".gdbinit"; 14 | }; 15 | home.file.gdb_dashboard_init = { 16 | text = '' 17 | # gdb-dashboard init file 18 | 19 | # available layout modules 20 | # stack registers history assembly 21 | # breakpoints expressions memory 22 | # source threads variables 23 | dashboard -layout source 24 | 25 | # https://en.wikipedia.org/wiki/ANSI_escape_code 26 | #dashboard -style prompt 27 | ## fg bold blue 28 | dashboard -style prompt_not_running "\\[\\e[1;34m\\]$\\[\\e[0m\\]" 29 | ## fg bold green 30 | dashboard -style prompt_running "\\[\\e[1;32m\\]$\\[\\e[0m\\]" 31 | ''; 32 | target = ".gdbinit.d/init"; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /usr/cli/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xieby1/nix_config/eecf06aa8a787aaaaa4bdfca7984d45d768f812a/usr/cli/index.md -------------------------------------------------------------------------------- /usr/cli/kaleido.nix: -------------------------------------------------------------------------------- 1 | { buildPythonPackage 2 | , lib 3 | , nss 4 | , nspr 5 | , expat 6 | , fetchPypi 7 | }: 8 | let 9 | rpath = lib.makeLibraryPath [ 10 | nss 11 | nspr 12 | expat 13 | ]; 14 | in buildPythonPackage rec { 15 | pname = "kaleido"; 16 | version = "0.2.1"; 17 | format = "wheel"; 18 | src = fetchPypi { 19 | inherit pname version format; 20 | platform = "manylinux1_x86_64"; 21 | hash = "sha256-qiHPG/HHj4+lCp99ReEAPDh709b+CnZ8+780S5W9w6g="; 22 | }; 23 | doCheck = false; 24 | postFixup = '' 25 | for file in $(find $out -type f \( -perm /0111 -o -name \*.so\* \) ); do 26 | patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$file" || true 27 | patchelf --set-rpath ${rpath}:$out/lib/x86_64-linux-gnu $file || true 28 | done 29 | sed -i 's,#!/bin/bash,#!/usr/bin/env bash,' $out/lib/python3.11/site-packages/kaleido/executable/kaleido 30 | ''; 31 | } 32 | -------------------------------------------------------------------------------- /usr/cli/ld.md: -------------------------------------------------------------------------------- 1 | # binutils's ld and gcc's ld collsion 2 | 3 | Background: I want to install `gcc` and `objdump`, where `objdump` is contained in `binutils`. 4 | Home-manager tolds me `gcc`'s `ld` collides with `binutils`'s `ld`. 5 | As I explore into `gcc` and `binutils`, weird thing comes. 6 | 7 | Packages `binutils` and `gcc` both contain ld executable. 8 | `binutils` and `gcc` has the same priority 10. 9 | 10 | The WEIRD thing is, 11 | 12 | * `binutils` wants to have a lower priority than gcc-wrapper, 13 | so sets its priority to 10, 14 | see nixpkgs: `pkgs/development/tools/misc/binutils/default.nix` 15 | > Give binutils a lower priority than gcc-wrapper to prevent a 16 | > collision due to the ld/as wrappers/symlinks in the latter. 17 | * Both `gcc` wrapper and all-packages set gcc priority to 10, 18 | see nixpkgs: `pkgs/top-level/all-packages.nix` and 19 | `pkgs/build-support/cc-wrapper/default.nix` 20 | All-packages set priority by lowPrio function, 21 | which will set priority to 10. 22 | Cc-wrapper directly set priority to 10. 23 | 24 | As a result, `binutils` will definitely collide with `gcc`! 25 | 26 | My solution: assign `binutils` a lower priority, like this 27 | 28 | ```nix 29 | home.packages = with pkgs; [ 30 | (lib.setPrio # higher value, less prior 31 | (bintools-unwrapped.meta.priority + 1) 32 | bintools-unwrapped 33 | ) 34 | gdb 35 | ] 36 | ``` 37 | -------------------------------------------------------------------------------- /usr/cli/node.md: -------------------------------------------------------------------------------- 1 | # Nodejs packages (npm) in NixOS 2 | 3 | # NixOS中的Nodejs包(npm) 4 | 5 | 太长不看:手动暴露`buildNodePackage`,添加自定义的npm包。 6 | 7 | nixpkgs中的node包虽多但有限, 8 | 遇到需要的node包不存在时,是个麻烦事。 9 | 10 | 让我觉得十分诡异的是, 11 | nixpkgs中存在一个十分方便的添加node包的函数`nodeEnv.buildNodePackage`, 12 | 但是这个函数却不暴露出来给用户。 13 | 甚至,有些nixpkgs中的包为了使用这个函数, 14 | 复制粘贴该函数到自己的包中。 15 | 16 | 在这些奇怪的事情的基础上, 17 | 还衍生出来自动生成该`buildNodePackage`函数软件`node2nix`。 18 | 19 | 所以这真的是存在即合理嘛? 20 | 还是我学艺不精,不能理解设计者的意图? 21 | 22 | 一个简单的暴露`buildNodePackage`的方法, 23 | 直接导入`buildNodePackage`所在的文件。 24 | 为了跨平台可用, 25 | 路径的构建采用了一点使用了点点小把戏, 26 | 27 | ```nix 28 | + /pkgs/development/node-packages/node-env.nix 29 | ``` 30 | 31 | 以@types/node为例子,nodepkgs.nix: 32 | 33 | ```nix 34 | { ... }: 35 | let 36 | pkgs = import {}; 37 | nodeEnv = import ( + /pkgs/development/node-packages/node-env.nix) { 38 | inherit (pkgs) lib stdenv nodejs python2; 39 | inherit pkgs; 40 | inherit (pkgs) libtool runCommand writeTextFile writeShellScript; 41 | }; 42 | globalBuildInputs = []; 43 | in { 44 | "@types/node" = nodeEnv.buildNodePackage { 45 | name = "_at_types_slash_node"; 46 | packageName = "@types/node"; 47 | version = "18.7.15"; 48 | src = pkgs.fetchurl { 49 | url = "https://registry.npmjs.org/@types/node/-/node-18.7.15.tgz"; 50 | sha512 = "XnjpaI8Bgc3eBag2Aw4t2Uj/49lLBSStHWfqKvIuXD7FIrZyMLWp8KuAFHAqxMZYTF9l08N1ctUn9YNybZJVmQ=="; 51 | }; 52 | buildInputs = globalBuildInputs; 53 | meta = { 54 | description = "TypeScript definitions for Node.js"; 55 | homepage = "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node"; 56 | license = "MIT"; 57 | }; 58 | production = true; 59 | bypassCache = true; 60 | reconstructLock = true; 61 | }; 62 | } 63 | ``` 64 | 65 | 该nodepkgs.nix文件为用户自定义的node包, 66 | 可以像nixpkgs一样使用这个文件,例如导入 67 | 68 | ```nix 69 | myNodePkgs = import ./cli/nodepkgs.nix {} 70 | ``` 71 | 72 | 包的表达式为`myNodePkgs."@types/node"`。 73 | -------------------------------------------------------------------------------- /usr/cli/python.md: -------------------------------------------------------------------------------- 1 | # Python in Nix/NixOS 2 | 3 |
2023.05.03
4 | 5 | | Project | Maintained | Description | Purity | Compatibility | 6 | |----------------------|------------|-------------|--------|---------------| 7 | | venv | | | ❌ | 100%? | 8 | | mach-nix | ✅ | | | | 9 | | pypi2nix | ❌ | | | | 10 | | pip2nix | ✅ | | ✅ | | 11 | | `buildPythonPackage` | ✅ | | ✅ | | 12 | | [TODO] poetry | | | | | 13 | | [TODO] dream2nix | | | | | 14 | 15 | ## pip2nix 16 | 17 | Noted: Latest version of pip2nix only use python39. 18 | While nixpkgs 22.11 (current stable) is python310. 19 | I dont to install multiple versions of python3. 20 | 21 | If pip2nix can overcome the disadvantage of that 22 | generate a long list of python packages, 23 | and reuse python3Packages in nixpkgs, 24 | I would prefer to use pip2nix completely. 25 | 26 | Currently, I use `buildPythonPackage`. 27 | 28 | ## `buildPythonPackage` 29 | 30 | `pkgs.python3Packages.buildPythonPackage` 31 | 32 | ## venv 33 | 34 | Use virtualenv, `pip` is available, no need to write nix expressions to install packages. 35 | 36 | Code see https://xieby1.github.io/scripts/index.html#venvnix 37 | 38 | ## poetry 39 | 40 |
2022.05.15
41 | 42 | According to [What is the correct way to setup pip with nix to install any python package in an isolated nix environment](https://www.reddit.com/r/NixOS/comments/q71v0e/what_is_the_correct_way_to_setup_pip_with_nix_to/), 43 | I found two useful tools to install python packages in Nix/NixOS 44 | 45 | * [TODO] poetry 46 | * mach-nix 47 | 48 | ## mach-nix 49 | 50 | mach-nix github repo: 51 | [github.com/DavHau/mach-nix](https://github.com/DavHau/mach-nix) 52 | 53 | Here is [python_mach.nix]({{ site.repo_url }}/scripts/shell/python_mach.nix), 54 | an example which create a shell with a python package called expmcc. 55 | -------------------------------------------------------------------------------- /usr/cli/searxng.nix: -------------------------------------------------------------------------------- 1 | { config, pkgs, stdenv, lib, ... }: 2 | let 3 | opt = import ../../opt.nix; 4 | searxng_yml = builtins.toFile "searxng.yml" '' 5 | # https://docs.searxng.org/admin/settings/settings.html#settings-yml-location 6 | # The initial settings.yml we be load from these locations: 7 | # * the full path specified in the SEARXNG_SETTINGS_PATH environment variable. 8 | # * /etc/searxng/settings.yml 9 | 10 | # Default settings see /lib/python3.11/site-packages/searx/settings.yml 11 | use_default_settings: true 12 | 13 | search: 14 | autocomplete: "google" 15 | default_lang: "en" 16 | 17 | server: 18 | # Is overwritten by $SEARXNG_SECRET 19 | secret_key: ${if builtins.pathExists ~/Gist/Config/passwordFile 20 | then builtins.readFile ~/Gist/Config/passwordFile 21 | else "miao"} 22 | 23 | outgoing: 24 | proxies: 25 | all://: 26 | - http://127.0.0.1:${toString opt.proxyPort} 27 | 28 | engines: 29 | - name: bilibili 30 | engine: bilibili 31 | shortcut: bil 32 | disabled: false 33 | 34 | - name: bing 35 | engine: bing 36 | shortcut: bi 37 | disabled: false 38 | 39 | - name: qwant 40 | disabled: true 41 | ui: 42 | results_on_new_tab: true 43 | ''; 44 | in { 45 | systemd.user.services.searxng = { 46 | Unit = { 47 | Description = "Auto start searxng"; 48 | After = ["network.target"]; 49 | }; 50 | Install = { 51 | WantedBy = ["default.target"]; 52 | }; 53 | Service = { 54 | Environment = [ 55 | "SEARXNG_SETTINGS_PATH=${searxng_yml}" 56 | ]; 57 | ExecStart = "${pkgs.searxng}/bin/searx-run"; 58 | }; 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /usr/cli/tailscale.md: -------------------------------------------------------------------------------- 1 | # Tailscale/Headscale 2 | 3 | ## overview 4 | 5 | * client 6 | * tailscale 7 | * tailscaled 8 | * server 9 | * headscale 10 | 11 | ## Command 12 | 13 | TODO: exit node 14 | * https://www.reddit.com/r/Tailscale/comments/w9mtow/question_about_headscale_and_routing/ 15 | * https://icloudnative.io/posts/how-to-set-up-or-migrate-headscale/ 16 | 17 | TODO: headtail config 18 | TODO: nix config 19 | 20 | * rootless service 21 | * root service 22 | 23 | ```bash 24 | tailscale --socket /tmp/tailscaled.sock up --login-server http://82.157.197.100 25 | tailscale --socket /tmp/tailscaled.sock up --login-server http://82.157.197.100 --force-reauth 26 | ``` 27 | 28 | ### enable routes, exit node 29 | 30 | sudo tailscale --socket /tmp/tailscaled.sock up --login-server http://82.157.197.100 --advertise-routes=0.0.0.0/0,::/0 --accept-routes=true 31 | 32 | sudo docker exec headscale headscale nodes routes enable -i 13 -a -r 0.0.0.0/0 -r ::/0 33 | 34 | 35 | -------------------------------------------------------------------------------- /usr/cli/tailscale.nix: -------------------------------------------------------------------------------- 1 | { config, pkgs, stdenv, lib, ... }: 2 | let 3 | opt = import ../../opt.nix; 4 | tailscale-bash-completion = builtins.derivation { 5 | name = "tailscale-bash-completion"; 6 | system = builtins.currentSystem; 7 | src = builtins.fetchurl "https://gist.githubusercontent.com/cmtsij/f0d0be209224a7bdd67592695e1427de/raw/tailscale"; 8 | builder = pkgs.writeShellScript "tailscale-bash-completion-builder" '' 9 | source ${pkgs.stdenv}/setup 10 | dstdir=$out/share/bash-completion/completions 11 | dst=$dstdir/tailscale 12 | mkdir -p $dstdir 13 | cp $src $dst 14 | ''; 15 | }; 16 | tailscale-wrapper = {suffix, httpPort, socks5Port}: let 17 | tailscale-wrapped = pkgs.writeShellScriptBin "tailscale-${suffix}" '' 18 | tailscale --socket /tmp/tailscale-${suffix}.sock $@ 19 | ''; 20 | stateDir = "${config.home.homeDirectory}/.local/share/tailscale-${suffix}"; 21 | tailscaled-wrapped = pkgs.writeShellScriptBin "tailscaled-${suffix}" '' 22 | TS_LOGS_DIR="${stateDir}" \ 23 | ${pkgs.tailscale}/bin/tailscaled \ 24 | --tun userspace-networking \ 25 | --outbound-http-proxy-listen=localhost:${httpPort} \ 26 | --socks5-server=localhost:${socks5Port} \ 27 | --socket=/tmp/tailscale-${suffix}.sock \ 28 | --state=${stateDir}/tailscaled.state \ 29 | --statedir=${stateDir} \ 30 | $@ 31 | ''; 32 | tailscale-wrapped-bash-completion = builtins.derivation { 33 | name = "tailscale-${suffix}-bash-completion"; 34 | system = builtins.currentSystem; 35 | builder = pkgs.writeShellScript "tailscale-${suffix}-bash-completion-builder" '' 36 | source ${pkgs.stdenv}/setup 37 | reldir=share/bash-completion/completions 38 | dstdir=$out/$reldir 39 | dst=$dstdir/tailscale-${suffix} 40 | mkdir -p $dstdir 41 | touch $dst 42 | echo ". ${tailscale-bash-completion}/$reldir/tailscale" >> $dst 43 | echo "complete -F _tailscale tailscale-${suffix}" >> $dst 44 | ''; 45 | }; 46 | in { 47 | home.packages = [ 48 | tailscale-wrapped 49 | tailscaled-wrapped 50 | tailscale-wrapped-bash-completion 51 | ]; 52 | systemd.user.services."tailscaled-${suffix}" = { 53 | Unit = { 54 | Description = "Auto start tailscaled-${suffix} userspace network"; 55 | After = ["clash.service"]; 56 | }; 57 | Install = { 58 | WantedBy = ["default.target"]; 59 | }; 60 | Service = { 61 | Environment = [ 62 | "HTTPS_PROXY=http://127.0.0.1:${toString opt.proxyPort}" 63 | "HTTP_PROXY=http://127.0.0.1:${toString opt.proxyPort}" 64 | "https_proxy=http://127.0.0.1:${toString opt.proxyPort}" 65 | "http_proxy=http://127.0.0.1:${toString opt.proxyPort}" 66 | ]; 67 | ExecStart = "${tailscaled-wrapped}/bin/tailscaled-${suffix}"; 68 | }; 69 | }; 70 | programs.bash.bashrcExtra = lib.optionalString opt.isNixOnDroid '' 71 | # start tailscale-${suffix} 72 | if [[ -z "$(pidof tailscaled-${suffix})" ]]; then 73 | tmux new -d -s tailscaled-${suffix} tailscaled-${suffix} 74 | fi 75 | ''; 76 | }; 77 | in { 78 | imports = [{ 79 | home.packages = [pkgs.tailscale tailscale-bash-completion]; 80 | } 81 | # (tailscale-wrapper {suffix="headscale"; httpPort="1055"; socks5Port="1065";}) 82 | (tailscale-wrapper {suffix="official"; httpPort="1056"; socks5Port="1066";}) 83 | ]; 84 | } 85 | -------------------------------------------------------------------------------- /usr/cli/tmux.nix: -------------------------------------------------------------------------------- 1 | #MC # tmux 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | opt = import ../../opt.nix; 5 | in { 6 | home.packages = [pkgs.tmux]; 7 | #MC ## bash config for tmux 8 | #MC 9 | #MC Auto start tmux in non-GUI device. 10 | #MC mkAfter ensure the tmux config is appended to the tail of .bashrc. 11 | programs.bash.bashrcExtra = lib.mkAfter (lib.optionalString (!opt.isGui) '' 12 | # Auto start tmux 13 | # see: https://unix.stackexchange.com/questions/43601/how-can-i-set-my-default-shell-to-start-up-tmux 14 | # ~~1. tmux exists on the system~~, nix ensure that tmux does exist 15 | # 2. we're in an interactive shell, and 16 | # 3. tmux doesn't try to run within itself 17 | if [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then 18 | exec tmux 19 | fi 20 | ''); 21 | #MC ## tmux config file 22 | home.file.tmux = { 23 | text = '' 24 | # display status at top 25 | set -g status-position top 26 | set -g status-right "" 27 | 28 | # status bar 29 | ## display title on terminal 30 | set -g set-titles on 31 | set -g window-status-format "#F#I #W #{=/-20/…:pane_title}" 32 | set -g window-status-current-format "🐶#F#I #W #{=/-20/…:pane_title}" 33 | ## hide status bar when only one window 34 | ### refer to 35 | ### https://www.reddit.com/r/tmux/comments/6lwb07/is_it_possible_to_hide_the_status_bar_in_only_a/ 36 | ### It not good, since its global! 37 | # if -F "#{==:#{session_windows},1}" "set -g status off" "set -g status on" 38 | # set-hook -g window-linked 'if -F "#{==:#{session_windows},1}" "set -g status off" "set -g status on"' 39 | # set-hook -g window-unlinked 'if -F "#{==:#{session_windows},1}" "set -g status off" "set -g status on"' 40 | ## color 41 | ### colour256的前10个和终端(gnome-terminal tango)的配色一致 42 | set -g status-style "bg=white fg=black" 43 | set -g window-status-last-style "bg=white fg=green bold" 44 | set -g window-status-current-style "bg=black fg=green bold" 45 | # set -g window-status-separator "|" 46 | 47 | # enable mouse scroll 48 | set -g mouse on 49 | 50 | # window index start from 1 51 | set -g base-index 1 52 | setw -g pane-base-index 1 53 | 54 | # auto re-number 55 | set -g renumber-windows on 56 | 57 | # Set new panes to open in current directory 58 | bind c new-window -c "#{pane_current_path}" 59 | bind '"' split-window -c "#{pane_current_path}" 60 | bind % split-window -h -c "#{pane_current_path}" 61 | 62 | # alt-num select window 63 | bind-key -n M-1 select-window -t 1 64 | bind-key -n M-2 select-window -t 2 65 | bind-key -n M-3 select-window -t 3 66 | bind-key -n M-4 select-window -t 4 67 | bind-key -n M-5 select-window -t 5 68 | bind-key -n M-6 select-window -t 6 69 | bind-key -n M-7 select-window -t 7 70 | bind-key -n M-8 select-window -t 8 71 | bind-key -n M-9 select-window -t 9 72 | # ctrl-t new window 73 | bind-key -n C-t new-window -c "#{pane_current_path}" 74 | 75 | # vi key bindings 76 | set -g mode-keys vi 77 | set -g status-keys vi 78 | 79 | # Home, End key not work in nix-on-droid 80 | # https://stackoverflow.com/questions/18600188/home-end-keys-do-not-work-in-tmux 81 | bind-key -n Home send Escape "OH" 82 | bind-key -n End send Escape "OF" 83 | 84 | set -g allow-passthrough on 85 | ''; 86 | target = ".tmux.conf"; 87 | }; 88 | } 89 | -------------------------------------------------------------------------------- /usr/cli/vim/README.md: -------------------------------------------------------------------------------- 1 | # 📑neovim 2 | 3 | xieby1's neovim config! 4 | 5 | See [default.nix](./default.nix.md) 6 | -------------------------------------------------------------------------------- /usr/cli/vim/close-windows.nix: -------------------------------------------------------------------------------- 1 | #MC # key bindings of closing windows 2 | { ... }: { 3 | programs.neovim = { 4 | extraConfig = '' 5 | function CloseWindowsAbove() 6 | let l:curwin = winnr() 7 | while winnr('1k') != l:curwin 8 | wincmd k 9 | close 10 | let l:curwin -= 1 11 | endwhile 12 | endfunction 13 | function CloseWindowsBelow() 14 | let l:curwin = winnr() 15 | wincmd j 16 | while winnr() != l:curwin 17 | close 18 | endwhile 19 | endfunction 20 | 21 | command CloseWindowsAbove call CloseWindowsAbove() 22 | command CloseWindowsBelow call CloseWindowsBelow() 23 | nnoremap Z :call CloseWindowsAbove() 24 | nnoremap Z :call CloseWindowsAbove() 25 | nnoremap Z :call CloseWindowsBelow() 26 | nnoremap Z :call CloseWindowsBelow() 27 | 28 | " quit all 29 | nnoremap ZA :qa! 30 | ''; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /usr/cli/vim/color-scheme.nix: -------------------------------------------------------------------------------- 1 | #MC # 🎨My nvim color scheme 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | my-color-scheme = { 5 | plugin = pkgs.vimPlugins.sonokai; 6 | config = '' 7 | nnoremap c :set termguicolors! 8 | set termguicolors 9 | 10 | let g:sonokai_transparent_background = 1 11 | 12 | let g:sonokai_colors_override = { 13 | \ 'black': ['#111215', '237'], 14 | \ 'bg0': ['#22232a', '235'], 15 | \ 'bg1': ['#33353f', '236'], 16 | \ 'bg2': ['#444754', '236'], 17 | \ 'bg3': ['#555869', '237'], 18 | \ 'bg4': ['#666a7e', '237'], 19 | \ 'grey': ['#a5a5a6', '246'], 20 | \ 'grey_dim': ['#787879', '240'], 21 | \} 22 | 23 | " custom sonokai, 24 | " see section "How to use custom colors" of `:h sonokai.vim` 25 | function! s:sonokai_custom() abort 26 | let l:palette = sonokai#get_palette('default', {}) 27 | call sonokai#highlight('StatusLine', l:palette.black, l:palette.fg, 'bold') 28 | call sonokai#highlight('StatusLineNC', l:palette.black, l:palette.grey, 'bold') 29 | endfunction 30 | augroup SonokaiCustom 31 | autocmd! 32 | autocmd ColorScheme sonokai call s:sonokai_custom() 33 | augroup END 34 | 35 | colorscheme sonokai 36 | ''; 37 | }; 38 | in { 39 | programs.neovim = { 40 | plugins = [ 41 | my-color-scheme 42 | ]; 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /usr/cli/vim/conform-nvim.nix: -------------------------------------------------------------------------------- 1 | #MC # conform-nvim: formatter 2 | { pkgs, ... }: { 3 | programs.neovim = { 4 | plugins = [{ 5 | plugin = pkgs.vimPlugins.conform-nvim; 6 | type = "lua"; 7 | config = '' 8 | require("conform").setup({ 9 | formatters_by_ft = { 10 | nix = { "nixfmt" }, 11 | c = { "clang_format" }, 12 | cpp = { "clang_format" }, 13 | json = { "js_beautify" }, 14 | javascript = { "js_beautify" }, 15 | }, 16 | }) 17 | 18 | -- refer to https://github.com/stevearc/conform.nvim/blob/master/doc/recipes.md#format-command 19 | vim.api.nvim_create_user_command("TrimWhitespace", function(args) 20 | local range = nil 21 | if args.count ~= -1 then 22 | local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1] 23 | range = { 24 | start = { args.line1, 0 }, 25 | ["end"] = { args.line2, end_line:len() }, 26 | } 27 | end 28 | require("conform").format({ formatters = {"trim_whitespace"}, range = range }) 29 | end, { range = true }) 30 | vim.keymap.set({'n','v'}, 'f', ':TrimWhitespace') 31 | 32 | vim.api.nvim_create_user_command("Format", function(args) 33 | local range = nil 34 | if args.count ~= -1 then 35 | local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1] 36 | range = { 37 | start = { args.line1, 0 }, 38 | ["end"] = { args.line2, end_line:len() }, 39 | } 40 | end 41 | require("conform").format({ async = true, lsp_fallback = true, range = range }) 42 | end, { range = true }) 43 | vim.keymap.set({'n','v'}, 'F', ':Format') 44 | ''; 45 | }]; 46 | extraPackages = with pkgs; [ 47 | nixfmt-rfc-style 48 | clang-tools 49 | nodePackages.js-beautify 50 | ]; 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /usr/cli/vim/deprecated.DrawIt.nix: -------------------------------------------------------------------------------- 1 | #MC # DrawIt: ascii art drawing 2 | # Currently, DrawIt runs very slowly, and it has not been maintained for a long time, so deprecate it. 3 | { config, pkgs, stdenv, lib, ... }: 4 | let 5 | DrawIt = pkgs.vimUtils.buildVimPlugin { 6 | name = "DrawIt"; 7 | src = pkgs.fetchFromGitHub { 8 | owner = "vim-scripts"; 9 | repo = "DrawIt"; 10 | rev = "master"; # I believe it wont update ^_*, so its safe 11 | sha256 = "0yn985pj8dn0bzalwfc8ssx62m01307ic1ypymil311m4gzlfy60"; 12 | }; 13 | # disable f binding 14 | postPatch = '' 15 | sed -i '/f/d' autoload/DrawIt.vim 16 | ''; 17 | }; 18 | in { 19 | programs.neovim = { 20 | plugins = [ 21 | DrawIt 22 | ]; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /usr/cli/vim/deprecated.image-nvim.nix: -------------------------------------------------------------------------------- 1 | # 问题 2 | # * svg会变成png,非常不清晰,也没人提问题 3 | # * (幻灯片里)图片多了非常卡,会显示不出来 4 | # * 排版有问题,总有错位,issues说解决了,我这里用的最新版,仍然部分有问题 5 | # 6 | # 结论,不如用MarkdownPreview 7 | { pkgs, ... }: { 8 | programs.neovim = { 9 | plugins = [{ 10 | plugin = pkgs.vimUtils.buildVimPlugin { 11 | name = "image-nvim"; 12 | src = pkgs.fetchFromGitHub { 13 | owner = "3rd"; 14 | repo = "image.nvim"; 15 | rev = "4c51d6202628b3b51e368152c053c3fb5c5f76f2"; 16 | hash = "sha256-r3s19L0NcUfNTR1SQ98z8fEvhTxGRr4/jlicmbzmQZs="; 17 | }; 18 | }; 19 | type = "lua"; 20 | config = '' 21 | require("image").setup({ 22 | integrations = { 23 | markdown = { 24 | enabled = true, 25 | only_render_image_at_cursor = true, 26 | }, 27 | html = { 28 | enabled = true, 29 | only_render_image_at_cursor = true, 30 | -- [Render HTML images in markdown files #234](https://github.com/3rd/image.nvim/issues/234) 31 | -- need html treesitter 32 | filetypes = { "html", "xhtml", "htm", "markdown" }, 33 | }, 34 | css = { 35 | enabled = true, 36 | only_render_image_at_cursor = true, 37 | }, 38 | }, 39 | }) 40 | 41 | -- add :ImageToggle 42 | -- inspired by [How to toggle markdown image previews with a command? #181](https://github.com/3rd/image.nvim/issues/181) 43 | vim.api.nvim_create_user_command('ImageToggle', function() 44 | local image = require("image") 45 | if image.is_enabled() then 46 | image.disable() 47 | else 48 | image.enable() 49 | end 50 | end, {}) 51 | ''; 52 | }]; 53 | extraPackages = [ pkgs.imagemagick ]; 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /usr/cli/vim/fold.nix: -------------------------------------------------------------------------------- 1 | #MC # fold 2 | { ... }: { 3 | programs.neovim = { 4 | extraConfig = '' 5 | "" Fold 6 | """ fold text to be the first and last line 7 | """ refer to sbernheim4's reply at 8 | """ https://github.com/nvim-treesitter/nvim-treesitter/pull/390 9 | function! GetSpaces(foldLevel) 10 | if &expandtab == 1 11 | " Indenting with spaces 12 | let str = repeat(" ", a:foldLevel / (&shiftwidth + 1) - 1) 13 | return str 14 | elseif &expandtab == 0 15 | " Indenting with tabs 16 | return repeat(" ", indent(v:foldstart) - (indent(v:foldstart) / &shiftwidth)) 17 | endif 18 | endfunction 19 | function! MyFoldText() 20 | let startLineText = getline(v:foldstart) 21 | let endLineText = trim(getline(v:foldend)) 22 | let indentation = GetSpaces(foldlevel(".")) 23 | let spaces = repeat(" ", 200) 24 | let str = indentation . startLineText . " …… " . endLineText . spaces 25 | return str 26 | endfunction 27 | "" toggle foldmethod between manual and indent 28 | set foldmethod=indent 29 | :function ToggleFoldmethod() 30 | : if (&foldmethod == "manual") 31 | : set foldmethod=indent 32 | : else 33 | : set foldmethod=manual 34 | : endif 35 | :endfunction 36 | nnoremap z :call ToggleFoldmethod():echo &foldmethod 37 | "" Custom display for text when folding 38 | set foldtext=MyFoldText() 39 | """ Set the foldlevel to a high setting, 40 | """ files are always loaded with opened folds. 41 | set foldlevel=20 42 | ''; 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /usr/cli/vim/git-wip.nix: -------------------------------------------------------------------------------- 1 | #MC # git-wip: auto wip branch 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | git-wip = pkgs.vimUtils.buildVimPlugin { 5 | name = "git-wip"; 6 | src = pkgs.fetchFromGitHub { 7 | owner = "bartman"; 8 | repo = "git-wip"; 9 | rev = "1c095e93539261370ae811ebf47b8d3fe9166869"; 10 | hash = "sha256-rjvg6sTOuUM3ltD3DuJqgBEDImLrsfdnK52qxCbu8vo="; 11 | }; 12 | preInstall = "cd vim"; 13 | }; 14 | in { 15 | programs.neovim = { 16 | plugins = [ 17 | git-wip 18 | ]; 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /usr/cli/vim/gitsigns-nvim.nix: -------------------------------------------------------------------------------- 1 | #MC # gitsigns-nvim: git support 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | my-gitsigns-nvim = { 5 | plugin = pkgs.vimPlugins.gitsigns-nvim; 6 | type = "lua"; 7 | config = '' 8 | require('gitsigns').setup { 9 | signs_staged_enable = false, 10 | signcolumn = false, 11 | numhl = true, 12 | linehl = true, 13 | 14 | current_line_blame = true, 15 | current_line_blame_formatter = '🖂 🖃 🖆 ', 16 | 17 | -- keymaps 18 | on_attach = function(bufnr) 19 | local gs = package.loaded.gitsigns 20 | 21 | local function map(mode, l, r, opts) 22 | opts = opts or {} 23 | opts.buffer = bufnr 24 | vim.keymap.set(mode, l, r, opts) 25 | end 26 | 27 | -- Navigation 28 | map('n', ']c', function() 29 | if vim.wo.diff then return ']c' end 30 | vim.schedule(function() gs.next_hunk() end) 31 | return '' 32 | end, {expr=true}) 33 | 34 | map('n', '[c', function() 35 | if vim.wo.diff then return '[c' end 36 | vim.schedule(function() gs.prev_hunk() end) 37 | return '' 38 | end, {expr=true}) 39 | 40 | -- Actions 41 | map({'n', 'v'}, 'hs', ':Gitsigns stage_hunk') 42 | map({'n', 'v'}, 'hr', ':Gitsigns reset_hunk') 43 | map('n', 'hS', gs.stage_buffer) 44 | map('n', 'hu', gs.undo_stage_hunk) 45 | map('n', 'hR', gs.reset_buffer) 46 | map('n', 'hp', gs.preview_hunk) 47 | map('n', 'hb', function() gs.blame_line{full=true} end) 48 | map('n', 'tb', gs.toggle_current_line_blame) 49 | map('n', 'hd', gs.diffthis) 50 | map('n', 'hD', function() gs.diffthis('~') end) 51 | map('n', 'td', gs.toggle_deleted) 52 | 53 | -- Text object 54 | map({'o', 'x'}, 'ih', ':Gitsigns select_hunk') 55 | end 56 | } 57 | ''; 58 | }; 59 | in { 60 | programs.neovim = { 61 | plugins = [ 62 | my-gitsigns-nvim 63 | ]; 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /usr/cli/vim/hbac-nvim.nix: -------------------------------------------------------------------------------- 1 | #MC # hbac-nvim: auto close buffer 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | my-hbac = { 5 | plugin = pkgs.vimUtils.buildVimPlugin { 6 | name = "hbac.nvim"; 7 | src = pkgs.fetchFromGitHub { 8 | owner = "axkirillov"; 9 | repo = "hbac.nvim"; 10 | rev = "e2e8333aa56ef43a577ac3a2a2e87bdf2f0d4cbb"; 11 | hash = "sha256-7+e+p+0zMHPJjpnKNkL7QQHZJGQ1DFZ6fsofcsVNXaY="; 12 | }; 13 | doCheck = false; 14 | }; 15 | type = "lua"; 16 | config = '' 17 | require("hbac").setup({ 18 | autoclose = true, -- set autoclose to false if you want to close manually 19 | threshold = 10, -- hbac will start closing unedited buffers once that number is reached 20 | close_command = function(bufnr) 21 | vim.api.nvim_buf_delete(bufnr, {}) 22 | end, 23 | close_buffers_with_windows = false, -- hbac will close buffers with associated windows if this option is `true` 24 | telescope = { 25 | -- See #telescope-configuration below 26 | }, 27 | }) 28 | ''; 29 | }; 30 | in { 31 | programs.neovim = { 32 | plugins = [ 33 | my-hbac 34 | ]; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /usr/cli/vim/leap-nvim.nix: -------------------------------------------------------------------------------- 1 | { config, pkgs, stdenv, lib, ... }: 2 | let 3 | my-leap-nvim = { 4 | plugin = pkgs.vimPlugins.leap-nvim; 5 | type = "lua"; 6 | config = '' 7 | require('leap').set_default_mappings() 8 | ''; 9 | }; 10 | in { 11 | programs.neovim = { 12 | plugins = [ 13 | my-leap-nvim 14 | ]; 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /usr/cli/vim/markdown-preview-nvim.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: { 2 | programs.neovim = { 3 | plugins = [{ 4 | plugin = pkgs.vimPlugins.markdown-preview-nvim.overrideAttrs (old: { 5 | # set port to 7700~7799 6 | postPatch = '' 7 | sed -i 's/port = port ||.*/port = port || (7700 + Number(`''${Date.now()}`.slice(-2)))/' app/server.js 8 | ''; 9 | }); 10 | config = '' 11 | " allow LAN 12 | let g:mkdp_open_to_the_world = 1 13 | let g:mkdp_theme = 'light' 14 | ''; 15 | }]; 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /usr/cli/vim/mini-nvim.nix: -------------------------------------------------------------------------------- 1 | #MC # mini-nvim: a nvim distro 2 | #MC 3 | #MC mini-nvim is wonderful nvim plugin! 4 | #MC I found it due to below link: 5 | #MC indent-blankline.nvim is too complex. 6 | #MC However, it does not support basic functionality like highlight current indentation 7 | #MC See: https://github.com/lukas-reineke/indent-blankline.nvim/issues/649 8 | { config, pkgs, stdenv, lib, ... }: 9 | let 10 | my-mini-nvim = { 11 | plugin = pkgs.vimPlugins.mini-nvim; 12 | type = "lua"; 13 | config = '' 14 | require('mini.indentscope').setup{ 15 | options = { 16 | try_as_border = true, 17 | }, 18 | } 19 | 20 | -- mini.animate looks promising, and can totally replace vim-smoothie 21 | -- However, bugs seem exist: 22 | -- * touchpad scroll become slow 23 | -- * background color blinks when create window 24 | -- * background color broken after q::q 25 | -- require('mini.animate').setup() 26 | 27 | require('mini.icons').setup() 28 | ''; 29 | }; 30 | in { 31 | programs.neovim = { 32 | plugins = [ 33 | my-mini-nvim 34 | ]; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-config-local.nix: -------------------------------------------------------------------------------- 1 | #MC # nvim-config-local: secure load local vim config 2 | { pkgs, ... }: 3 | let 4 | my-nvim-config-local = { 5 | plugin = pkgs.vimPlugins.nvim-config-local; 6 | type = "lua"; 7 | config = '' 8 | require('config-local').setup { 9 | config_files = { ".nvim.lua", ".nvimrc", ".exrc", ".vimrc" }, 10 | lookup_parents = true, 11 | silent = true, 12 | } 13 | ''; 14 | }; 15 | in { 16 | programs.neovim = { 17 | plugins = [ 18 | my-nvim-config-local 19 | ]; 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-lspconfig/bash.nix: -------------------------------------------------------------------------------- 1 | #MC # bashls: bash language server 2 | { pkgs, ... }: { 3 | programs.neovim = { 4 | extraLuaConfig = '' 5 | require('lspconfig').bashls.setup{} 6 | require('lspconfig')['bashls'].setup { 7 | capabilities = require("cmp_nvim_lsp").default_capabilities(), 8 | } 9 | ''; 10 | extraPackages = with pkgs; [ 11 | nodePackages.bash-language-server 12 | ]; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-lspconfig/c.nix: -------------------------------------------------------------------------------- 1 | #MC # lspconfig for C/C++ language 2 | { pkgs, ...}: { 3 | programs.neovim = { 4 | #MC ## C/C++ 5 | #MC 6 | #MC ### Why use clangd instead of ccls? 7 | #MC 8 | #MC I encountered the problem below, 9 | #MC when view https://github.com/xieby1/openc910 smart_run/logical/tb/sim_main1.cpp 10 | #MC ``` 11 | #MC LSP[ccls]: Error NO_RESULT_CALLBACK_FOUND: { 12 | #MC error = { 13 | #MC code = -32603, 14 | #MC message = "failed to index /home/xieby1/Codes/openc910/smart_run/work/fputc.c" 15 | #MC }, 16 | #MC id = 1, 17 | #MC jsonrpc = "2.0" 18 | #MC } 19 | #MC ``` 20 | #MC 21 | #MC After some searching, I found 22 | #MC 23 | #MC [GitHub: neovim: issue: lsp: NO_RESULT_CALLBACK_FOUND with ccls, rust-analyzer #15844](https://github.com/neovim/neovim/issues/15844) 24 | #MC 25 | #MC sapphire-arches found: 26 | #MC 27 | #MC > Something is causing the r-a LSP to send two replies with the same ID, see the attached log: 28 | #MC > lsp_debug.log 29 | #MC > 30 | #MC > It would be nice for the neovim LSP to handle this more gracefully (not filling my screen with garbage and taking focus), but I do think the bug is in R-A here? The problem seems to be related to editor.action.triggerParameterHints? 31 | #MC 32 | #MC [GitHub: ccls: issue: I'm very confused about this question, it's about ccls or neovim built in LSP? #836](https://github.com/MaskRay/ccls/issues/836) 33 | #MC 34 | #MC No one try to fix the two-replies problem in ccls. 35 | #MC However, nimaipatel recommanded [clangd_extensions](https://github.com/p00f/clangd_extensions.nvim). 36 | extraLuaConfig = '' 37 | require('lspconfig').clangd.setup{ 38 | filetypes = { "c", "cc", "cpp", "c++", "objc", "objcpp", "cuda", "proto" } 39 | } 40 | require("clangd_extensions.inlay_hints").setup_autocmd() 41 | require("clangd_extensions.inlay_hints").set_inlay_hints() 42 | require('lspconfig')['clangd'].setup { 43 | capabilities = require("cmp_nvim_lsp").default_capabilities(), 44 | } 45 | ''; 46 | plugins = [ 47 | pkgs.vimPlugins.clangd_extensions-nvim 48 | ]; 49 | extraPackages = with pkgs; [ 50 | clang-tools 51 | ]; 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-lspconfig/default.nix: -------------------------------------------------------------------------------- 1 | #MC # nvim-lspconfig 2 | { pkgs, ... }: { 3 | imports = [ 4 | ./bash.nix 5 | ./c.nix 6 | ./html.nix 7 | ./lua.nix 8 | ./nix.nix 9 | ./python.nix 10 | ./typos.nix 11 | ./xml.nix 12 | ]; 13 | programs.neovim = { 14 | plugins = [{ 15 | plugin = pkgs.vimPlugins.nvim-lspconfig; 16 | type = "lua"; 17 | #MC ## Global mappings. 18 | config = '' 19 | -- See `:help vim.diagnostic.*` for documentation on any of the below functions 20 | vim.keymap.set('n', 'e', vim.diagnostic.open_float) 21 | vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) 22 | vim.keymap.set('n', ']d', vim.diagnostic.goto_next) 23 | vim.keymap.set('n', 'q', vim.diagnostic.setloclist) 24 | 25 | -- Use LspAttach autocommand to only map the following keys 26 | -- after the language server attaches to the current buffer 27 | vim.api.nvim_create_autocmd('LspAttach', { 28 | group = vim.api.nvim_create_augroup('UserLspConfig', {}), 29 | callback = function(ev) 30 | -- Enable completion triggered by 31 | vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' 32 | 33 | -- Buffer local mappings. 34 | -- See `:help vim.lsp.*` for documentation on any of the below functions 35 | local opts = { buffer = ev.buf } 36 | vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) 37 | vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) 38 | vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) 39 | vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) 40 | vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) 41 | vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) 42 | vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) 43 | vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) 44 | vim.keymap.set('n', 'wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, opts) 45 | vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) 46 | vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) 47 | vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) 48 | vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, opts) 49 | end, 50 | }) 51 | ''; 52 | }]; 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-lspconfig/deprecated.ltex.nix: -------------------------------------------------------------------------------- 1 | #MC # lspconfig for plain text 2 | { pkgs, ... }: { 3 | programs.neovim = { 4 | extraLuaConfig = '' 5 | local paths = { 6 | -- vim.fn.stdpath("config") .. "/spell/ltex.dictionary.en-US.txt", 7 | vim.fn.expand("%:p:h") .. "/.ltexdict", 8 | } 9 | local words = {} 10 | for _, path in ipairs(paths) do 11 | local f = io.open(path) 12 | if f then 13 | for word in f:lines() do 14 | table.insert(words, word) 15 | end 16 | f:close() 17 | end 18 | end 19 | 20 | require('lspconfig').ltex.setup{ 21 | settings = { 22 | ltex = { 23 | -- Supported languages: 24 | -- https://valentjn.github.io/ltex/settings.html#ltexlanguage 25 | -- https://valentjn.github.io/ltex/supported-languages.html#code-languages 26 | language = "en-US", -- "zh-CN" | "en-US", 27 | filetypes = { "bib", "gitcommit", "markdown", "org", "plaintex", "rst", "rnoweb", "tex", "pandoc" }, 28 | dictionary = { 29 | ['en-GB'] = words, 30 | }, 31 | }, 32 | }, 33 | } 34 | require('lspconfig')['ltex'].setup { 35 | capabilities = require("cmp_nvim_lsp").default_capabilities(), 36 | } 37 | ''; 38 | extraPackages = with pkgs; [ 39 | ltex-ls 40 | ]; 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-lspconfig/html.nix: -------------------------------------------------------------------------------- 1 | #MC # lspconfig for html 2 | { pkgs, ... }: { 3 | programs.neovim = { 4 | extraLuaConfig = '' 5 | require('lspconfig').html.setup{} 6 | require('lspconfig')['html'].setup { 7 | capabilities = require("cmp_nvim_lsp").default_capabilities(), 8 | } 9 | ''; 10 | extraPackages = with pkgs; [ 11 | vscode-langservers-extracted # html 12 | ]; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-lspconfig/lua.nix: -------------------------------------------------------------------------------- 1 | #MC # lspconfig for plain text 2 | { pkgs, ... }: { 3 | programs.neovim = { 4 | extraLuaConfig = '' 5 | require('lspconfig').lua_ls.setup{} 6 | require('lspconfig')['lua_ls'].setup { 7 | capabilities = require("cmp_nvim_lsp").default_capabilities(), 8 | } 9 | ''; 10 | extraPackages = with pkgs; [ 11 | lua-language-server 12 | ]; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-lspconfig/nix.nix: -------------------------------------------------------------------------------- 1 | #MC # lspconfig for nix 2 | { pkgs, ... }: { 3 | programs.neovim = { 4 | extraLuaConfig = '' 5 | require('lspconfig').nixd.setup{} 6 | require('lspconfig')['nixd'].setup { 7 | capabilities = require("cmp_nvim_lsp").default_capabilities(), 8 | } 9 | ''; 10 | extraPackages = with pkgs; [ 11 | nixd 12 | ]; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-lspconfig/python.nix: -------------------------------------------------------------------------------- 1 | #MC # lspconfig for python 2 | { pkgs, ... }: { 3 | programs.neovim = { 4 | extraLuaConfig = '' 5 | require('lspconfig').pyright.setup{} 6 | require('lspconfig')['pyright'].setup { 7 | capabilities = require("cmp_nvim_lsp").default_capabilities(), 8 | } 9 | ''; 10 | extraPackages = with pkgs; [ 11 | pyright 12 | ]; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-lspconfig/typos.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: { 2 | programs.neovim = { 3 | extraLuaConfig = '' 4 | require'lspconfig'.typos_lsp.setup{} 5 | ''; 6 | extraPackages = [ 7 | pkgs.typos-lsp 8 | ]; 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-lspconfig/xml.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: { 2 | programs.neovim = { 3 | extraLuaConfig = '' 4 | require'lspconfig'.lemminx.setup{ 5 | capabilities = require("cmp_nvim_lsp").default_capabilities(), 6 | } 7 | ''; 8 | extraPackages = [ 9 | pkgs.lemminx 10 | ]; 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-metals/default.nix: -------------------------------------------------------------------------------- 1 | #MC # nvim-metals: Scala LSP 2 | #MC 3 | #MC The JRE proxy need subtle configuration. 4 | # If jump to definition not work, try 5 | # * clean .metals/, ~/.bloop/, ~/.cache/mill 6 | # * MetalsResetChoice: Build server selection: mill-bsp 7 | { config, pkgs, ... }: 8 | let 9 | opt = import ../../../../opt.nix; 10 | jre_with_proxy = pkgs.callPackage ./jre_with_proxy.nix { 11 | jre = pkgs.openjdk_headless; 12 | proxyHost = "127.0.0.1"; 13 | proxyPort = toString opt.proxyPort; 14 | }; 15 | my-nvim-metals = { 16 | plugin = pkgs.vimPlugins.nvim-metals; 17 | type = "lua"; 18 | config = '' 19 | -- lspconfig.metals.setup{} 20 | local metals_config = require("metals").bare_config() 21 | metals_config.find_root_dir_max_project_nesting = 2 22 | metals_config.root_patterns = { 23 | "build.sbt", 24 | "build.sc", 25 | ".git", 26 | } 27 | metals_config.settings = { 28 | showImplicitArguments = true, 29 | excludedPackages = { "akka.actor.typed.javadsl", "com.github.swagger.akka.javadsl" }, 30 | serverProperties = { 31 | "-Dhttps.proxyHost=127.0.0.1", 32 | "-Dhttps.proxyPort=${toString opt.proxyPort}", 33 | "-Dhttp.proxyHost=127.0.0.1", 34 | "-Dhttp.proxyPort=${toString opt.proxyPort}", 35 | }, 36 | -- see `:h metalsBinaryPath`, "Another setting for you crazy Nix kids." Hahaha! 37 | metalsBinaryPath = "${pkgs.metals.override {jre = jre_with_proxy;}}/bin/metals", 38 | javaHome = "${jre_with_proxy}", 39 | showImplicitArguments = true, 40 | showImplicitConversionsAndClasses = true, 41 | showInferredType = true, 42 | -- use mill in system, preventing the situation where I can compile but I cannot use metals 43 | millScript = "mill", 44 | } 45 | metals_config.capabilities = require("cmp_nvim_lsp").default_capabilities() 46 | -- Autocmd that will actually be in charging of starting the whole thing 47 | local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true }) 48 | vim.api.nvim_create_autocmd("FileType", { 49 | group = nvim_metals_group, 50 | pattern = { "scala", "sbt" }, 51 | callback = function() 52 | require("metals").initialize_or_attach(metals_config) 53 | end, 54 | }) 55 | ''; 56 | }; 57 | in { 58 | programs.neovim = { 59 | plugins = [ 60 | my-nvim-metals 61 | ]; 62 | extraPackages = [ 63 | (pkgs.coursier.override { 64 | jre = jre_with_proxy; 65 | }) 66 | ]; 67 | 68 | }; 69 | # nvim-metals proxy for bloop 70 | home.file.jvmopts = { 71 | text = '' 72 | -Dhttps.proxyHost=127.0.0.1 73 | -Dhttps.proxyPort=${toString opt.proxyPort} 74 | -Dhttp.proxyHost=127.0.0.1 75 | -Dhttp.proxyPort=${toString opt.proxyPort} 76 | ''; 77 | target = ".bloop/.jvmopts"; 78 | }; 79 | } 80 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-metals/jre_with_proxy.nix: -------------------------------------------------------------------------------- 1 | #MC # JRE with Proxy 2 | #MC 3 | #MC Let JRE aware of proxy by default. 4 | #MC This package can be used standalone, while my main usage is for nvim-metals lsp. 5 | #MC Without proxy, the scala package update make me headached. 6 | #MC 7 | #MC For usage example, see [my nvim-metals config](./default.nix) 8 | { runCommand 9 | , writeShellScript 10 | , jre 11 | , lndir 12 | , proxyHost 13 | , proxyPort 14 | }: let 15 | java_with_proxy_sh = writeShellScript "java" '' 16 | ${jre}/bin/java -Dhttp.proxyHost=${proxyHost} -Dhttp.proxyPort=${proxyPort} -Dhttps.proxyHost=${proxyHost} -Dhttps.proxyPort=${proxyPort} "$@" 17 | ''; 18 | in runCommand "jre_with_proxy" {} '' 19 | mkdir -p $out 20 | ${lndir}/bin/lndir -silent ${jre} $out 21 | rm $out/bin/java 22 | ln -s ${java_with_proxy_sh} $out/bin/java 23 | '' 24 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-nav.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: { 2 | programs.neovim = { 3 | plugins = [{ 4 | plugin = pkgs.vimPlugins.nvim-navic; 5 | type = "lua"; 6 | config = '' 7 | require("nvim-navic").setup { 8 | lsp = { 9 | auto_attach = true, 10 | }, 11 | } 12 | -- https://unix.stackexchange.com/questions/224771/what-is-the-format-of-the-default-statusline 13 | -- %<%f %h%w%m%r%=%-14.(%l,%c%V%) %P 14 | vim.o.statusline = "%<%f %h%w%m%r " .. 15 | -- set maximum width of nvim-navic str: winwidth-40 16 | -- exec %{%...%} results in '%.xx(yyyy%)', where xx is the max width, yyyy is the navic str 17 | "%{%'%.' .. (winwidth(0)-40) .. '(' .. v:lua.require'nvim-navic'.get_location() .. '%)'%}" .. 18 | " %=%-5.(%l,%c%V%) %P" 19 | ''; 20 | }{ 21 | plugin = pkgs.vimPlugins.nvim-navbuddy; 22 | type = "lua"; 23 | config = '' 24 | require("nvim-navbuddy").setup { 25 | lsp = { 26 | auto_attach = true, 27 | }, 28 | mappings = { 29 | [""] = require("nvim-navbuddy.actions").parent(), 30 | [""] = require("nvim-navbuddy.actions").children(), 31 | }, 32 | } 33 | ''; 34 | }]; 35 | }; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-treesitter.nix: -------------------------------------------------------------------------------- 1 | #MC # nvim-treesitter: languages parsing 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | #MC ## d2-vim vs tree-sitter-d2 5 | #MC 6 | #MC When edit a large d2 file using d2-vim, the cursor movement becomes lag. 7 | #MC However, tree-sitter-d2 works fluently. 8 | #MC So I replace the d2-vim with tree-sitter-d2. 9 | tree-sitter-d2 = pkgs.tree-sitter.buildGrammar rec { 10 | language = "d2"; 11 | # tree-sitter language version 14 12 | version = "0.5.1"; 13 | src = pkgs.fetchFromGitHub { 14 | owner = "ravsii"; 15 | repo = "tree-sitter-d2"; 16 | rev = "v${version}"; 17 | hash = "sha256-Ru+EAtnBl+Td4HxHPXLwcXOiFB/NbYPE5AhMNFyP2Kg="; 18 | }; 19 | }; 20 | my-nvim-treesitter = { 21 | # Available languages see: 22 | # https://github.com/nvim-treesitter/nvim-treesitter 23 | # see `pkgs.tree-sitter.builtGrammars.` 24 | # with `tree-sitter-` prefix and `-grammar` suffix removed 25 | plugin = pkgs.vimPlugins.nvim-treesitter.withPlugins (tree-sitter: [ 26 | tree-sitter.c 27 | tree-sitter.cpp 28 | tree-sitter.python 29 | tree-sitter.markdown 30 | tree-sitter.lua 31 | tree-sitter-d2 32 | ]); 33 | type = "lua"; 34 | config = '' 35 | require 'nvim-treesitter.configs'.setup { 36 | -- TODO: https://github.com/NixOS/nixpkgs/issues/189838 37 | -- ensure_installed = {"c", "cpp", "python", "markdown"}, 38 | ensure_installed = {}, 39 | sync_install = false, 40 | highlight = { 41 | enable = true, 42 | additional_vim_regex_highlighting = false, 43 | disable = { 44 | "nix", 45 | }, 46 | }, 47 | } 48 | ''; 49 | }; 50 | in { 51 | programs.neovim = { 52 | plugins = [ 53 | my-nvim-treesitter 54 | ]; 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /usr/cli/vim/nvim-window-picker.nix: -------------------------------------------------------------------------------- 1 | #MC # nvim-window-picker 2 | { pkgs, ... }: { 3 | programs.neovim = { 4 | plugins = [{ 5 | plugin = pkgs.vimPlugins.nvim-window-picker; 6 | type = "lua"; 7 | config = '' 8 | require 'window-picker'.setup({ 9 | selection_chars = 'abcdefghijklmnopqrstuvwxyz', 10 | picker_config = { 11 | statusline_winbar_picker = { 12 | selection_display = function(char, windowid) 13 | return '[' .. char .. ']' .. vim.o.statusline 14 | end, 15 | }, 16 | }, 17 | show_prompt = false, 18 | highlights = { 19 | statusline = { 20 | unfocused = { 21 | fg = '#2c2e34', 22 | bg = '#7f8490', 23 | bold = true, 24 | }, 25 | }, 26 | }, 27 | }) 28 | vim.keymap.set('n', '', function() 29 | vim.api.nvim_set_current_win( require('window-picker').pick_window() ) 30 | end) 31 | vim.keymap.set('n', 'j', function() 32 | vim.api.nvim_set_current_win( require('window-picker').pick_window() ) 33 | end) 34 | ''; 35 | }]; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /usr/cli/vim/outline-nvim.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: { 2 | programs.neovim = { 3 | plugins = [{ 4 | plugin = pkgs.vimPlugins.outline-nvim; 5 | type = "lua"; 6 | config = '' 7 | require("outline").setup({ 8 | outline_window = { 9 | relative_width = false, 10 | }, 11 | guides = { 12 | enabled = false, -- I already have mini indentscope 13 | }, 14 | symbol_folding = { 15 | autofold_depth = 99, 16 | }, 17 | keymaps = { 18 | close = {}, -- disable close key 19 | }, 20 | }) 21 | ''; 22 | }]; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /usr/cli/vim/reject.avante-nvim.nix: -------------------------------------------------------------------------------- 1 | #MC # avante-nvim: AI 2 | #MC 3 | #MC 2025.1.27:使用中发现的问题: 4 | #MC * 没有:h 5 | #MC * 说了要去掉nui但仍然没有https://news.ycombinator.com/item?id=41353835 6 | #MC * 安装了dressing、nui、plenary(telescope都没问题)插件仍然不识别 7 | #MC ```vim 8 | #MC avante: require("avante.health").check() 9 | #MC 10 | #MC avante.nvim ~ 11 | #MC - ERROR Missing required plugin: stevearc/dressing.nvim 12 | #MC - ERROR Missing required plugin: MunifTanjim/nui.nvim 13 | #MC - ERROR Missing required plugin: nvim-lua/plenary.nvim 14 | #MC - OK Found required plugin: nvim-treesitter/nvim-treesitter 15 | #MC - OK Found icons plugin (nvim-web-devicons or mini.icons) 16 | #MC ``` 17 | #MC 简单看了代码avante checkhealth:lua/avante/utils/init.lua 18 | #MC 居然要使用lazy。按claude.ai的说法 19 | #MC “啊,这是实际的源码实现,比我之前解释的要简单很多。让我详细解释一下这个函数:” 20 | #MC 是不是就是因为简单,但是又没有强制要求安装lazy,遇到的问题? 21 | { lib, pkgs, ... }: 22 | { 23 | programs.neovim = { 24 | plugins = with pkgs.pkgsu.vimPlugins; (lib.mkAfter [ 25 | nui-nvim 26 | dressing-nvim 27 | { 28 | plugin = avante-nvim; 29 | type = "lua"; 30 | config = '' 31 | require('avante_lib').load() 32 | require('avante').setup ({ 33 | provider = "deepseek", 34 | vendors = { 35 | deepseek = { 36 | __inherited_from = "openai", 37 | api_key_name = "DEEPSEEK_API_KEY", 38 | endpoint = "https://api.deepseek.com", 39 | model = "deepseek-chat", 40 | }, 41 | }, 42 | }) 43 | ''; 44 | } 45 | ]); 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /usr/cli/vim/reject.distant-nvim.nix: -------------------------------------------------------------------------------- 1 | #MC # distant-nvim: edit remote files with local nvim 2 | #MC 3 | #MC 不足: 4 | #MC * 文档不在源码里,没有:h 5 | #MC * 文档写的很不清晰,找了半天才知道:DistantConnect和:DistantOpen 6 | #MC * 现有nvim文件操作似乎都不能用,比如:Ex比如ff等,都需要用它的:DistantOpen 7 | #MC * 简单尝试了xiangshan项目的跳转,没办法正常使用。但是sshfs一切正常 8 | { pkgs, ... }: { 9 | programs.neovim = { 10 | plugins = [{ 11 | plugin = pkgs.pkgsu.vimPlugins.distant-nvim; 12 | type = "lua"; 13 | config = '' 14 | require('distant'):setup() 15 | ''; 16 | }]; 17 | extraPackages = [ 18 | pkgs.pkgsu.distant 19 | ]; 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /usr/cli/vim/reject.remote-sshfs-nvim.nix: -------------------------------------------------------------------------------- 1 | #MC # Deprecated: remote-sshfs.nvim: integrate sshfs into nvim 2 | #MC 3 | #MC Reason of Deprecation: It is better to use sshfs CLI! 4 | #MC 5 | #MC In my opinion, sshfs provides a better experience than distant.nvim 6 | { pkgs, ... }: { 7 | programs.neovim = { 8 | plugins = [{ 9 | plugin = pkgs.vimUtils.buildVimPlugin { 10 | pname = "remote-sshfs.nvim"; 11 | version = "2025-2-10"; 12 | src = pkgs.fetchFromGitHub { 13 | owner = "NOSDuco"; 14 | repo = "remote-sshfs.nvim"; 15 | rev = "03f6c40c4032eeb1ab91368e06db9c3f3a97a75d"; 16 | hash = "sha256-vFEIISxhTIGSl9LzDYHuEIkjLGkU0y5XhfWI/i5DgN4="; 17 | }; 18 | }; 19 | type = "lua"; 20 | config = '' 21 | require('telescope').load_extension 'remote-sshfs' 22 | require('remote-sshfs').setup{ 23 | connections = { 24 | ssh_configs = { 25 | vim.fn.expand "$HOME" .. "/.ssh/config", 26 | vim.fn.expand "$HOME" .. "/Gist/Config/ssh.conf", 27 | "/etc/ssh/ssh_config", 28 | }, 29 | }, 30 | } 31 | ''; 32 | }]; 33 | extraPackages = [ 34 | pkgs.sshfs 35 | ]; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /usr/cli/vim/smartyank-nvim.nix: -------------------------------------------------------------------------------- 1 | #MC # smartyank-nvim: smart yank to clipboard 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | my-smartyank-nvim = { 5 | plugin = pkgs.vimPlugins.smartyank-nvim; 6 | type = "lua"; 7 | config = '' 8 | require('smartyank').setup { 9 | highlight = { 10 | enabled = false, -- not enable highlight yanked text 11 | }, 12 | validate_yank = function() return vim.v.operator == '"+y' end, 13 | } 14 | ''; 15 | }; 16 | in { 17 | programs.neovim = { 18 | plugins = [ 19 | my-smartyank-nvim 20 | ]; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /usr/cli/vim/telescope-nvim.nix: -------------------------------------------------------------------------------- 1 | #MC # telescope-nvim 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | my-telescope-nvim = { 5 | plugin = pkgs.vimPlugins.telescope-nvim; 6 | config = '' 7 | " search relative to file 8 | "" https://github.com/nvim-telescope/telescope.nvim/pull/902 9 | nnoremap ff lua require('telescope.builtin').find_files({cwd=require'telescope.utils'.buffer_dir()}) 10 | nnoremap fF lua require('telescope.builtin').find_files() 11 | nnoremap fb lua require('telescope.builtin').buffers() 12 | nnoremap fh lua require('telescope.builtin').help_tags() 13 | nnoremap ft lua require('telescope.builtin').treesitter() 14 | nnoremap fc lua require('telescope.builtin').command_history() 15 | nnoremap fC lua require('telescope.builtin').commands() 16 | ''; 17 | }; 18 | # Problem: unable to fuzzy search parenthesis '(' 19 | # https://github.com/nvim-telescope/telescope-fzf-native.nvim/issues/141 20 | my-telescope-fzf-native-nvim = { 21 | plugin = pkgs.vimPlugins.telescope-fzf-native-nvim; 22 | type = "lua"; 23 | config = '' 24 | require('telescope').setup { 25 | extensions = {fzf = {}}, 26 | defaults = { 27 | layout_strategy = 'vertical', 28 | layout_config = { 29 | height = 0.95, 30 | width = 0.95, 31 | -- do not disable preview 32 | preview_cutoff = 1, 33 | }, 34 | }, 35 | } 36 | require('telescope').load_extension('fzf') 37 | ''; 38 | }; 39 | my-telescope-live-grep-args-nvim = { 40 | plugin = pkgs.vimPlugins.telescope-live-grep-args-nvim; 41 | type = "lua"; 42 | config = '' 43 | require('telescope').load_extension("live_grep_args") 44 | 45 | -- nnoremap fg lua require('telescope.builtin').live_grep({cwd=require'telescope.utils'.buffer_dir()}) 46 | vim.keymap.set('n', 'fg', 'lua require("telescope").extensions.live_grep_args.live_grep_args({search_dirs={require"telescope.utils".buffer_dir()}})') 47 | -- nnoremap fG lua require('telescope.builtin').live_grep() 48 | vim.keymap.set('n', 'fG', 'lua require("telescope").extensions.live_grep_args.live_grep_args()') 49 | ''; 50 | }; 51 | in { 52 | programs.neovim = { 53 | plugins = [ 54 | my-telescope-nvim 55 | my-telescope-fzf-native-nvim 56 | pkgs.vimPlugins.plenary-nvim 57 | my-telescope-live-grep-args-nvim 58 | ]; 59 | extraPackages = with pkgs; [ 60 | ripgrep 61 | ]; 62 | }; 63 | } 64 | -------------------------------------------------------------------------------- /usr/cli/vim/vim-easy-align.nix: -------------------------------------------------------------------------------- 1 | #MC # vim-easy-align: A simple, easy-to-use Vim alignment plugin. 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | my-vim-easy-align = { 5 | plugin = pkgs.vimPlugins.vim-easy-align; 6 | config = '' 7 | " Start interactive EasyAlign in visual mode (e.g. vipga) 8 | xmap ga (EasyAlign) 9 | 10 | " Start interactive EasyAlign for a motion/text object (e.g. gaip) 11 | nmap ga (EasyAlign) 12 | 13 | let g:easy_align_delimiters = { 14 | \ '>': { 'pattern': '>>\|=>\|>' }, 15 | \ '/': { 16 | \ 'pattern': '//\+\|/\*\|\*/', 17 | \ 'delimiter_align': 'l', 18 | \ 'ignore_groups': ['!Comment'] }, 19 | \ ']': { 20 | \ 'pattern': '[\]]', 21 | \ 'left_margin': 0, 22 | \ 'right_margin': 0, 23 | \ 'stick_to_left': 0 24 | \ }, 25 | \ '[': { 26 | \ 'pattern': '[\[]', 27 | \ 'left_margin': 0, 28 | \ 'right_margin': 0, 29 | \ 'stick_to_left': 0 30 | \ }, 31 | \ ')': { 32 | \ 'pattern': '[)]', 33 | \ 'left_margin': 0, 34 | \ 'right_margin': 0, 35 | \ 'stick_to_left': 0 36 | \ }, 37 | \ '(': { 38 | \ 'pattern': '[(]', 39 | \ 'left_margin': 0, 40 | \ 'right_margin': 0, 41 | \ 'stick_to_left': 0 42 | \ }, 43 | \ } 44 | 45 | let g:easy_align_ignore_groups = [] " default: ['Comment', 'String'] 46 | ''; 47 | }; 48 | in { 49 | programs.neovim = { 50 | plugins = [ 51 | my-vim-easy-align 52 | ]; 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /usr/cli/vim/vim-floaterm.nix: -------------------------------------------------------------------------------- 1 | #MC # vim-floaterm: floating terminal 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | my-vim-floaterm = { 5 | plugin = pkgs.vimPlugins.vim-floaterm; 6 | config = '' 7 | nmap t :FloatermNew --cwd= 8 | " let g:floaterm_keymap_new = 't' 9 | let g:floaterm_width = 0.8 10 | let g:floaterm_height = 0.8 11 | " Set floaterm window's background 12 | hi Floaterm guibg=black 13 | ''; 14 | }; 15 | in { 16 | programs.neovim = { 17 | plugins = [ 18 | my-vim-floaterm 19 | ]; 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /usr/cli/vim/vim-mark.nix: -------------------------------------------------------------------------------- 1 | #MC # vim-mark: multi-color highlight 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | vim-ingo-library = pkgs.vimUtils.buildVimPlugin { 5 | name = "vim-ingo-library"; 6 | src = pkgs.fetchFromGitHub { 7 | owner = "inkarkat"; 8 | repo = "vim-ingo-library"; 9 | rev = "c93c33f803356b16bf4b4d122404d8251dc7b24d"; 10 | hash = "sha256-85h3S+5IjVIbTkYJasPXU+z/ALc9oT+MzdyjvTOhIwg="; 11 | }; 12 | }; 13 | my-vim-mark = { 14 | plugin = pkgs.vimUtils.buildVimPlugin { 15 | name = "vim-mark"; 16 | src = pkgs.fetchFromGitHub { 17 | owner = "inkarkat"; 18 | repo = "vim-mark"; 19 | rev = "76a25085d7c46f90fd5dfd7c43c3ba05b86ee192"; 20 | hash = "sha256-h2uaZ8dCUopNJ7fpf3BEoZNRk+25zqFukcHa3LomPSk="; 21 | }; 22 | }; 23 | config = '' 24 | " clear highlight created by vim-mark 25 | nnoremap :MarkClear 26 | " show all marks 27 | nnoremap M :Marks 28 | ''; 29 | }; 30 | in { 31 | programs.neovim = { 32 | plugins = [ 33 | my-vim-mark 34 | vim-ingo-library 35 | ]; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /usr/cli/vim/vim-matchup.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: { 2 | programs.neovim = { 3 | plugins = [{ 4 | plugin = pkgs.vimPlugins.vim-matchup; 5 | type = "lua"; 6 | config = '' 7 | vim.g.matchup_matchparen_offscreen = { method = "popup" } 8 | -- 不要加粗光标下的可匹配文字,不然写代码时常遇到的不协调感觉 9 | -- 比如写{}时{是普通字体}是加粗字体,光标左移一下,{变成加粗}是普通字体。 10 | vim.cmd("highlight MatchParenCur cterm=NONE gui=NONE") 11 | '' 12 | # * [Incompatibility with nvim-cmp snippet completion #328](Incompatibility with nvim-cmp snippet completion #328) 13 | # * [[Bug] Sniprun + matchup cause snippets to automatically be expanded in nvim-cmp #354](https://github.com/andymass/vim-matchup/issues/354) 14 | # * [fix(*) incopatibility with blink-cmp as well as nvim-cmp #354 #382](https://github.com/andymass/vim-matchup/pull/382/files) 15 | + '' 16 | require('cmp').event:on("menu_opened", function() 17 | vim.b.matchup_matchparen_enabled = false 18 | end) 19 | require('cmp').event:on("menu_closed", function() 20 | vim.b.matchup_matchparen_enabled = true 21 | end) 22 | ''; 23 | }]; 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /usr/cli/vim/winshift-nvim.nix: -------------------------------------------------------------------------------- 1 | #MC # winshift-nvim: rearrange windows 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | my-winshift-nvim = { 5 | plugin = pkgs.vimPlugins.winshift-nvim; 6 | type = "lua"; 7 | config = '' 8 | -- Lua 9 | require("winshift").setup({ 10 | highlight_moving_win = true, -- Highlight the window being moved 11 | focused_hl_group = "Visual", -- The highlight group used for the moving window 12 | -- moving_win_options = { 13 | -- -- These are local options applied to the moving window while it's 14 | -- -- being moved. They are unset when you leave Win-Move mode. 15 | -- wrap = true, 16 | -- cursorline = false, 17 | -- cursorcolumn = false, 18 | -- colorcolumn = "", 19 | -- }, 20 | keymaps = { 21 | disable_defaults = false, -- Disable the default keymaps 22 | win_move_mode = { 23 | ["h"] = "left", 24 | ["j"] = "down", 25 | ["k"] = "up", 26 | ["l"] = "right", 27 | ["H"] = "far_left", 28 | ["J"] = "far_down", 29 | ["K"] = "far_up", 30 | ["L"] = "far_right", 31 | [""] = "left", 32 | [""] = "down", 33 | [""] = "up", 34 | [""] = "right", 35 | [""] = "far_left", 36 | [""] = "far_down", 37 | [""] = "far_up", 38 | [""] = "far_right", 39 | }, 40 | }, 41 | ---A function that should prompt the user to select a window. 42 | --- 43 | ---The window picker is used to select a window while swapping windows with 44 | ---`:WinShift swap`. 45 | ---@return integer? winid # Either the selected window ID, or `nil` to 46 | --- indicate that the user cancelled / gave an invalid selection. 47 | window_picker = function() 48 | return require("winshift.lib").pick_window({ 49 | -- A string of chars used as identifiers by the window picker. 50 | picker_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", 51 | filter_rules = { 52 | -- This table allows you to indicate to the window picker that a window 53 | -- should be ignored if its buffer matches any of the following criteria. 54 | cur_win = true, -- Filter out the current window 55 | floats = true, -- Filter out floating windows 56 | filetype = {}, -- List of ignored file types 57 | buftype = {}, -- List of ignored buftypes 58 | bufname = {}, -- List of vim regex patterns matching ignored buffer names 59 | }, 60 | ---A function used to filter the list of selectable windows. 61 | ---@param winids integer[] # The list of selectable window IDs. 62 | ---@return integer[] filtered # The filtered list of window IDs. 63 | filter_func = nil, 64 | }) 65 | end, 66 | }) 67 | 68 | vim.keymap.set('n', 'm', 'WinShift') 69 | ''; 70 | }; 71 | in { 72 | programs.neovim = { 73 | plugins = [ 74 | my-winshift-nvim 75 | ]; 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /usr/gui.nix: -------------------------------------------------------------------------------- 1 | { config, pkgs, stdenv, lib, ... }: 2 | let 3 | opt = import ../opt.nix; 4 | xelfviewer = pkgs.callPackage ./gui/xelfviewer.nix {}; 5 | in 6 | { 7 | imports = [ 8 | ./gui/mime.nix 9 | ./gui/kdeconnect.nix 10 | ./gui/xdot.nix 11 | ./gui/firefox 12 | ./gui/warpd.nix 13 | ] ++ (lib.optionals (builtins.currentSystem=="x86_64-linux") [ 14 | ./gui/rustdesk.nix 15 | ]) ++ (if !opt.isWSL2 then [ 16 | ./gui/gnome 17 | ./gui/kitty 18 | ./gui/singleton_web_apps.nix 19 | ./gui/rofi.nix 20 | ./gui/xcolor.nix 21 | ] else [{ # install fonts for WSL 22 | fonts.fontconfig.enable = true; 23 | home.packages = with pkgs; [ 24 | noto-fonts-cjk-sans 25 | noto-fonts-cjk-serif 26 | noto-fonts-emoji 27 | ]; 28 | }]); 29 | 30 | home.packages = with pkgs; [ 31 | libnotify 32 | # browser 33 | # dont ask me for keyring chromium-like browsers! 34 | (chromium.override {commandLineArgs="--password-store=basic";}) 35 | ] ++ [ 36 | # network 37 | ] ++ pkgs.lib.optionals (builtins.currentSystem=="x86_64-linux") [ 38 | feishu 39 | (wechat-uos.override { 40 | buildFHSEnv = args: buildFHSEnv (args // { 41 | # bubble wrap wechat-uos's home directory 42 | extraBwrapArgs = [ 43 | "--bind ${config.home.homeDirectory}/.local/share/wechat-uos /home" 44 | "--chdir /home" 45 | ]; 46 | }); 47 | }) 48 | # wine weixin waste too much memory, more than 4GB!!! 49 | #(import ./gui/weixin.nix {}) 50 | nur.repos.linyinfeng.wemeet 51 | nur.repos.xddxdd.dingtalk 52 | # telegram desktop not provide aarch64 prebuilt 53 | tdesktop 54 | ] ++ [ 55 | transmission_4-gtk 56 | # text 57 | #wpsoffice 58 | libreoffice 59 | meld 60 | # TODO: use this after switching to wayland 61 | #wl-clipboard 62 | textsnatcher 63 | # draw 64 | drawio 65 | #aseprite-unfree 66 | inkscape 67 | gimp 68 | # viewer 69 | ] ++ pkgs.lib.optionals (builtins.currentSystem=="x86_64-linux") [ 70 | imhex 71 | xelfviewer 72 | ] ++ [ 73 | vlc 74 | obsidian 75 | ] ++ pkgs.lib.optionals (builtins.currentSystem=="x86_64-linux") [ 76 | ghidra 77 | ] ++ [ 78 | # management 79 | ] ++ pkgs.lib.optionals (builtins.currentSystem=="x86_64-linux") [ 80 | zotero 81 | ] ++ [ 82 | # pkgs.pkgsu.deskflow 83 | barrier 84 | keepassxc 85 | # entertainment 86 | antimicrox 87 | ]; 88 | 89 | xdg.mime.types = { 90 | drawio = { 91 | name = "draw-io"; 92 | type = "text/draw-io"; 93 | pattern = "*.drawio"; 94 | defaultApp = "drawio.desktop"; 95 | }; 96 | }; 97 | 98 | # home.file.autostart_deskflow = { 99 | # source = "${pkgs.pkgsu.deskflow}/share/applications/org.deskflow.deskflow.desktop"; 100 | # target = ".config/autostart/org.deskflow.deskflow.desktop"; 101 | # }; 102 | # use barrier due to its support of hotkey toggle screen! 103 | # see: https://github.com/deskflow/deskflow/issues/8006 104 | home.file.autostart_barrier = { 105 | source = "${pkgs.barrier}/share/applications/barrier.desktop"; 106 | target = ".config/autostart/barrier.desktop"; 107 | }; 108 | } 109 | -------------------------------------------------------------------------------- /usr/gui/feishu.md: -------------------------------------------------------------------------------- 1 |
2022.05.11
2 | 3 | # 安装deb包,以飞书为例 4 | 5 | **太长不看** 6 | 7 | * nix文件: https://github.com/xieby1/nix_config/blob/main/usr/gui/feishu.nix 8 | * 使用方法: 9 | ```nix 10 | home.packages = with pkgs; [ 11 | (callPackage ./feishu.nix {}) 12 | ]; 13 | ``` 14 | 15 | 参考nixpkgs/pkgs/applications/networking/instant-messengers/skypeforlinux/default.nix 16 | 17 | ## 测试环境 18 | 19 | nix-build -E "with import {}; callPackage ./default.nix {}" 20 | 21 | ## 权限问题 22 | 23 | nix-build遇到dpkg -x解压失败。 24 | 但是手动执行dpkg -x一切正常。 25 | 26 | https://unix.stackexchange.com/questions/138188/easily-unpack-deb-edit-postinst-and-repack-deb 27 | 28 | 确认是权限问题的实验 29 | 30 | 是s权限的问题。 31 | nix-build下不能添加s权限。 32 | 原因未知 33 | 34 | 复现方法 35 | 36 | ```bash 37 | touch $out/miao 38 | chmox +s $out/miao 39 | ls -l $out/miao 40 | ``` 41 | 42 | 解决方法,使用fakeroot. 43 | 44 | ## 补全库 45 | 46 | 使用ldd脚本,获取所有elf所需的库,挨个添加进rpath即可。 47 | 48 | ## 桌面 49 | 50 | application/*.desktop 51 | menu/*.menu // 负责图标 52 | 53 | -------------------------------------------------------------------------------- /usr/gui/firefox/default.nix: -------------------------------------------------------------------------------- 1 | #MC # firefox configurations 2 | { pkgs, ... }: 3 | { 4 | imports = [ 5 | ./apps 6 | ./extensions 7 | ]; 8 | programs.firefox = { 9 | enable = true; 10 | # If state version ≥ 19.09 then this should be a wrapped Firefox 11 | package = pkgs.firefox.overrideAttrs (old: { 12 | # MOZ_USE_XINPUT2=1 allow more smooth (pixel-level) scroll and zoom 13 | buildCommand = old.buildCommand + '' 14 | mv $out/bin/firefox $out/bin/firefox-no-xinput2 15 | makeWrapper $out/bin/firefox-no-xinput2 $out/bin/firefox --set-default MOZ_USE_XINPUT2 1 16 | ''; 17 | }); 18 | # id is default 0, thus this profile is default 19 | profiles.xieby1 = { 20 | settings = { 21 | # https://superuser.com/questions/1483037/making-firefox-fullscreen-like-without-actually-maximizing-the-window 22 | # the full screen hotkey/button will trigger fullscreen like normal, except it won't resize the window. 23 | "full-screen-api.ignore-widgets" = true; 24 | # Disable `alt` key of toggling menu bar 25 | "ui.key.menuAccessKeyFocuses" = false; 26 | "ui.key.menuAccessKey" = -1; # original number 18 27 | # enable userChrome.css 28 | "toolkit.legacyUserProfileCustomizations.stylesheets" = true; 29 | }; 30 | userChrome = 31 | # [Disabling the mouseover to reveal the address/toolbar while in fullscreen - old method doesn't work](https://support.mozilla.org/en-US/questions/1324666) 32 | # [prevent firefox from showing the address bar in fullscreen mode](https://support.mozilla.org/en-US/questions/1323320) 33 | '' 34 | *|div#fullscr-toggler {display:none!important;} 35 | ''; 36 | }; 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /usr/gui/firefox/extensions/darkreader.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: let 2 | darkreader = pkgs.nur.repos.rycee.firefox-addons.darkreader; 3 | in { 4 | programs.firefox = { 5 | profiles.xieby1 = { 6 | extensions.packages = [ darkreader ]; 7 | }; 8 | }; 9 | firefox-extensions.xieby1.browser-extension-data."${darkreader.addonId}" = { 10 | storage = { 11 | schemeVersion = 2; 12 | syncSettings = false; 13 | disabledFor = [ 14 | # markdown-preview-nvim: x.x.x.x:7768 15 | # markdown_revealjs daemon: x.x.x.x:7782 16 | "/.*:77[0-9][0-9]/" 17 | # markdown_revealjs 18 | "//home/.*/slides/index.html/" 19 | ]; 20 | }; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /usr/gui/firefox/extensions/default.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: { 2 | imports = [ 3 | ./module.nix 4 | 5 | ./sidebery.nix 6 | ./darkreader.nix 7 | ./smartproxy.nix 8 | ./smart-toc.nix 9 | ]; 10 | 11 | programs.firefox = { 12 | profiles.xieby1 = { 13 | extensions.packages = with pkgs.nur.repos.rycee.firefox-addons; [ 14 | # 😾😾😾 Chinese users cannot use ad block extensions 15 | # https://discourse.mozilla.org/t/chinese-users-cant-use-ad-blocker-extensions/94823 16 | ublock-origin 17 | vimium 18 | ]; 19 | settings = { 20 | # Automatically enable extensions 21 | "extensions.autoDisableScopes" = 0; 22 | }; 23 | }; 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /usr/gui/firefox/extensions/sidebery.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: let 2 | sidebery = pkgs.nur.repos.rycee.firefox-addons.sidebery; 3 | in { 4 | programs.firefox = { 5 | profiles.xieby1 = { 6 | extensions.packages = [ sidebery ]; 7 | # transparent floating sidebar 8 | # Why not use it? 9 | # Because: I tried two ways to adjust the height of sidebar dynamically, but all failed: 10 | # * user.js cannot inject js code 11 | # * css counter cannot used in height 12 | # 13 | #settings = { 14 | # "browser.tabs.allow_transparent_browser" = true; 15 | #}; 16 | #userChrome = '' 17 | # #sidebar-box { 18 | # height: 90%; 19 | # top: 5%; 20 | # right: 0; 21 | # position: absolute; 22 | # z-index: 99; 23 | # } 24 | # #browser, 25 | # tabbox#tabbrowser-tabbox, 26 | # #tabbrowser-tabpanels, 27 | # #sidebar-box, 28 | # #sidebar, 29 | # window#webextpanels-window { 30 | # background-color: transparent !important; 31 | # background-image: none !important; 32 | # } 33 | #''; 34 | #userContent = '' 35 | # @-moz-document regexp("^moz-extension://.*/sidebar/sidebar.html") { 36 | # :root { 37 | # background-color: transparent !important; 38 | # } 39 | # #root.root { 40 | # --frame-bg: transparent !important; 41 | # --toolbar-bg: black !important; 42 | # --frame-el-bg: black !important; 43 | # } 44 | # } 45 | #''; 46 | settings = { 47 | "sidebar.position_start" = false; # sidebar on the right 48 | }; 49 | userChrome = '' 50 | /* Completely Remove Firefox Tab Bar */ 51 | /* https://bricep.net/completely-remove-firefox-tab-bar/ */ 52 | #TabsToolbar { visibility: collapse !important; } 53 | 54 | #sidebar-header { display: none; } 55 | #sidebar-splitter { display: none; } 56 | #sidebar-box { 57 | width: 13vw !important; 58 | min-width: 8em !important; 59 | max-width: 15em !important; 60 | padding: 0 !important; 61 | } 62 | ''; 63 | }; 64 | }; 65 | 66 | firefox-extensions.xieby1 = { 67 | extension-settings = { 68 | commands = { 69 | # toggle sidebery 70 | _execute_sidebar_action = { precedenceList = [{ 71 | id = sidebery.addonId; 72 | installDate = 0; 73 | value = { shortcut = "F1"; }; 74 | enabled = true; 75 | }];}; 76 | search = { precedenceList = [{ 77 | id = sidebery.addonId; 78 | installDate = 0; 79 | value = { shortcut = "F2"; }; 80 | enabled = true; 81 | }];}; 82 | up_shift = { precedenceList = [{ 83 | id = sidebery.addonId; 84 | installDate = 0; 85 | value = { shortcut = ""; }; 86 | enabled = true; 87 | }];}; 88 | down_shift = { precedenceList = [{ 89 | id = sidebery.addonId; 90 | installDate = 0; 91 | value = { shortcut = ""; }; 92 | enabled = true; 93 | }];}; 94 | switch_to_next_tab = { precedenceList = [{ 95 | id = sidebery.addonId; 96 | installDate = 0; 97 | value = { shortcut = "Alt+Shift+Down"; }; 98 | enabled = true; 99 | }];}; 100 | switch_to_prev_tab = { precedenceList = [{ 101 | id = sidebery.addonId; 102 | installDate = 0; 103 | value = { shortcut = "Alt+Shift+Up"; }; 104 | enabled = true; 105 | }];}; 106 | }; 107 | }; 108 | }; 109 | } 110 | -------------------------------------------------------------------------------- /usr/gui/firefox/extensions/smart-toc.nix: -------------------------------------------------------------------------------- 1 | { pkgs, lib, ... }: let 2 | smart-toc = pkgs.nur.repos.rycee.firefox-addons.buildFirefoxXpiAddon { 3 | pname = "smart-toc"; 4 | version = "0.11.25"; 5 | addonId = "{40289693-01fe-4740-91ae-07344bf5b09b}"; 6 | url = "https://addons.mozilla.org/firefox/downloads/file/4485577/smart_toc-0.11.25.xpi"; 7 | sha256 = "17jpqy2qs3qc1m9l4kbqw14m5bkwfzb253wpf1x1b5p9q6sap8w8"; 8 | meta = with lib; { 9 | mozPermissions = [ 10 | "activeTab" 11 | "scripting" 12 | "storage" 13 | "tabs" 14 | "*://*/*" 15 | "file:///*" 16 | ]; 17 | platforms = platforms.all; 18 | }; 19 | }; 20 | in { 21 | programs.firefox = { 22 | profiles.xieby1 = { 23 | extensions.packages = [ smart-toc ]; 24 | }; 25 | }; 26 | firefox-extensions.xieby1 = { 27 | extension-settings = { 28 | commands = { 29 | toggle = {precedenceList = [{ 30 | id = smart-toc.addonId; 31 | installDate = 0; 32 | value = { shortcut = "Alt+E"; }; 33 | enabled = true; 34 | }];}; 35 | }; 36 | }; 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /usr/gui/firefox/extensions/smartproxy.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: let 2 | inherit (pkgs.nur.repos.rycee.firefox-addons) smartproxy; 3 | opt = import ../../../../opt.nix; 4 | in { 5 | programs.firefox = { 6 | profiles.xieby1 = { 7 | extensions.packages = [ smartproxy ]; 8 | }; 9 | }; 10 | firefox-extensions.xieby1 = { 11 | browser-extension-data."${smartproxy.addonId}" = { 12 | storage = { 13 | activeProfileId = "InternalProfile_SmartRules"; 14 | defaultProxyServerId = "defaultProxyServerId"; 15 | proxyServers = [{ 16 | name = "nix"; 17 | id = "defaultProxyServerId"; 18 | order = 0; 19 | host = "127.0.0.1"; 20 | port = opt.proxyPort; 21 | protocol = "HTTP"; 22 | username = ""; 23 | password = ""; 24 | proxyDNS = true; 25 | failoverTimeout = null; 26 | }]; 27 | proxyProfiles = [{ 28 | profileName = "Smart Proxy"; 29 | profileId = "InternalProfile_SmartRules"; 30 | profileProxyServerId = "defaultProxyServerId"; 31 | profileType = 2; 32 | enabled = true; 33 | rulesSubscriptions = [{ 34 | enabled = true; 35 | refreshRate = 6000; 36 | id = "gfwlist"; 37 | name = "gfwlist"; 38 | url = "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"; 39 | obfuscation = "Base64"; 40 | format = 0; 41 | applyProxy = 1; 42 | username = ""; 43 | password = ""; 44 | }]; 45 | profileTypeConfig = { 46 | builtin = true; 47 | editable = true; 48 | selectable = true; 49 | supportsSubscriptions = true; 50 | supportsProfileProxy = true; 51 | customProxyPerRule = true; 52 | canBeDisabled = true; 53 | supportsRuleActionWhitelist = true; 54 | defaultRuleActionIsWhitelist = false; 55 | }; 56 | }]; 57 | }; 58 | }; 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /usr/gui/gnome/calendar/default.nix: -------------------------------------------------------------------------------- 1 | { config, ... }: { 2 | imports = [ 3 | ./module.nix 4 | { # my private calendars 5 | gnome-calendar = let 6 | caldavs = "${config.home.homeDirectory}/Gist/Vault/caldavs.nix"; 7 | in if builtins.pathExists caldavs then import caldavs else {}; 8 | } 9 | ]; 10 | 11 | # public calendars 12 | gnome-calendar = { 13 | china_calendar = { 14 | # 包含所有类型日历(暂时除农历、天干地支)(时间段版本) 15 | url = "https://yangh9.github.io/ChinaCalendar/calendar_1.ics"; 16 | settings = { 17 | Calendar = { 18 | Color = "#82B366"; 19 | }; 20 | # do not show notifications for this calendar 21 | Alarms = { 22 | IncludeMe = false; 23 | ForEveryEvent = false; 24 | }; 25 | }; 26 | }; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /usr/gui/gnome/calendar/module.nix: -------------------------------------------------------------------------------- 1 | #MC # gnome-calendar module 2 | { config, pkgs, lib, ... }: { 3 | options = { 4 | gnome-calendar = lib.mkOption { 5 | # entry type 6 | type = lib.types.attrsOf (lib.types.submodule { 7 | options = { 8 | url = lib.mkOption { 9 | type = lib.types.str; 10 | default = ""; 11 | }; 12 | settings = lib.mkOption { 13 | type = lib.types.attrs; 14 | default = {}; 15 | }; 16 | }; 17 | }); 18 | default = {}; 19 | description = '' 20 | Attrs of calendars settings. 21 | 22 | gnome-calendar = { 23 | calendar1 = { 24 | url = "...calendar1.ics"; 25 | settings = {...calendar1 settings...} 26 | }; 27 | calendar2 = { 28 | url = "...calendar2.ics"; 29 | settings = {...calendar2 settings...} 30 | }; 31 | ... 32 | }; 33 | ''; 34 | }; 35 | }; 36 | 37 | config = { 38 | # Available options: /glib-2.0/schemas/org.gnome.evolution-data-server.calendar.gschema.xml 39 | dconf.settings."org/gnome/evolution-data-server/calendar" = { 40 | # Currently, cannot use audio, otherwise no notification pops out. 41 | # * https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/1226 42 | # * https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/1280 43 | notify-enable-audio = false; 44 | notify-enable-display = true; 45 | 46 | # Default reminder for all events in chosen calendars 47 | defall-reminder-enabled = true; 48 | # defall-reminder-interval = 15 49 | # defall-reminder-units = minutes 50 | }; 51 | home.activation = lib.mapAttrs (name: entry: 52 | let 53 | parseUrl = urlString: 54 | let 55 | protocolSplit = lib.strings.splitString "://" urlString; 56 | protocol = builtins.head protocolSplit; 57 | afterProtocol = builtins.elemAt protocolSplit 1; 58 | hostPathSplit = lib.strings.splitString "/" afterProtocol; 59 | host = builtins.head hostPathSplit; 60 | path = "/" + lib.strings.concatStringsSep "/" (builtins.tail hostPathSplit); 61 | in { 62 | inherit protocol host path; 63 | port = if protocol == "http" then 80 64 | else if protocol == "https" then 443 65 | else throw "unknown protocol: ${protocol}"; 66 | security = if protocol == "https" then "tls" 67 | else ""; 68 | }; 69 | parsedUrl = parseUrl entry.url; 70 | mergeCfg = lib.foldl lib.recursiveUpdate {}; 71 | cal_cfg = mergeCfg [ 72 | (import ./template.nix) 73 | { 74 | "Data Source" = { 75 | DisplayName = name; 76 | }; 77 | Authentication = { 78 | Host=parsedUrl.host; 79 | Port=parsedUrl.port; 80 | }; 81 | Security = { 82 | Method=parsedUrl.security; 83 | }; 84 | "WebDAV Backend" = { 85 | ResourcePath=parsedUrl.path; 86 | }; 87 | } 88 | entry.settings 89 | ]; 90 | src = (pkgs.formats.ini {}).generate "${name}.source" cal_cfg; 91 | dst = "${config.home.homeDirectory}/.config/evolution/sources/${name}.source"; 92 | # Why not using yq, due to Color=#xxxxxx, '#' will be identified as comment, and be striped 93 | in lib.hm.dag.entryAfter [ "writeBoundary" ] '' 94 | $DRY_RUN_CMD mkdir -p $VERBOSE_ARG $(dirname ${dst}) 95 | $DRY_RUN_CMD sed 's/LastNotified=.*/LastNotified='$(date -u +"%Y-%m-%dT%H:%M:%SZ")'/g' ${src} > ${dst} 96 | '' 97 | ) config.gnome-calendar; 98 | }; 99 | } 100 | -------------------------------------------------------------------------------- /usr/gui/gnome/calendar/template.nix: -------------------------------------------------------------------------------- 1 | { 2 | "Data Source" = { 3 | DisplayName = "toBeFilled"; 4 | Enabled=true; 5 | Parent="webcal-stub"; 6 | }; 7 | Authentication = { 8 | Host= "toBeFilled"; 9 | Method="plain/password"; 10 | Port=443; 11 | ProxyUid="system-proxy"; 12 | RememberPassword=true; 13 | User=""; 14 | CredentialName=""; 15 | IsExternal=false; 16 | }; 17 | Security = { 18 | Method="tls"; 19 | }; 20 | "WebDAV Backend" = { 21 | AvoidIfmatch=false; 22 | CalendarAutoSchedule=false; 23 | Color=""; 24 | DisplayName=""; 25 | EmailAddress=""; 26 | ResourcePath= "toBeFilled"; 27 | ResourceQuery=""; 28 | SslTrust=""; 29 | Order=4294967295; 30 | Timeout=90; 31 | }; 32 | Calendar = { 33 | BackendName="webcal"; 34 | Color = "#B85450"; 35 | Selected=true; 36 | Order=0; 37 | }; 38 | Offline = { 39 | StaySynchronized=true; 40 | }; 41 | Refresh = { 42 | Enabled=true; 43 | EnabledOnMeteredNetwork=true; 44 | IntervalMinutes=30; 45 | }; 46 | Alarms = { 47 | IncludeMe=true; 48 | # LastNotified="2025-02-24T13:27:00Z"; 49 | LastNotified=""; 50 | ForEveryEvent=true; 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /usr/gui/gnome/default.nix: -------------------------------------------------------------------------------- 1 | #MC Gnome settings 2 | { pkgs, lib, ... }: 3 | let 4 | opt = import ../../../opt.nix; 5 | in { 6 | imports = [ 7 | ./calendar 8 | ./extensions 9 | ]; 10 | home.packages = with pkgs; [ 11 | gnome-sound-recorder 12 | dconf-editor 13 | devhelp 14 | ]; 15 | 16 | # Setting: `gsettings set ` 17 | # Getting: `dconf dump /` 18 | dconf.settings = { 19 | "org/gnome/shell" = { 20 | ## dock icons 21 | favorite-apps = [ 22 | "org.gnome.Nautilus.desktop" 23 | "firefox.desktop" 24 | "chromium-browser.desktop" 25 | "spotify.desktop" 26 | ]; 27 | }; 28 | "org/gnome/shell/keybindings" = { 29 | # disable original super+A 30 | toggle-application-view = []; 31 | }; 32 | 33 | "org/gnome/desktop/session" = { 34 | idle-delay=lib.hm.gvariant.mkUint32 0; # never turn off screen 35 | }; 36 | "org/gnome/settings-daemon/plugins/power" = { 37 | ambient-enabled=false; 38 | idle-dim=false; 39 | power-button-action="nothing"; 40 | sleep-inactive-ac-timeout=3600; 41 | sleep-inactive-ac-type="nothing"; 42 | sleep-inactive-battery-type="suspend"; 43 | }; 44 | 45 | # predefined keyboard shortcuts 46 | "org/gnome/desktop/wm/keybindings" = { 47 | switch-applications=[]; 48 | switch-applications-backward=[]; 49 | switch-windows=["Tab"]; 50 | switch-windows-backward=["Tab"]; 51 | maximize=["Up"]; 52 | unmaximize=["Down"]; 53 | minimize=[]; 54 | move-to-workspace-left=["Left"]; 55 | move-to-workspace-right=["Right"]; 56 | switch-input-source=["space"]; 57 | switch-input-source-backward=["space"]; 58 | }; 59 | 60 | # nautilus 61 | "org/gtk/settings/file-chooser" = { 62 | sort-directories-first=true; 63 | }; 64 | 65 | "org/gnome/desktop/interface" = { 66 | enable-hot-corners=false; 67 | show-battery-percentage=true; 68 | }; 69 | 70 | # proxy 71 | "system/proxy" = {mode = "manual";}; 72 | "system/proxy/ftp" = {host="127.0.0.1"; port=opt.proxyPort;}; 73 | "system/proxy/http" = {host="127.0.0.1"; port=opt.proxyPort;}; 74 | "system/proxy/https" = {host="127.0.0.1"; port=opt.proxyPort;}; 75 | 76 | "org/gnome/mutter" = { 77 | dynamic-workspaces = true; 78 | }; 79 | }; 80 | 81 | # inspired by https://discourse.nixos.org/t/how-to-set-the-bookmarks-in-nautilus/36143 82 | home.activation.nautilus_bookmarks = lib.hm.dag.entryAfter [ "writeBoundary" ] '' 83 | # WSL2 may not have folder ~/.config/gtk-3.0 84 | $DRY_RUN_CMD mkdir -p $VERBOSE_ARG ~/.config/gtk-3.0 85 | $DRY_RUN_CMD ln -sf $VERBOSE_ARG ~/Gist/Config/nautilus_bookmarks ~/.config/gtk-3.0/bookmarks 86 | ''; 87 | } 88 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/advanced-alttab-window-switcher.nix: -------------------------------------------------------------------------------- 1 | #MC # advanced-alttab-window-switcher 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | pkgs.gnomeExtensions.advanced-alttab-window-switcher 5 | ]; 6 | dconf.settings = { 7 | "org/gnome/shell" = { 8 | enabled-extensions = [ 9 | "advanced-alt-tab@G-dH.github.com" 10 | ]; 11 | }; 12 | "org/gnome/shell/extensions/advanced-alt-tab-window-switcher" = { 13 | switcher-popup-preview-selected=2; 14 | win-switcher-popup-filter=2; 15 | }; 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/auto-accent-colour.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: { 2 | home.packages = [ 3 | pkgs.gnomeExtensions.auto-accent-colour 4 | ]; 5 | dconf.settings = { 6 | "org/gnome/shell" = { 7 | enabled-extensions = [ 8 | "auto-accent-colour@Wartybix" 9 | ]; 10 | }; 11 | "org/gnome/shell/extensions/auto-accent-colour" = { 12 | hide-indicator = true; 13 | }; 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/bing-wallpaper-changer.nix: -------------------------------------------------------------------------------- 1 | #MC # BingWallpaper 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | pkgs.gnomeExtensions.bing-wallpaper-changer 5 | # random-wallpaper-wip-v3 6 | ]; 7 | dconf.settings = { 8 | "org/gnome/shell" = { 9 | enabled-extensions = [ 10 | "BingWallpaper@ineffable-gmail.com" 11 | # "randomwallpaper@iflow.space" 12 | ]; 13 | }; 14 | "org/gnome/shell/extensions/bingwallpaper" = { 15 | market="zh-CN"; 16 | delete-previous=true; 17 | download-folder="/tmp/pictures"; 18 | }; 19 | # "org/gnome/shell/extensions/space-iflow-randomwallpaper" = { 20 | # auto-fetch = true; 21 | # change-lock-screen = true; 22 | # hours = 8; 23 | # minutes = 29; 24 | # source = "genericJSON"; 25 | # # source = "wallhaven"; 26 | # }; 27 | # "org/gnome/shell/extensions/space-iflow-randomwallpaper/genericJSON" = { 28 | # generic-json-request-url = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"; 29 | # generic-json-response-path = "$.images[0].url"; 30 | # generic-json-url-prefix = "http://www.bing.com"; 31 | # }; 32 | # "org/gnome/shell/extensions/space-iflow-randomwallpaper/wallhaven" ={ 33 | # wallhaven-keyword="cardcaptor sakura"; 34 | # }; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/bluetooth-battery-meter.nix: -------------------------------------------------------------------------------- 1 | #MC # bluetooth battery meter 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | pkgs.gnomeExtensions.bluetooth-battery-meter 5 | ]; 6 | dconf.settings = { 7 | "org/gnome/shell" = { 8 | enabled-extensions = [ 9 | "Bluetooth-Battery-Meter@maniacx.github.com" 10 | ]; 11 | }; 12 | "org/gnome/shell/extensions/Bluetooth-Battery-Meter" = { 13 | enable-battery-level-text = true; 14 | }; 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/customize-ibus.nix: -------------------------------------------------------------------------------- 1 | #MC # customize-ibus: input method customization 2 | { pkgs, lib, ... }: { 3 | home.packages = [ 4 | pkgs.gnomeExtensions.customize-ibus 5 | ]; 6 | dconf.settings = { 7 | "org/gnome/shell" = { 8 | enabled-extensions = [ 9 | "customize-ibus@hollowman.ml" 10 | ]; 11 | }; 12 | "org/gnome/desktop/input-sources" = { 13 | sources = with lib.hm.gvariant; mkArray 14 | "(${lib.concatStrings [type.string type.string]})" [ 15 | (mkTuple ["xkb" "us"]) 16 | (mkTuple ["ibus" "rime"]) 17 | (mkTuple ["ibus" "mozc-jp"]) 18 | (mkTuple ["ibus" "hangul"]) 19 | ]; 20 | }; 21 | "org/gnome/shell/extensions/customize-ibus" = { 22 | candidate-orientation = lib.hm.gvariant.mkUint32 1; 23 | custom-font="Iosevka Nerd Font 16"; 24 | enable-orientation=true; 25 | input-indicator-only-on-toggle=false; 26 | input-indicator-only-use-ascii=false; 27 | use-custom-font=true; 28 | use-indicator-show-delay=true; 29 | }; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/dash-to-dock.nix: -------------------------------------------------------------------------------- 1 | #MC # dash-to-dock 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | pkgs.gnomeExtensions.dash-to-dock 5 | ]; 6 | dconf.settings = { 7 | "org/gnome/shell" = { 8 | enabled-extensions = [ 9 | "dash-to-dock@micxgx.gmail.com" 10 | ]; 11 | }; 12 | "org/gnome/shell/extensions/dash-to-dock" = { 13 | click-action="focus-or-appspread"; 14 | transparency-mode = "FIXED"; 15 | background-opacity = 0.4; 16 | }; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/default.nix: -------------------------------------------------------------------------------- 1 | #MC # Gnome Extensions 2 | #MC 3 | #MC Each time home-manager switched, no need log out. 4 | #MC Just reload extension by +F2 r 5 | { pkgs, ... }: { 6 | imports = [ 7 | ./advanced-alttab-window-switcher.nix 8 | ./bing-wallpaper-changer.nix 9 | ./bluetooth-battery-meter.nix 10 | ./customize-ibus.nix 11 | ./dash-to-dock.nix 12 | ./gtile.nix 13 | ./hide-top-bar.nix 14 | ./pano.nix 15 | ./system-monitor.nix 16 | ./transparent-top-bar.nix 17 | ./unite.nix 18 | ./lunar-calendar.nix 19 | ./auto-accent-colour.nix 20 | ]; 21 | home.packages = with pkgs.gnomeExtensions; [ 22 | always-show-titles-in-overview 23 | x11-gestures 24 | ] ++ [ 25 | pkgs.gnome45Extensions."permanent-notifications@bonzini.gnu.org" 26 | ]; 27 | dconf.settings = { 28 | "org/gnome/shell" = { 29 | disable-extension-version-validation = true; 30 | ## enabled gnome extensions 31 | disable-user-extensions = false; 32 | disabled-extensions = []; 33 | enabled-extensions = [ 34 | "Always-Show-Titles-In-Overview@gmail.com" 35 | "x11gestures@joseexposito.github.io" 36 | "permanent-notifications@bonzini.gnu.org" 37 | ]; 38 | }; 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/gtile.nix: -------------------------------------------------------------------------------- 1 | #MC # gtile: tiled windows manager 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | pkgs.gnomeExtensions.gtile 5 | ]; 6 | dconf.settings = { 7 | "org/gnome/shell" = { 8 | enabled-extensions = [ 9 | "gTile@vibou" 10 | ]; 11 | }; 12 | "org/gnome/shell/extensions/gtile" = { 13 | animation=true; 14 | global-presets=true; 15 | grid-sizes="16x10"; 16 | preset-resize-1=["bracketleft"]; 17 | preset-resize-2=["bracketright"]; 18 | preset-resize-3=["comma"]; 19 | preset-resize-4=["period"]; 20 | preset-resize-5=["semicolon"]; 21 | preset-resize-6=["apostrophe"]; 22 | preset-resize-7=["slash"]; 23 | resize1="2x2 1:1 1:1"; 24 | resize2="2x2 2:1 2:1"; 25 | resize3="2x2 1:2 1:2"; 26 | resize4="2x2 2:2 2:2"; 27 | resize5="4x8 2:2 3:7"; 28 | resize6="1x2 1:1 1:1"; 29 | resize7="1x2 1:2 1:2"; 30 | show-icon=false; 31 | }; 32 | }; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/hide-top-bar.nix: -------------------------------------------------------------------------------- 1 | #MC # hide-top-bar 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | pkgs.gnomeExtensions.hide-top-bar 5 | ]; 6 | dconf.settings = { 7 | "org/gnome/shell" = { 8 | enabled-extensions = [ 9 | "hidetopbar@mathieu.bidon.ca" 10 | ]; 11 | }; 12 | "org/gnome/shell/extensions/hidetopbar" = { 13 | mouse-sensitive = true; 14 | enable-active-window=false; 15 | enable-intellihide=true; 16 | # enable shortcut +v show nofication list, +s show quick settings, and so on 17 | keep-round-corners=true; 18 | shortcut-delay = 0.0; 19 | shortcut-keybind = ["h"]; 20 | }; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/lunar-calendar.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: { 2 | home.packages = with pkgs.gnomeExtensions; [ 3 | lunar-calendar 4 | ]; 5 | dconf.settings = { 6 | "org/gnome/shell" = { 7 | enabled-extensions = [ 8 | "lunarcal@ailin.nemui" 9 | ]; 10 | }; 11 | "org/gnome/shell/extensions/lunar-calendar" = { 12 | # 日历内的节日 13 | jrrilinei = true; 14 | # 顶栏日期 15 | show-date = true; 16 | # 顶栏时间 17 | show-time = false; 18 | # 语言:大陆 19 | yuyan = 0; 20 | }; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/pano.nix: -------------------------------------------------------------------------------- 1 | #MC # pano: Next-gen Clipboard Manager for Gnome Shell 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | pkgs.gnomeExtensions.pano 5 | ]; 6 | dconf.settings = { 7 | "org/gnome/shell" = { 8 | enabled-extensions = [ 9 | "pano@elhan.io" 10 | ]; 11 | }; 12 | "org/gnome/shell/extensions/pano" = { 13 | play-audio-on-copy=false; 14 | send-notification-on-copy=false; 15 | paste-on-select=false; 16 | }; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/system-monitor.nix: -------------------------------------------------------------------------------- 1 | #MC # system-monitor 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | # replace system-monitor(-next) with vitals 5 | # refers to https://github.com/mgalgs/gnome-shell-system-monitor-applet/issues/57 6 | # vitals 7 | pkgs.gnomeExtensions.system-monitor-next 8 | ]; 9 | dconf.settings = { 10 | "org/gnome/shell" = { 11 | enabled-extensions = [ 12 | # "Vitals@CoreCoding.com" 13 | "system-monitor-next@paradoxxx.zero.gmail.com" 14 | ]; 15 | }; 16 | # "org/gnome/shell/extensions/vitals" = { 17 | # fixed-widths = true; 18 | # hide-icons = true; 19 | # hot-sensors = [ 20 | # "_processor_usage_" 21 | # "_memory_usage_" 22 | # "__network-rx_max__" 23 | # "__network-tx_max__" 24 | # ]; 25 | # show-fan = false; 26 | # show-system = false; 27 | # show-temperature = false; 28 | # show-voltage = false; 29 | # update-time = 2; 30 | # }; 31 | "org/gnome/shell/extensions/system-monitor-next-applet" = { 32 | compact-display = true; 33 | icon-display = false; 34 | swap-display = true; 35 | cpu-style = "digit"; 36 | memory-style = "digit"; 37 | net-style = "digit"; 38 | swap-style = "digit"; 39 | cpu-show-text = false; 40 | memory-show-text = false; 41 | net-show-text = false; 42 | swap-show-text = false; 43 | }; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/transparent-top-bar.nix: -------------------------------------------------------------------------------- 1 | #MC # transparent-top-bar: able to adjust transparency 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | pkgs.gnomeExtensions.transparent-top-bar-adjustable-transparency 5 | ]; 6 | dconf.settings = { 7 | "org/gnome/shell" = { 8 | enabled-extensions = [ 9 | "transparent-top-bar@ftpix.com" 10 | ]; 11 | }; 12 | "com/ftpix/transparentbar" = { 13 | dark-full-screen = false; 14 | transparency = 40; 15 | }; 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /usr/gui/gnome/extensions/unite.nix: -------------------------------------------------------------------------------- 1 | #MC # unite: unite style 2 | { pkgs, ... }: { 3 | home.packages = [ 4 | pkgs.gnomeExtensions.unite 5 | ]; 6 | dconf.settings = { 7 | "org/gnome/shell" = { 8 | enabled-extensions = [ "unite@hardpixel.eu" ]; 9 | }; 10 | "org/gnome/shell/extensions/unite" = { 11 | app-menu-ellipsize-mode="end"; 12 | extend-left-box=false; 13 | greyscale-tray-icons=false; 14 | hide-app-menu-icon=false; 15 | hide-dropdown-arrows=true; 16 | hide-window-titlebars="always"; 17 | notifications-position="center"; 18 | reduce-panel-spacing=true; 19 | show-window-buttons="always"; 20 | use-activities-text = false; 21 | window-buttons-placement="last"; 22 | window-buttons-theme="materia"; 23 | restrict-to-primary-screen=false; 24 | }; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /usr/gui/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xieby1/nix_config/eecf06aa8a787aaaaa4bdfca7984d45d768f812a/usr/gui/index.md -------------------------------------------------------------------------------- /usr/gui/kdeconnect.nix: -------------------------------------------------------------------------------- 1 | #MC # KDE Connect 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | mykdeconnect = pkgs.plasma5Packages.kdeconnect-kde; 5 | #MC This customized version of KDE Connect allow share PC's keyboard smoothly to android. 6 | #mykdeconnect = pkgs.kdeconnect.overrideAttrs (old: { 7 | # patches = [( pkgs.fetchpatch { 8 | # url = "https://raw.githubusercontent.com/xieby1/kdeconnect-kde-enhanced/4610431b932b2fab05d7e0fc55e7306dc7ff0910/diff.patch"; 9 | # hash = "sha256-NL/TVOMEhdJ/W7UTxjF7Qjnq7JciNvl08BC1wrBfvHo="; 10 | # })]; 11 | # # cmakeFlags = "-DCMAKE_BUILD_TYPE=Debug -DQT_FORCE_STDERR_LOGGING=1"; 12 | #}); 13 | in { 14 | home.packages = [ 15 | mykdeconnect 16 | ]; 17 | #MC Auto startup KDE Connect after Gnome GUI login. 18 | home.file.kde_connect_indicator = { 19 | source = "${mykdeconnect}/share/applications/org.kde.kdeconnect.nonplasma.desktop"; 20 | target = ".config/autostart/org.kde.kdeconnect.nonplasma.desktop"; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /usr/gui/kitty/search.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: let 2 | kitty-kitten-search = pkgs.runCommand "kitty-kitten-search" { 3 | src = pkgs.fetchFromGitHub { 4 | owner = "trygveaa"; 5 | repo = "kitty-kitten-search"; 6 | rev = "0760138fad617c5e4159403cbfce8421ccdfe571"; 7 | hash = "sha256-egisza7V5dWplRYHIYt4bEQdqXa4E7UhibyWJAup8as="; 8 | }; 9 | } '' 10 | mkdir $out 11 | cp $src/scroll_mark.py $out/scroll_mark.py 12 | sed 's/typing/typing_compat/' $src/search.py > $out/search.py 13 | ''; 14 | in { 15 | home.file.kitty_search = { 16 | source = "${kitty-kitten-search}/search.py"; 17 | target = ".config/kitty/search.py"; 18 | }; 19 | home.file.kitty_scroll_mark = { 20 | source = "${kitty-kitten-search}/scroll_mark.py"; 21 | target = ".config/kitty/scroll_mark.py"; 22 | }; 23 | programs.kitty = { 24 | extraConfig = '' 25 | map ctrl+shift+f launch --location=hsplit --allow-remote-control kitty +kitten search.py @active-kitty-window-id 26 | ''; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /usr/gui/kitty/timer.nix: -------------------------------------------------------------------------------- 1 | { lib, ... }: { 2 | ## after direnv's bash.initExtra 3 | programs.bash.initExtra = lib.mkOrder 2000 '' 4 | # https://stackoverflow.com/questions/1862510/how-can-the-last-commands-wall-time-be-put-in-the-bash-prompt 5 | function timer_start { 6 | _timer=''${_timer:-$SECONDS} 7 | } 8 | function timer_stop { 9 | last_timer=$(($SECONDS - $_timer)) 10 | unset _timer 11 | 12 | _notification="[''${last_timer}s⏰] Job finished!" 13 | if [[ "$TERM" =~ tmux ]]; then 14 | # https://github.com/tmux/tmux/issues/846 15 | printf '\033Ptmux;\033\x1b]99;;%s\033\x1b\\\033\\' "$_notification" 16 | else 17 | printf '\x1b]99;;%s\x1b\\' "$_notification" 18 | fi 19 | } 20 | ''; 21 | programs.kitty = { 22 | extraConfig = '' 23 | # Notify when a long running command is finished 24 | ## https://github.com/kovidgoyal/kitty/issues/1892 25 | map f1 send_text all \x1a timer_start; fg; timer_stop \r 26 | ''; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /usr/gui/mime.nix: -------------------------------------------------------------------------------- 1 | # https://nixos.org/manual/nixos/stable/#sec-writing-modules 2 | # refers to syncthing module 3 | 4 | # list options: 5 | # home-manager option xdg.mime.types.\"*\" 6 | # nixos option 7 | { config 8 | , lib 9 | , pkgs 10 | , ... 11 | }: 12 | with lib; 13 | let 14 | cfg = config.xdg.mime.types; 15 | in 16 | { 17 | options = { 18 | xdg.mime.types = mkOption { 19 | default = {}; 20 | description = "Set MIME types and default applications."; 21 | example = '' 22 | xdg.mime.types.dot = { 23 | name = "graphviz-dot"; 24 | type = "text/graphviz-dot"; 25 | pattern = "*.dot"; 26 | defaultApp = "xdot.desktop"; 27 | }; 28 | ''; 29 | type = types.attrsOf (types.submodule ({name, ...}: 30 | { 31 | options = { 32 | name = mkOption { 33 | type = types.str; 34 | default = name; 35 | description = "The name of the xml file."; 36 | }; 37 | type = mkOption { 38 | type = types.str; 39 | default = ""; 40 | description = "The mime-type."; 41 | }; 42 | pattern = mkOption { 43 | type = types.str; 44 | default = ""; 45 | description = "The glob pattern."; 46 | }; 47 | defaultApp = mkOption { 48 | type = types.str; 49 | default = ""; 50 | description = "Default application for opening this MIME type."; 51 | }; 52 | }; 53 | })); 54 | }; 55 | }; 56 | 57 | # builtins.mapAttrs (n: v: {wang=v.miao;}) {file1={miao=1;}; file2={miao=2;};} 58 | # => {file1={wang=1;}; file2={wang=2;};} 59 | config = { 60 | home.file = builtins.mapAttrs (n: v: { 61 | text = '' 62 | 63 | 64 | 65 | 66 | 67 | 68 | ''; 69 | target = ".local/share/mime-types/${v.name}.xml"; 70 | onChange = '' 71 | ${pkgs.xdg-utils}/bin/xdg-mime install ~/.local/share/mime-types/${v.name}.xml 72 | ${pkgs.xdg-utils}/bin/xdg-mime default ${v.defaultApp} ${v.type} 73 | ''; 74 | }) cfg; 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /usr/gui/rofi.nix: -------------------------------------------------------------------------------- 1 | { config, pkgs, stdenv, lib, ... }: 2 | let 3 | my-rofi = pkgs.rofi.override { 4 | plugins = with pkgs; [ 5 | # rofi-file-browser 6 | ]; 7 | }; 8 | in 9 | { 10 | home.packages = with pkgs; [ 11 | my-rofi 12 | ]; 13 | 14 | # gnome keyboard shortcuts 15 | dconf.settings."org/gnome/settings-daemon/plugins/media-keys".custom-keybindings = [ 16 | "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/rofi_window/" 17 | "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/rofi_drun/" 18 | ]; 19 | dconf.settings."org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/rofi_window" = { 20 | binding="w"; 21 | command="rofi -show window"; 22 | name="rofi window"; 23 | }; 24 | dconf.settings."org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/rofi_drun" = { 25 | binding="d"; 26 | command="rofi -show drun"; 27 | name="rofi drun"; 28 | }; 29 | 30 | home.file.rofi_config = { 31 | target = ".config/rofi/config.rasi"; 32 | text = '' 33 | /* This is a comment */ 34 | /* rofi -dump-config */ 35 | 36 | configuration { 37 | modes: [ 38 | window, 39 | drun, 40 | run, 41 | ssh 42 | /* file-browser-extended */ 43 | ]; 44 | terminal: "kitty"; 45 | dpi: 1; 46 | show-icons: true; 47 | } 48 | filebrowser { 49 | directory: "~/Documents"; 50 | } 51 | 52 | /* man rofi-theme */ 53 | 54 | window { 55 | width: 80%; 56 | } 57 | ''; 58 | }; 59 | 60 | # home.file.rofi_file_browser_config = let 61 | # openDir = pkgs.writeScript "openDir" '' 62 | # if [[ -d "$1" ]]; then 63 | # xdg-open "$1" 64 | # elif [[ -f "$1" ]]; then 65 | # xdg-open "''${1%/*}" 66 | # fi 67 | # ''; 68 | # in { 69 | # target = ".config/rofi/file-browser"; 70 | # text = '' 71 | # # This is a comment 72 | # dir ~/Documents 73 | # depth 0 74 | # no-sort-by-type 75 | # sort-by-depth 76 | 77 | # # BUG: rofi -show-icons causes segmentation fault 78 | # # oc-search-path 79 | # # oc-cmd "nautilus" 80 | # # oc-cmd "${openDir}" 81 | # ''; 82 | # }; 83 | } 84 | -------------------------------------------------------------------------------- /usr/gui/rustdesk.nix: -------------------------------------------------------------------------------- 1 | #MC # rustdesk, the remote desktop app 2 | { config, pkgs, stdenv, lib, ... }: 3 | { 4 | home.packages = [ 5 | #MC The new version of rustdesk is rustdesk-flutter, 6 | #MC which is cached in offical nix binary cache. 7 | pkgs.rustdesk-flutter 8 | ]; 9 | #MC Auto startup rustdesk after Gnome GUI login. 10 | home.file.autostart_rustdesk_desktop = { 11 | source = "${pkgs.rustdesk-flutter}/share/applications/rustdesk.desktop"; 12 | target = ".config/autostart/rustdesk.desktop"; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /usr/gui/singleton_web_apps.nix: -------------------------------------------------------------------------------- 1 | { config, pkgs, ... }: 2 | # TODO: change it into a module 3 | # TODO: split 4 | let 5 | singleton = pkgs.writeShellScriptBin "singleton.sh" '' 6 | if [[ $# -lt 2 || $1 == "-h" ]] 7 | then 8 | echo "Usage: ''${0##*/} " 9 | echo " Only start a app once, if the app is running" 10 | echo " then bring it to foreground" 11 | exit 0 12 | fi 13 | 14 | if [[ "$1" == "kdeconnect.app" ]] 15 | then 16 | WID=$(${pkgs.xdotool}/bin/xdotool search --classname "$1") 17 | else 18 | WID=$(${pkgs.xdotool}/bin/xdotool search --onlyvisible --name "$1") 19 | fi 20 | 21 | if [[ -z $WID ]] 22 | then 23 | eval "''${@:2}" 24 | else 25 | for WIN in $WID 26 | do 27 | CURDESK=$(${pkgs.xdotool}/bin/xdotool get_desktop) 28 | ${pkgs.xdotool}/bin/xdotool set_desktop_for_window $WIN $CURDESK 29 | ${pkgs.xdotool}/bin/xdotool windowactivate $WIN 30 | done 31 | fi 32 | ''; 33 | singleton_sh = "${singleton}/bin/singleton.sh"; 34 | 35 | open_my_cheatsheet_md_sh = pkgs.writeShellScript "open_my_cheatsheet_md" '' 36 | cd ${config.home.homeDirectory}/Documents/Tech 37 | kitty nvim my_cheatsheet.mkd -c Outline 38 | make 39 | ''; 40 | in 41 | { 42 | xdg.desktopEntries = { 43 | # singleton apps 44 | my_cheatsheet_md = { 45 | name = "Cheatsheet Edit MD"; 46 | genericName = "cheatsheet"; 47 | exec = "${singleton_sh} my_cheatsheet.mkd ${open_my_cheatsheet_md_sh}"; 48 | icon = builtins.toFile "cheatsheet.svg" '' 49 | 50 | 51 | 52 | CS 53 | Edit 54 | MD 55 | 56 | 57 | ''; 58 | }; 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /usr/gui/typora.md: -------------------------------------------------------------------------------- 1 | # Typora 2 | 3 | 采用nixpkgs支持的最后的typora版本,即0.9.98。 4 | 5 | ```nix 6 | mytypora = (pkgs.callPackage (pkgs.fetchurl { 7 | url = "https://raw.githubusercontent.com/NixOS/nixpkgs/137f19d1d48b6d7c7901bb86729a2bce3588d4e9/pkgs/applications/editors/typora/default.nix"; 8 | sha256 = "057dk4hl4fljn50098g7l35sh7gwm7zqqqlrczv5lhmpgxi971c1"; 9 | }) {}).overrideAttrs (old: { 10 | src = pkgs.fetchurl { 11 | url = "https://web.archive.org/web/20211222112532/https://download.typora.io/linux/typora_0.9.98_amd64.deb"; 12 | sha256 = "1srj1fdcblfdsfvdnrqnwsxd3y8qd1h45p4sf1mxn6hr7z2s6ai6"; 13 | }; 14 | }); 15 | ``` 16 | 17 | 注:我尝试打包0.11.18, 18 | 发现这个版本会检测文件完整性, 19 | 因此基本上没办法用nix进行二次打包。 20 | 21 | -------------------------------------------------------------------------------- /usr/gui/warpd.nix: -------------------------------------------------------------------------------- 1 | { pkgs, lib, ... }: { 2 | home.packages = [ pkgs.warpd ]; 3 | home.file.autostart_warpd = { 4 | target = ".config/autostart/warpd.desktop"; 5 | text = '' 6 | [Desktop Entry] 7 | Type=Application 8 | Name=warpd 9 | Exec=${pkgs.warpd}/bin/warpd 10 | ''; 11 | }; 12 | 13 | # 为什么不用gnome快捷键? 14 | # * 一次性warpd启动比warpd后台运行慢 15 | # 为什么用gnome快捷键 16 | # * warpd没办法正确识别M-k键?或者是gnome抢了?要M-kk才行 17 | # dconf.settings."org/gnome/settings-daemon/plugins/media-keys".custom-keybindings = [ 18 | # "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/warpd-hint/" 19 | # "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/warpd-normal/" 20 | # ]; 21 | # dconf.settings."org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/warpd-hint" = { 22 | # binding="k"; 23 | # command = "warpd --hint"; 24 | # name="warpd-hint"; 25 | # }; 26 | # dconf.settings."org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/warpd-normal" = { 27 | # binding="k"; 28 | # command = "warpd --normal"; 29 | # name="warpd-normal"; 30 | # }; 31 | home.file.warpd_config = { 32 | target = ".config/warpd/config"; 33 | # Available options see `warpd --list-options`. 34 | # Available modifiers (according to warpd source code): 35 | # * alt: A- 36 | # * super/meta: M- 37 | # * shift: S- 38 | # * ctrl: C- 39 | # Available X11 key names by removing "XK_" prefix in ${pkgs.xorg.xorgproto}/include/X11/keysymdef.h 40 | text = lib.generators.toKeyValue {mkKeyValue=lib.generators.mkKeyValueDefault {} ": ";} { 41 | activation_key = "A-M-z"; # 一只手按A-M-z比A-M-c更方便! 42 | buttons = "q w e"; 43 | left = "Left"; 44 | up = "Up"; 45 | right = "Right"; 46 | down = "Down"; 47 | scroll_up = "S-Up"; 48 | scroll_down = "S-Down"; 49 | }; 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /usr/gui/waydroid.md: -------------------------------------------------------------------------------- 1 | # Wayland 2 | 3 | ```nix 4 | virtualisation.waydroid.enable = true; 5 | ``` 6 | 7 | 尝试使用weston,消息来源参考: 8 | 9 | * https://github.com/waydroid/waydroid/issues/470 10 | * https://wiki.archlinux.org/title/Waydroid 11 | 12 | wayland images: `/var/lib/waydroid/images/` 13 | 14 | ```bash 15 | weston --scale=2 16 | 17 | # 在weston里 18 | waydroid show-full-ui 19 | ``` 20 | 21 | weston快捷键参考`man weston-bindings` 22 | -------------------------------------------------------------------------------- /usr/gui/weixin.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} 2 | , wrapWine ? import ./wrapWine.nix {inherit pkgs;} 3 | }: 4 | 5 | let 6 | name = "weixin"; 7 | installer = builtins.fetchurl "https://dldir1.qq.com/weixin/Windows/WeChatSetup.exe"; 8 | regfile = builtins.toFile "${name}.reg" '' 9 | Windows Registry Editor Version 5.00 10 | 11 | # [HKEY_LOCAL_MACHINE\System\CurrentControlSet\Hardware Profiles\Current\Software\Fonts] 12 | # "LogPixels"=dword:000000F0 13 | 14 | [HKEY_CURRENT_USER\Software\Wine\X11 Driver] 15 | "Decorated"="N" 16 | ''; 17 | bin = wrapWine { 18 | inherit name; 19 | executable = "$WINEPREFIX/drive_c/Program Files/Tencent/WeChat/WeChat.exe"; 20 | tricks = ["riched20" "msls31"]; 21 | setupScript = '' 22 | LANG="zh_CN.UTF-8" 23 | ''; 24 | firstrunScript = '' 25 | # prevent weixin polluting my Documents folder 26 | rm -f $WINEPREFIX/drive_c/users/$USER/Documents 27 | mkdir -p $WINEPREFIX/drive_c/users/$USER/Documents 28 | 29 | wine ${installer} 30 | 31 | # 占用磁盘空间持续增加 32 | # https://github.com/vufa/deepin-wine-wechat-arch/issues/225 33 | mkdir -p $WINEPREFIX/drive_c/users/xieby1/AppData/Roaming/Tencent/WeChat/xweb/crash/Crashpad/ 34 | touch $WINEPREFIX/drive_c/users/xieby1/AppData/Roaming/Tencent/WeChat/xweb/crash/Crashpad/reports 35 | ''; 36 | inherit regfile; 37 | }; 38 | desktop = pkgs.makeDesktopItem { 39 | inherit name; 40 | desktopName = "Wine微信"; 41 | genericName = "weixin"; 42 | type = "Application"; 43 | exec = "${bin}/bin/${name}"; 44 | icon = pkgs.fetchurl { 45 | url = "https://cdn.cdnlogo.com/logos/w/79/wechat.svg"; 46 | sha256 = "1xk1dsia6favc3p1rnmcncasjqb1ji4vkmlajgbks0i3xf60lskw"; 47 | }; 48 | }; 49 | in 50 | pkgs.symlinkJoin { 51 | inherit name; 52 | paths = [bin desktop]; 53 | } 54 | -------------------------------------------------------------------------------- /usr/gui/wrapWine.nix: -------------------------------------------------------------------------------- 1 | # based on https://github.com/lucasew/nixcfg/blob/49d44c1a655f1c20d7354ecea942c78704067d50/pkgs/wrapWine.nix 2 | { pkgs ? import {} }: 3 | let 4 | inherit (builtins) length concatStringsSep; 5 | inherit (pkgs) lib cabextract 6 | writeShellScriptBin symlinkJoin; 7 | inherit (lib) makeBinPath; 8 | in 9 | { is64bits ? false 10 | , wine ? if is64bits then pkgs.wineWowPackages.stable else pkgs.wine 11 | , wineFlags ? "" 12 | , executable 13 | , chdir ? null 14 | , name 15 | , tricks ? [ ] 16 | , setupScript ? "" 17 | , firstrunScript ? "" 18 | , home ? "" 19 | , regfile ? null 20 | }: 21 | let 22 | wineBin = "${wine}/bin/wine${if is64bits then "64" else ""}"; 23 | requiredPackages = [ 24 | wine 25 | cabextract 26 | ]; 27 | PATH = makeBinPath requiredPackages; 28 | NAME = name; 29 | WINEARCH = 30 | if is64bits 31 | then "win64" 32 | else "win32"; 33 | WINE_NIX = "$HOME/.wine-nix"; 34 | WINEPREFIX = "${WINE_NIX}/${name}"; 35 | setupHook = '' 36 | ${wine}/bin/wineboot 37 | ''; 38 | tricksHook = 39 | if (length tricks) > 0 then 40 | let 41 | tricksStr = concatStringsSep " " tricks; 42 | tricksCmd = '' 43 | ${pkgs.winetricks}/bin/winetricks ${tricksStr} 44 | ''; 45 | in 46 | tricksCmd 47 | else ""; 48 | run = writeShellScriptBin name '' 49 | export APP_NAME="${NAME}" 50 | export WINEARCH=${WINEARCH} 51 | export WINE_NIX=${WINE_NIX} 52 | export PATH=$PATH:${PATH} 53 | export WINEPREFIX="${WINEPREFIX}" 54 | export EXECUTABLE="${executable}" 55 | mkdir -p "$WINE_NIX" 56 | ${setupScript} 57 | if [ ! -e "$EXECUTABLE" ] # if the executable does not exist 58 | then 59 | ${if regfile!=null 60 | then ''${wineBin} regedit /C ${regfile}'' 61 | else "" 62 | } 63 | ${setupHook} 64 | ${tricksHook} 65 | ${firstrunScript} 66 | else # no automatically run after installation! 67 | ${if chdir != null 68 | then ''cd "${chdir}"'' 69 | else ""} 70 | if [ ! "$REPL" == "" ]; # if $REPL is setup then start a shell in the context 71 | then 72 | bash 73 | exit 0 74 | fi 75 | 76 | ${wineBin} ${wineFlags} "$EXECUTABLE" "$@" 77 | fi 78 | ''; 79 | clean = writeShellScriptBin "${name}-clean" '' 80 | read -p "Are you sure you want to clean ${WINEPREFIX}? " prompt 81 | if [[ $prompt =~ [yY](es)* ]]; then 82 | rm ${WINEPREFIX} -rf 83 | fi 84 | ''; 85 | winecfg = writeShellScriptBin "${name}-cfg" '' 86 | export WINEARCH=${WINEARCH} 87 | WINEPREFIX=${WINE_NIX}/${name} winecfg $@ 88 | ''; 89 | _wine = writeShellScriptBin "${name}-wine" '' 90 | export WINEARCH=${WINEARCH} 91 | WINEPREFIX=${WINE_NIX}/${name} ${wineBin} $@ 92 | ''; 93 | in 94 | symlinkJoin { 95 | inherit name; 96 | paths = [run clean winecfg _wine]; 97 | } 98 | -------------------------------------------------------------------------------- /usr/gui/xcolor.nix: -------------------------------------------------------------------------------- 1 | #MC # XColor 2 | #MC 3 | #MC Why use XColor instead of gcolor3 or eyedropper? 4 | #MC Because they do not support zoom: e.g. https://github.com/FineFindus/eyedropper/issues/79 5 | { pkgs, ... }: { 6 | home.packages = [( 7 | let 8 | name = "xcolor-sleep"; 9 | # [Error when launching xcolor from the Activities overview: Could not grab pointer #38](https://github.com/Soft/xcolor/issues/38) 10 | exec = pkgs.writeShellScript name '' 11 | for ((n=0; n<3; n++)); do 12 | ${pkgs.xcolor}/bin/xcolor -s && break 13 | sleep 0.2 14 | done 15 | ''; 16 | in 17 | pkgs.runCommand name {} '' 18 | mkdir -p $out 19 | ${pkgs.xorg.lndir}/bin/lndir -silent ${pkgs.xcolor} $out 20 | rm $out/share/applications/XColor.desktop 21 | sed 's,^Exec.*,Exec=${exec},' ${pkgs.xcolor}/share/applications/XColor.desktop > $out/share/applications/XColor.desktop 22 | '' 23 | )]; 24 | } 25 | -------------------------------------------------------------------------------- /usr/gui/xdot.nix: -------------------------------------------------------------------------------- 1 | #MC # xdot, the dot (graphviz) viewer 2 | { config, pkgs, stdenv, lib, ... }: 3 | let 4 | #MC Add a xdot.desktop for my xdot. 5 | myxdot = pkgs.symlinkJoin { 6 | name = "myxdot"; 7 | paths = [ 8 | pkgs.xdot 9 | (pkgs.makeDesktopItem { 10 | name = "xdot"; 11 | desktopName = "xdot"; 12 | exec = "xdot %U"; 13 | icon = builtins.toFile "cheatsheet.svg" '' 14 | 15 | 16 | 17 | xdot 18 | 19 | 20 | ''; 21 | })];}; 22 | in { 23 | home.packages = [ 24 | myxdot 25 | ]; 26 | #MC Open *.dot files with xdot.desktop by default. 27 | xdg.mime.types.dot = { 28 | name = "graphviz-dot"; 29 | type = "text/graphviz-dot"; 30 | pattern = "*.dot"; 31 | defaultApp = "xdot.desktop"; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /usr/gui/xelfviewer.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | stdenv, 4 | fetchurl, 5 | dpkg, 6 | qt5 7 | }: 8 | let 9 | version = "0.05"; 10 | rpath = lib.makeLibraryPath [ 11 | qt5.qtbase 12 | ] + ":${stdenv.cc.cc.lib}/lib64"; 13 | src = 14 | if stdenv.hostPlatform.system == "x86_64-linux" then 15 | fetchurl { 16 | urls = [ 17 | "https://github.com/horsicq/XELFViewer/releases/download/0.05/xelfviewer_0.05_Ubuntu_22.04_amd64.deb" 18 | ]; 19 | sha256 = "0l6j0pnpfzwr8205xzis95k4x2la0mfy08bv6hfg32rh3bw906bz"; 20 | } 21 | else 22 | throw "xelfviewer is not supported on ${stdenv.hostPlatform.system}"; 23 | in 24 | stdenv.mkDerivation { 25 | pname = "xelfviewer"; 26 | inherit version; 27 | 28 | system = "x86_64-linux"; 29 | 30 | inherit src; 31 | 32 | nativeBuildInputs = [ qt5.wrapQtAppsHook ]; 33 | 34 | buildInputs = [ dpkg ]; 35 | 36 | dontUnpack = true; 37 | installPhase = '' 38 | mkdir -p $out 39 | dpkg-deb -x $src $out 40 | mv $out/usr/* $out/ 41 | rm -r $out/usr 42 | ''; 43 | 44 | postFixup = '' 45 | for file in $(find $out -type f \( -perm /0111 -o -name \*.so\* \) ); do 46 | patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$file" || true 47 | patchelf --set-rpath ${rpath}:$out/lib/xelfviewer $file || true 48 | done 49 | ''; 50 | 51 | meta = with lib; { 52 | description = "XELFViewer"; 53 | homepage = "https://github.com/horsicq/XELFViewer"; 54 | license = licenses.mit; 55 | maintainers = with maintainers; [ xieby1 ]; 56 | platforms = [ "x86_64-linux" ]; 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /usr/modules/cachix.nix: -------------------------------------------------------------------------------- 1 | { config, lib, ...}: 2 | 3 | { 4 | imports = [../../modules/cachix.nix]; 5 | config = lib.mkIf ( 6 | (builtins.pathExists config.cachix_dhall) && 7 | (config.cachix_packages != []) 8 | ) { 9 | home.activation.cachix_push = lib.hm.dag.entryAfter ["writeBoundary"] config._cachix_push; 10 | }; 11 | } 12 | --------------------------------------------------------------------------------