Nixos入门建议|一天入门nixos|一篇文章从入门到高手

nixos的优点不用多说了,除了入门难基本没有缺点。

看过很多人入门nixos都是浅尝辄止,或者很快就遇到坑放弃,或走入误区。有人甚至反复入门多次,最后还是放弃。询问数人后,明白了这部分人无法入门nixos的关键的问题:路走错了。

所以这里整理了一个让你一天入门nixos的方法,

并在文末提供了从基础到进阶的nixos的几乎方方面面的配置范例,只要你本来就熟悉linux,有一丢丢编程基础可以就可以快速入门。

使用nixos的条件

你本身需要熟悉Linux ,了解你自己的日用软件的配置方式,有一些修改dotfile的经验。最起码能搞定常见linux问题,能做到在常规linux发行版,完成环境搭建 开发 部署 日用桌面环境 等常见场景。 会一丢丢编程语言,并且愿意学虽然很简单但是有一些蛋疼的nix语言。nixos对科研上网环境有要求。

用过常用的linux发行版,目前有能力把linux桌面当作主力系统 很少需要使用win/macos ,有一点程序员技能。有稳定的科研上网环境。

安装

安装方式

如果你没有如 archlinux手动安装 或 其他类似rootfs安装系统的经验,建议你直接 用 nixos的gnome live盘来默认安装。当然你要在路由/网关上配置好那个啥的代理(全局),或者其他方式。

如果你搞不定安装过程的代理,那就只能用用nixos-install。 https://wiki.nixos.org/wiki/NixOS_Installation_Guide/zh 这里有详细的中文说明,网上也很多其他说明。

在同局域网的手机开科研软件,然后安装过程中的电脑走手机代理也是可行的。

如果你还是搞不定,可能需要补充一下Linux或科研上网的基础知识。

渐进式

这是最重要的一点!!!不要企图一口吃胖。

nixos新人,最常见的一个错误就是 想在入门第一天就实现全nix托管。甚至完全不了解的情况下直接CLONE别人仓库试图复刻。
你要知道 别人的一个 nixos-config 是一整个系统的配置,甚至是多机器 多环境,覆盖范围很大牵扯的知识点其实很多。 新人切勿全盘抄作业。

我的建议是还是逐步过度,可以善用搜索和ai,但是要自己从0开始配置(也就是 nixos-generate-config 后获得的 hardware-configuration.nix and configuration.nix这两个文件)。

flake home-manager

不建议新手马上用flake和home-manager。新手就用nix-shell -p XXX 以及编辑 configuration.nixenvironment.systemPackages字段 不要搞其他的。

文末有一个 最小化系统flake和home-manager的范例

那么怎么开始使用

先用 nix-shell -p XXX 替代你原来的 apt install xxx

然后试着修改 /etc/nixos/configuration.nix 的 environment.systemPackages

即便开始用home-manager的时候,也不要一开始就把软件配置 programs.xxx = {} 全写到 nix里面,更不要一开始就 用Nix(或者xdg.configfile/home.file)去管理所有配置文件。先手动管理。确定没问题了再逐步用nix托管。

docker 和 flatpak

记住这段代码 先搞docker和flatpak 以及 appimage

 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
42
43
44
45
46
47
48
49
50
51
{
  pkgs,
  ...
}:
{
environment.systemPackages = with pkgs; [
    docker-compose
    x11docker
    nix-prefetch-docker
];
programs.appimage.enable = true;
programs.appimage.binfmt = true;
services.flatpak.enable = true;
virtualisation.docker.enable = true;
  virtualisation.docker.daemon.settings = {
    registry-mirrors = [
      "https://docker.hpcloud.cloud"
      "https://docker.m.daocloud.io"
      "https://docker.unsee.tech"
      "https://docker.1panel.live"
      "http://mirrors.ustc.edu.cn"
      "https://docker.chenby.cn"
      "http://mirror.azure.cn"
      "https://dockerpull.org"
      "https://dockerhub.icu"
      "https://hub.rat.dev"
    ];
    data-root = "/home/XXXX/docker/data-root";
    userland-proxy = false;
    experimental = true;
    ipv6 = true;
    fixed-cidr-v6 = "fd00::/80";
    metrics-addr = "0.0.0.0:9323";
    log-driver = "json-file";
    log-opts.max-size = "10m";
    log-opts.max-file = "10";
  };
# 这是一个用nixos直接管理docker的例子,也可以用docker cli/docker-compose 随意 
virtualisation.oci-containers = {
    backend = "docker"; 
    containers = {
      metacubexd = {
        image = "ghcr.geekery.cn/metacubex/metacubexd:latest";
        ports = [ "80:80" ];
        autoStart = true;
        environment = {
          TZ = "Asia/Shanghai";
        };
      };
  };
};

日用软件有flatpak版但是没有nixpkgs的就先用这,服务类的搞不定的就先用docker跑。 然后慢慢按照必要性慢慢用nixpkgs逐渐接管就好了。

appimage

有极个别的Nixpkg没有包但是有appimage的 那就先。不过appimage打包为nixpkgs也简单,后面需要自己学打包的时候,也可以考虑从appimage开始。

1
2
3
4
{
  programs.appimage.enable = true;
  programs.appimage.binfmt = true;
}

然后 appimage-run /home/XXX/my-opt/XXXX.AppImage

nur

nixpkgs的包足够多,而且自己打包简单。nur在大部分情况下都没必要使用。如果你确实使用,后期可以考虑自己封一个,直接抄nur仓库的对应包的代码就好了。

例如我用的rime-ice和火狐浏览器插件 一开始用的nur后来发现没必要 就手动安装,再后来发现干脆自己封装一个就好。

nixpkgs完全没有的包

能docker的就docker先对付下,实在不行kvm。
还是搞不定的就找ai帮你封装nixpkg,中间的错误反复几次 运气好的话能一次性搞定,自己实在搞不定就去寻求社区帮助。

善用社区帮助

不要那么自负,大家都说nix门槛高 肯定是有难度的。还是慢需要社区帮助的。

github 搜索

不用说了,抄作业必备

电报群

nixos 中文电报群整体环境都比较友好,不会和其他技术社区一样那么多暴躁老哥。只要不是太入门的问题 都会有人解答。 也有 nixos核心团队的人偶尔出没在电报群,nixpkgs贡献者更是经常有人在群里活跃。

礼貌一些,谦虚一些。问题解决后 说一声感谢。

一句话总结

渐进式入门使用nixos,抄作业不要搬作业。

从 最基础的hardware-configuration.nix 和 configuration.nix两个文件 开始,

  • 善用docker flatpak nix-shell -p XXX甚至kvm 能开始使用nixos工作学习,
  • 然后再引入flake.nix,再然后引入homemanager,但是不要马上用nix接管所有配置项。
  • 最后再尝试全nix托管 以及 自己打包nixpkgs没有的软件

最小flake.nix + home-manger 参考

下面代码是有时效性,不要照搬主要代码兼容nixos25.05,新版nixos可能需要有针对性升级修改的地方。

下面代码几乎涵盖了所有nixos入门和进阶甚至毕业的配置实例。从最简单的基础开始。

flake.nix

 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
42
43
44
45
46
47
48
49
50
{
  inputs = {
    #gh.jasonzeng.dev 是github proxy站,我随便搜的,随时会失效,最好换成一下,如果有条件就直连
    nixpkgs.url = "git+https://gh.jasonzeng.dev/https://github.com/NixOS/nixpkgs.git?ref=nixos-25.05";
    nixpkgs-unstable.url = "git+https://gh.jasonzeng.dev/https://github.com/NixOS/nixpkgs.git?ref=nixos-unstable";
    nixpkgs-master.url = "git+https://gh.jasonzeng.dev/https://github.com/NixOS/nixpkgs.git?ref=master"; # 不是特别推荐 使用 master的包
    home-manager.url = "git+https://gh.jasonzeng.dev/https://github.com/nix-community/home-manager.git/?ref=release-25.05";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
  };
  inputs = {
  };
  outputs =
    inputs@{
      nixpkgs,
      nixpkgs-unstable,
      nixpkgs-master,
      home-manager,
      self,
      ...
    }:
    let
      username = "joyanhui";
      system = "x86_64-linux";
    in
    {
      nixosConfigurations = {
        amd = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [
            {
              nixpkgs.overlays = [
                (import ./system-setting/overlays-pkg-unstable.nix inputs)
              ];
            }
            ./amd_configuration.nix # 就是原来的hardware-configuration.nix 和 configuration.nix
          ];
          specialArgs = {
            host = "thinkbook";
            inherit
              self
              inputs
              username
              nixpkgs-unstable
              ;
          };
        };

      };
    };
}

overlays-pkg-unstable.nix

这是一个补丁文件,可以写到flake.nix 里面 也可以单独写到一个nix文件中

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
inputs: final: prev: {
  unstable = import inputs.nixpkgs-unstable {
    system = prev.system;
    config.allowUnfree = true;
    config.allowBroken = true;
  };

  master = import inputs.nixpkgs-master {
    system = prev.system;
    config.allowUnfree = true;
    config.allowBroken = true;
  };
}

amd_configuration.nix 也就是configuration.nix

直接复制 你原来的/etc/nixos/configuration.nix 然后编辑

 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
{ pkgs, ... }:
{
  imports = [
    ./hardware-configuration/hardware-configuration_thinbook_14p_amd.nix # 直接复制你原来的 hardware-configuration.nix 按需改动
    #./某一个服务.nix
    #./某一个配置项.nix
    #./某一个软件包.nix
    #.等等等等......
];
  services.usbmuxd.enable = true;
  services.upower.enable = true;
  services.fstrim.enable = true;
  services.blueman.enable = true;
  programs.appimage.enable = true;
  programs.appimage.binfmt = true;
  # ... 更多 需要的  可以把gnome kde之类的写这里
  environment.systemPackages = with pkgs; [
    coreutils-full
    fastfetch
    dex
    htop
    unzip
    p7zip
    # 更多需要的
  ];
 programs.nix-ld.enable = true;
}

声音.nix

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
  config,
  lib,
  pkgs,
  ...
}:
{
  services.pulseaudio.enable = false;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    jack.enable = true;
  };
}

用户设置.nix

 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
42
43
44
45
{
  pkgs,
  inputs,
  username,
  host,
  ...
}:
{
  imports = [ inputs.home-manager.nixosModules.home-manager ];
  home-manager = {
    backupFileExtension = ".home_manager_backup";
    useUserPackages = true;
    useGlobalPkgs = true;
    extraSpecialArgs = { inherit inputs username host; };
    users.${username} = {
      #imports =[];
      home.username = "${username}";
      home.homeDirectory = "/home/${username}";
      home.stateVersion = "24.05";
      programs.home-manager.enable = true;
    };
  };
  users.mutableUsers = false; # 禁止useradd添加用户
  security.sudo.wheelNeedsPassword = false; # wheel 用户组使用sudo 可以不输入密码
  users.users.${username} = {
    isNormalUser = true;
    description = "${username}";
    extraGroups = [
      "wheel"
      "users"
      "libvirtd" # kvm
      "vboxusers"
      "kvm" # android kvm
      "adbusers" # android adb 需要
      "video" # 调整hyprland下亮度用
      "dialout" # 调试串口设备要用
      "docker"
      "lxc" 
      "plugdev" # usb
      "nginx"
    ];
    shell = pkgs.bash;
  };
  nix.settings.allowed-users = [ "${username}" ];
}

用户安全.nix :非必须

 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
{
  username,
  ...
}:
{
  users.users.${username} = {
    hashedPassword = "XXXXXX";
    openssh.authorizedKeys.keys = [
      "ssh-ed25519XXXXXX"
      "ssh-rsa XXXXXX"
    ];
  };
  users.users.root = {
    hashedPassword = "XXXXXX";
    openssh.authorizedKeys.keys = [
      "ssh-ed25519XXXXXX"
      "ssh-rsa XXXXXX"
    ];
  };
  home-manager = {
    users.${username} = {
      home.file = {
        ".ssh/id_ed25519".text = ''
          -----BEGIN OPENSSH PRIVATE KEY-----
          XXXXX
          -----END OPENSSH PRIVATE KEY-----
        '';
        ".ssh/id_rsa".text = ''
          -----BEGIN OPENSSH PRIVATE KEY-----
          XXXXXX
          -----END OPENSSH PRIVATE KEY-----
        '';
      };
    };
  };
}

某一个软件包例子.nix

网易云音乐:超简单的 home-manager packages

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{
  pkgs,
  username,
  ...
}:
{
  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        netease-cloud-music-gtk
      ];
    };
  };
}

terminator(终端工具).nix 简单管理一个配置文件

home.file是从传统手动管理配置文件或者其他文件 过度到nix管理的最简单的方式了。不过下面的例子按照规范来说应该xdg.configFile.

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
  pkgs,
  username,
  ...
}:
{

  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        terminator
      ];

      home.file.".config/terminator/config" = {
        force = true;
        text = ''
          [global_config]
            enabled_plugins = ActivityWatch, InactivityWatch, CustomCommandsMenu, CurrDirOpen, InsertTermName, Logger, MavenPluginURLHandler, MouseFreeURLHandler, RunCmdOnMatchMenu, SaveLastSessionLayout, SaveUserSessionLayout, TerminalShot, TestPlugin, LaunchpadBugURLHandler, LaunchpadCodeURLHandler, APTURLHandler
          [keybindings]
          [profiles]
            [[default]]
              background_color = "#241f31"
              background_darkness = 0.79
              background_type = transparent
              cursor_fg_color = "#241f31"
              cursor_bg_color = "#ebdbb2"
              font = JetBrainsMono Nerd Font 10
              foreground_color = "#ebdbb2"
              scrollbar_position = hidden
              scrollback_lines = 10000
              use_system_font = False
              title_transmit_bg_color = "#62a0ea"
              title_use_system_font = False
              title_font = JetBrainsMono Nerd Font 9
          [layouts]
            [[default]]
              [[[window0]]]
                type = Window
                parent = ""
                size = 900, 600
              [[[child1]]]
                type = Terminal
                parent = window0
                profile = default
            [[SaveLastSessionLayout]]
          [plugins]


        '';
      };

    };
  };

}

fish和bash以及starship.nix的例子

值得注意的是starship需要字体,但是字体没在这下面代码中管理.

common-aliases.nix别名
 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
{
  # Common shell aliases shared between bash, zsh and fish
  commonAliases = {
    ping = "ping -O";
    killall = "killall -v";
    umount = "umount -v";
    lsblk = "lsblk -a --output 'NAME,LABEL,FSTYPE,SIZE,FSUSE%,RO,TYPE,MOUNTPOINTS'";
    chmod = "chmod -v";
    chown = "chown -v";
    chattr = "chattr -v";
    ln = "ln -v";
    cp = "cp -v";
    mv = "mv -v";
    #    rm = "rm -v";
    mkdir = "mkdir -pv";
    rmdir = "rmdir -v";

    myupdateAMD = "cat /home/y/myworkspace/os-joyanhui/script/myupdateAMD.sh";
    myupdateAMD_with_cd_nix_flake_update = "cat /homeyh/myworkspace/os-joyanhui/script/myupdateAMD_with_cd_nix_flake_update.sh";
    myclean_nixos = "cat /home/y/myworkspace/os-joyanhui/script/myclean.sh";
    myclean_home_manager = "find /home  -name '*home-manager-backup*' -delete ";
    mybackup = "cat /home/y/myworkspace/os-joyanhui/script/mybackup.sh";

    proxySet = "export http_proxy=http://127.0.0.1:7890&&export https_proxy=http://127.0.0.1:7890";
    proxyUnSet = "unset http_proxy&&unset https_proxy";

    scpToX240 = "scp -r /home/y/myworkspace/os-joyanhui/* yh@x240:/home/y/myworkspace/os-joyanhui/";
    # find /path/to/directory -type f -name '*home-manager-backup*' -exec rm -f {} \;
    waybarRestart = "pkill waybar & sleep 0.5 && waybar";

    helix = "hx";
    #npm = "pnpm";
    #nano = "command -v micro &>/dev/null && micro || nano";
    neofetch = "echo fastfetch && fastfetch";
  };
}
starship.nix

都是花里胡哨啦,可以不看内容 注意

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{ pkgs,... }:
{

  environment.systemPackages = with pkgs; [
    noto-fonts-emoji
  ];
  # starship -
  programs.starship = {
    enable = true;
    presets = [
      # "tokyo-night"
      "bracketed-segments"
      "nerd-font-symbols"
    ];
    # custom settings
    /*
      settings = {
        add_newline = false;
        aws.disabled = true;
        gcloud.disabled = true;
        line_break.disabled = true;
      };
    */

    settings = {
      add_newline = false;
      aws.disabled = true;
      gcloud.disabled = true;
      line_break.disabled = true;
      os.symbols.NixOS = "";
      username.format = "\\[[$user]($style)";
      username.show_always = true;
      hostname.format = "[@$hostname$ssh_symbol]($style)\\] ";
      hostname.ssh_symbol = "🌏";
      hostname.ssh_only = false;
      directory.read_only = "🔒";
      directory.truncate_to_repo = false;
      directory.truncation_symbol = "…/";
      character.success_symbol = "[󰜴](bold fg:grey)";
      character.error_symbol = "[󰜴](bold fg:color_red)";
      palette = "catppuccin_mocha";
      palettes.catppuccin_mocha.rosewater = "#f5e0dc";
      palettes.catppuccin_mocha.flamingo = "#f2cdcd";
      palettes.catppuccin_mocha.pink = "#f5c2e7";
      palettes.catppuccin_mocha.mauve = "#cba6f7";
      palettes.catppuccin_mocha.red = "#f38ba8";
      palettes.catppuccin_mocha.maroon = "#eba0ac";
      palettes.catppuccin_mocha.peach = "#fab387";
      palettes.catppuccin_mocha.yellow = "#f9e2af";
      palettes.catppuccin_mocha.green = "#a6e3a1";
      palettes.catppuccin_mocha.teal = "#94e2d5";
      palettes.catppuccin_mocha.sky = "#89dceb";
      palettes.catppuccin_mocha.sapphire = "#74c7ec";
      palettes.catppuccin_mocha.blue = "#89b4fa";
      palettes.catppuccin_mocha.lavender = "#b4befe";
      palettes.catppuccin_mocha.text = "#cdd6f4";
      palettes.catppuccin_mocha.subtext1 = "#bac2de";
      palettes.catppuccin_mocha.subtext0 = "#a6adc8";
      palettes.catppuccin_mocha.overlay2 = "#9399b2";
      palettes.catppuccin_mocha.overlay1 = "#7f849c";
      palettes.catppuccin_mocha.overlay0 = "#6c7086";
      palettes.catppuccin_mocha.surface2 = "#585b70";
      palettes.catppuccin_mocha.surface1 = "#45475a";
      palettes.catppuccin_mocha.surface0 = "#313244";
      palettes.catppuccin_mocha.base = "#1e1e2e";
      palettes.catppuccin_mocha.mantle = "#181825";
      palettes.catppuccin_mocha.crust = "#11111b";
    };
  };
}

bash.nix

在我入门的时候 不会让starship在home-manager中初始化,所以就写了两次包。

 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
42
43
44
45
46
47
48
49
50
51
{
  pkgs,
  username,
  ...
}:
let
  inherit (import ./common-aliases.nix) commonAliases;
in
{
  imports = [
    ./starship.nix
  ];

  programs.bash = {
    completion.enable = true;
    promptInit = ''
      eval "$(${pkgs.starship}/bin/starship init bash)"
    '';
    # 使用共享的别名
    shellAliases = commonAliases // {
      # bash 特有的别名可以在这里添加
      #helix = "hx";
      #neofetch = "echo fastfetch && fastfetch";
    };
  };

  home-manager = {
    users.${username} = {
      programs.bash = {
        enable = true;
        enableCompletion = true;
        historySize = 10000;
        historyFileSize = 10000;
        # TODO 在这里添加你的自定义 bashrc 内容
        bashrcExtra = ''
              # export PATH='$PATH:$HOME/bin:$HOME/.local/bin:$HOME/go/bin'
             #  export NIXPKGS_ALLOW_UNFREE=1
            #   export GOPROXY="https://goproxy.cn,direct"
              # export CGO_CPPFLAGS="-I ${pkgs.opencv}/include"
              # export CGO_LDFLAGS="-L ${pkgs.opencv}/lib"

          fish

        '';

        #  设置一些别名方便使用 不建议,因为home-manager 里面 无法在 shellAliases 之后再启动fish  最简单的方案是直接写到fish中
      };
    };
  };

}
fish.nix
 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
{
  pkgs,
  inputs,
  username,
  ...
}:
let
  inherit (import ./common-aliases.nix) commonAliases;
in
{
  imports = [
    inputs.home-manager.nixosModules.home-manager
    ./starship.nix
  ];

  home-manager = {
    users.${username} = {
      programs.fish = {
        # fish 4.2.x 好像还有点问题,暂时不用  package = pkgs.unstable.fish
        enable = true;
        interactiveShellInit = ''
          eval "$(${pkgs.starship}/bin/starship init fish)"
          #colors
            set fish_color_normal '#98be65'
            set fish_color_autosuggestion '#6272a4'
            set fish_color_command '#98be65'
            set fish_color_error '#ff6c6b'
            set fish_color_param '#98be65'
            # greeting
            set fish_greeting
        '';
        shellAliases = commonAliases // {
          # fish specific aliases
          helix = "hx";
          neofetch = "echo fastfetch && fastfetch";
        };
      };
    };
  };

}

gimp2.nix: 带一个简单小补丁的例子

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  pkgs,
  username,
  ...
}:
{
  home-manager = {
    users.${username} = {
      xdg.configFile."GIMP/2.10" = {
        source =
          pkgs.fetchFromGitHub {
            owner = "Diolinux";
            repo = "PhotoGIMP";
            rev = "photogimp-2.10"; # photogimp-2.10 对应gimp2  master 对应 gimp 3.0
            sha256 = "sha256-tWbkHf0Es/I0oLooep+GIFhFXWgGxanBUUCpzHMzC1I=";
          }
          + "/.var/app/org.gimp.GIMP/config/GIMP/2.10"; # update path when gimp 3.0 is in nixpkgs
      };
      home.packages = with pkgs; [
        gimp # gnu image manipulation program
      ];
    };
  };
}

gimp3.nix 带一个简单小补丁,但是复杂了一丢丢例子

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{
  pkgs,
  username,
  ...
}:
let
  PhotoGIMP = pkgs.stdenvNoCC.mkDerivation {
    pname = "PhotoGIMP";
    version = "2024.12.12";

    src = pkgs.fetchFromGitHub {
      owner = "Diolinux";
      repo = "PhotoGIMP";
      rev = "master";
      sha256 = "sha256-OLEqtI2Hem2fTTL0KNf0aZsFfuwwhgE4etyRMcW5KiQ=";
    };

    installPhase = ''
      mkdir -p $out/share/PhotoGIMP
      cp -r ./.config $out/share/PhotoGIMP
      cp -r ./.local $out/share/PhotoGIMP
      rm -rf $out/share/PhotoGIMP/.config/GIMP/3.0/gimprc  #这个文件在每次启动会被重新创建
    '';

    meta = {
      description = "PhotoGIMP";
      homepage = "https://github.com/Diolinux/PhotoGIMP";
      license = pkgs.lib.licenses.gpl3Only;
      platforms = pkgs.lib.platforms.all;
    };
  };
in
{
  home-manager = {
    users.${username} = {
      # Use home.file instead of xdg.configFile to ensure writable permissions
      # GIMP needs to write to its config directory
      home.file = {
        # GIMP 3.0 configuration directory - copy with proper permissions
        ".config/GIMP/3.0" = {
          source = "${PhotoGIMP}/share/PhotoGIMP/.config/GIMP/3.0";
          recursive = true;
          # Ensure the directory is writable for GIMP
          onChange = ''
            chmod -R u+w ~/.config/GIMP/3.0
          '';
        };
        # .local/share applications - only overlay the PhotoGIMP desktop file
        ".local/share/applications/org.gimp.GIMP.desktop" = {
          source = "${PhotoGIMP}/share/PhotoGIMP/.local/share/applications/org.gimp.GIMP.desktop";
        };
        # .local/share icons - only overlay PhotoGIMP specific icon files
        # This avoids overwriting other applications' icons in the hicolor theme
        ".local/share/icons/hicolor/16x16/apps/photogimp.png" = {
          source = "${PhotoGIMP}/share/PhotoGIMP/.local/share/icons/hicolor/16x16/apps/photogimp.png";
        };
        ".local/share/icons/hicolor/32x32/apps/photogimp.png" = {
          source = "${PhotoGIMP}/share/PhotoGIMP/.local/share/icons/hicolor/32x32/apps/photogimp.png";
        };
        ".local/share/icons/hicolor/48x48/apps/photogimp.png" = {
          source = "${PhotoGIMP}/share/PhotoGIMP/.local/share/icons/hicolor/48x48/apps/photogimp.png";
        };
        ".local/share/icons/hicolor/64x64/apps/photogimp.png" = {
          source = "${PhotoGIMP}/share/PhotoGIMP/.local/share/icons/hicolor/64x64/apps/photogimp.png";
        };
        ".local/share/icons/hicolor/128x128/apps/photogimp.png" = {
          source = "${PhotoGIMP}/share/PhotoGIMP/.local/share/icons/hicolor/128x128/apps/photogimp.png";
        };
        ".local/share/icons/hicolor/256x256/apps/photogimp.png" = {
          source = "${PhotoGIMP}/share/PhotoGIMP/.local/share/icons/hicolor/256x256/apps/photogimp.png";
        };
        ".local/share/icons/hicolor/512x512/apps/photogimp.png" = {
          source = "${PhotoGIMP}/share/PhotoGIMP/.local/share/icons/hicolor/512x512/apps/photogimp.png";
        };
      };
      home.packages = with pkgs; [
        gimp3
      ];
    };
  };
}

git.nix: 混合 programs.XX和 home.packages

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
  pkgs,
  username,
  ...
}:
{
  home-manager = {
    users.${username} = {
      programs.git = {
        enable = true;
        userName = "joyanhui";
        userEmail = "[email protected]";
      };
      home.packages = with pkgs; [
        gh
        github-runner
        gitea-actions-runner
      ];

    };
  };
}

brave.nix:又一个混合 programs.XX和 home.packages

 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
42
43
44
{
  pkgs,
  username,
  ...
}:
{

  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        keepassxc # 还需要浏览器插件 和app 比较麻烦
        bitwarden-desktop # 插件变成几十m 而且卡 所以弃用
        (makeDesktopItem {
          name = "brave-private";
          desktopName = "Brave Web Browser";
          genericName = "Open a private Brave window";
          icon = "brave";
          exec = "${brave}/bin/brave --incognito";
          categories = [ "Network" ];
        })

      ];
      programs.brave = {
        enable = true;
        package = pkgs.brave;
        extensions = [
          { id = "cjpalhdlnbpafiamejdnhcphjbkeiagm"; } # ublock
          { id = "nngceckbapebfimnlniiiahkandclblb"; } # Bitwarden
          { id = "fnaicdffflnofjppbagibeoednhnbjhg"; } # floccus bookmarks sync
          { id = "jlgkpaicikihijadgifklkbpdajbkhjo"; } # CrxMouse
          { id = "eimadpbcbfnmbkopoojfekhnkhdbieeh"; } # Dark Reader
          { id = "jdocbkpgdakpekjlhemmfcncgdjeiika"; } # 去掉右键 限制
          { id = "bggfcpfjbdkhfhfmkjpbhnkhnpjjeomc"; } # Material icons for github  文件列表图标
        ];
        commandLineArgs = [
          "--password-store=basic" # 不使用 密钥环
        ];

      };

    };
  };

}

firefox.nix 一个啰唆但是个性的配置

这是我目前在用的完整配置,完美超爽,并且带旧版的注释

  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
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
{
  pkgs,
  username,
  ...
}:
{

  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        bitwarden-desktop
      ];
      programs.firefox = {
        # package = pkgs.unstable.librewolf;
        # package = pkgs.firefox-bin;
        enable = true;
        # nativeMessagingHosts.packages = [ pkgs.firefoxpwa ];
        policies = {
          DisablePocket = true;
          DisplayBookmarksToolbar = true;
          DontCheckDefaultBrowser = true;
          OfferToSaveLogins = false;
          NoDefaultBookmarks = true;
          PasswordManagerEnable = false; # Unknown policy: PasswordManagerEnable禁用 自带的密码管理 和bitwarden冲突
          #DNSOverHTTPS = {
          #  Enabled = true;
          #};
          InstallAddonsPermission.Default = true;
          # bitwarden floccus gesturefy firefox-color user-agent-string-switcher
          ExtensionSettings = {
            # "[email protected]" = {
            #   install_url = "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi";
            #   installation_mode = "force_installed";
            # };
            "[email protected]" = {
              #install_url = "https://addons.mozilla.org/firefox/downloads/latest/floccus/latest.xpi";
              install_url = "https://addons.mozilla.org/firefox/downloads/file/4620792/floccus-5.8.0.xpi";
              installation_mode = "force_installed";
            };
            "{446900e4-71c2-419f-a6a7-df9c091e268b}" = {
              #install_url = "https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/latest.xpi";
              install_url = "https://addons.mozilla.org/firefox/downloads/file/4619294/bitwarden_password_manager-2025.11.0.xpi";
              installation_mode = "force_installed";
            };
            "[email protected]" = {
              # 跳过 youtube
              install_url = "https://addons.mozilla.org/firefox/downloads/file/4608179/sponsorblock-6.1.0.xpi";
              installation_mode = "force_installed";
            };
          };
          #Extensions = {
          #  Install = [
          #    "https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/"
          #    "https://addons.mozilla.org/firefox/downloads/latest/screenshot-capture-annotate/"
          #    "https://addons.mozilla.org/firefox/downloads/latest/sponsorblock/"
          #    "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/"
          #  ];
          #};
        };
        profiles.y = {
          id = 0;
          isDefault = true;
          name = "y";
          settings = {
            "browser.search.separatePrivateDefault" = false;
            "browser.search.separatePrivateDefault.ui.enabled" = true;
            #"browser.startup.homepage" = "http://dashboard.internal.flake.sh/";
            "network.trr.mode" = 5;
            "dom.security.https_first" = true;
            #"dom.security.https_only_mode" = true;
            #"dom.security.https_only_mode_ever_enabled" = true;
            "toolkit.legacyUserProfileCustomizations.stylesheets" = true;

            # Disable caching requests to disk; enable and expand in-memory caching.
            "browser.cache.memory.enable" = true;
            "browser.cache.memory.capacity" = -1; # Unlimited
            "browser.cache.memory.max_entry_size" = 51200;
            "browser.cache.disk.enable" = false;

            # catppuccin background color
            "browser.display.background_color.dark" = "#1e1e2e";
            "browser.discovery.enabled" = false;
            "browser.startup.homepage" = "about:blank";
            "general.smoothScroll" = true;
            "signon.autofillForms" = false;
            "widget.non-native-theme.scrollbar.style" = 3;
            "browser.uidensity" = 0;
            "browser.compactmode.show" = true;
            "breakpad.reportURL" = "";
            "browser.urlbar.trimHttps" = true;
            "browser.urlbar.trimURLs" = true;
            "browser.urlbar.suggest.calculator" = true;
            # do not recommend extensions
            "extensions.htmlaboutaddons.recommendations.enabled" = false;
            "extensions.getAddons.showPane" = false;
            "extensions.postDownloadThirdPartyPrompt" = false;
            "browser.preferences.moreFromMozilla" = false;
            "browser.tabs.tabmanager.enabled" = false;

            # enable tab groups
            "browser.tabs.groups.enable" = true;
            "browser.tabs.groups.smart.enabled" = true;
            "extensions.pocket.enable" = false;
            # sidebar with vertical tabs
            # "sidebar.visibility" = "expand-on-hover"; #"always-show";
            "sidebar.visibility" = "always-show";
            "sidebar.main.tools" = "aichat,history,bookmarks";
            "sidebar.expandOnHover" = true;
            "sidebar.verticalTabs" = true;
            "browser.toolbars.bookmarks.visibility" = "always";

            # disable welcome page when launching firefox for the first time
            "browser.aboutwelcome.enabled" = false;
            # disable address auto fill
            "extensions.formautofill.addresses.enabled" = false;
            # makes firefox faster in sway
            # https://www.reddit.com/r/swaywm/comments/1iuqclq/firefox_is_now_way_more_efficient_under_sway_it/
            "gfx.webrenderer.compositor.force-enabled" = true;
            # disable "caret"
            "accessibility.browsewithcaret.enabled" = false;
            "accessibility.browsewithcaret_shortcut.enabled" = false;

          };
          # userChrome = builtins.readFile ../../../static_file/firefox/userChrome.css;
          #extraConfig = builtins.readFile ./user.js/betterfox.js;
          search = {
            default = "cnbing";
            force = true;
            engines = {
              "cnbing" = {
                urls = [
                  {
                    template = "https://cn.bing.com";
                    params = [
                      {
                        name = "q";
                        value = "{searchTerms}";
                      }
                    ];
                  }
                ];
                definedAliases = [
                  "@c"
                  "@b"
                  "@bing"
                ];
              };
              "SearXNG xlei.eu.org" = {
                urls = [
                  {
                    template = "https://opnxng.com/";
                    #template = "https://s.xxxxxx.eu.org/";
                    params = [
                      {
                        name = "q";
                        value = "{searchTerms}";
                      }
                    ];
                  }
                ];
                icon = "https://s.xxxx.eu.org/static/themes/simple/img/favicon.png";
                definedAliases = [
                  "@sx"
                  "@xl"
                ];
              };
              "Nix Packages" = {
                urls = [
                  {
                    template = "https://search.nixos.org/packages";
                    params = [
                      {
                        name = "type";
                        value = "packages";
                      }
                      {
                        name = "query";
                        value = "{searchTerms}";
                      }
                    ];
                  }
                ];
                #icon = "''${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
                icon = "https://search.nixos.org/favicon.ico";
                definedAliases = [
                  "@np"
                  "@nix"
                  "@nixos"
                ];
              };
              "github" = {
                urls = [
                  {
                    template = "https://github.com/search";
                    params = [
                      {
                        name = "q";
                        value = "{searchTerms}";
                      }
                    ];
                  }
                ];
                icon = "https://github.com/favicon.ico";
                definedAliases = [
                  "@git"
                  "@gh"
                  "@github"
                ];
              };
              #"bing".metaData.hidden = true;
              #"google".metaData.hidden = true;
              "google".metaData.alias = "@g";
              "amazondotcom-us".metaData.hidden = true;
              "ebay".metaData.hidden = true;
              "ddg".metaData.hidden = false;
            };

          };

          #  extensions = with pkgs.nur.repos.rycee.firefox-addons; [
          #    # https://nur.nix-community.org/repos/rycee/
          #    bitwarden
          #    floccus
          #    gesturefy
          #    firefox-color
          #    user-agent-string-switcher
          #  ];

        };
      };

    };
  };

}

fcitx5-rime.nix 带词库和打包实例的

  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
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
{ pkgs, username, ... }:

let
  rime-ice = pkgs.stdenvNoCC.mkDerivation {
    pname = "rime-ice";
    version = "2024.12.12";

    src = pkgs.fetchFromGitHub {
      owner = "iDvel";
      repo = "rime-ice";
      rev = "2024.12.12";
      hash = "sha256-2QZdlLGZwWIesbjYTE/2yhM1hHGVVp7jR02bR0oqxV0=";
    };

    installPhase = ''
      mkdir -p $out/share/rime-data
      rm -rf ./others
      rm -f README.md LICENSE
      rm -rf ./.github
      rm squirrel.yaml weasel.yaml
      rm default.yaml custom_phrase.txt # 这两个要自定义 所这里删除,后面会用 home-manager 管理这两个文件
      cp -r ./* $out/share/rime-data
    '';

    meta = {
      description = "Rime 配置:雾凇拼音 | 长期维护的简体词库";
      homepage = "https://github.com/iDvel/rime-ice";
      license = pkgs.lib.licenses.gpl3Only;
      platforms = pkgs.lib.platforms.all;
    };
  };
in
{
  home-manager.users.${username} = {
    # 手动写入 fcitx5 配置文件
    xdg.configFile = {
      "fcitx5/conf/chttrans.conf" = {
        force = true;
        text = ''
          [Global]
          Engine=OpenCC
          OpenCCS2TProfile=default
          OpenCCT2SProfile=default

          [Hotkey]
          # 简体繁体切换快捷键 默认的F 和zed等编辑器冲突
          0=ControlL+Shift+Alt+L
        '';
      };
    };
    # ~/.local/share/fcitx5/rime/
    home.file = {
      # 复制 rime-ice 配置文件到用户 rime 目录
      ".local/share/fcitx5/rime" = {
        source = "${rime-ice}/share/rime-data";
        recursive = true;
        # 确保文件被复制而不是链接,并设置正确权限。为什么这样做不知道呢
        onChange = ''
          mkdir -p ~/.local/share/fcitx5/rime
          chmod -R u+w ~/.local/share/fcitx5/rime
          rm -f ~/.local/share/fcitx5/rime/*.bin
          rm -f ~/.local/share/fcitx5/rime/build/*
        '';
      };

      # 使用自定义的 default.yaml 覆盖。其实也可以在installPhase里面用sed编辑 具体参考rime说明
      ".local/share/fcitx5/rime/default.yaml" = {
        source = ./rime/default.yaml;
        force = true;
      };

      # 自定义短语 比较隐私了  参考  https://github.com/iDvel/rime-ice/blob/main/custom_phrase.txt
      ".local/share/fcitx5/rime/custom_phrase.txt" = {
        force = true;
        source = ././Security/file/fcitx5_rime_custom_phrase.txt # Security目录可以用来专门储存隐私文件
    };
  };

  i18n = {
    inputMethod = {
      type = "fcitx5";
      enable = true;
      fcitx5 = {
        waylandFrontend = true;
        plasma6Support = true;
        addons = with pkgs; [
          fcitx5-configtool
          fcitx5-gtk
          libsForQt5.fcitx5-qt
          kdePackages.fcitx5-qt
          fcitx5-fluent
          libime
          librime-lua # 雾凇拼音需要
          fcitx5-rime
          rime-ice
        ];
        settings = {
          # 插件配置
          addons = {
            # 主题配置
            classicui.globalSection = {
              Theme = "FluentLight-solid";
              DarkTheme = "FluentLight-solid";
            };
          };
          # 输入法配置
          inputMethod = {
            "Groups/0" = {
              Name = "Default";
              "Default Layout" = "us";
              DefaultIM = "rime";
            };
            "Groups/0/Items/0" = {
              Name = "rime";
            };
            GroupOrder = {
              "0" = "Default";
            };
          };
        };
      };
    };
  };
}

fcitx5-pinyin.nix 较简单

比rime当然简单太多了,但是也没那么爽了。

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{
  pkgs,
  username,
  ...
}:
{
  home-manager.users.${username} = {
    # 手动写入 fcitx5 配置文件
    xdg.configFile = {
      "fcitx5/conf/chttrans.conf" = {
        force = true;
        text = ''
          [Global]
          Engine=OpenCC
          OpenCCS2TProfile=default
          OpenCCT2SProfile=default

          [Hotkey]
          # 简体繁体切换快捷键 默认的F 和zed等编辑器冲突
          0=ControlL+Shift+Alt+L
        '';
      };
    };
  };
  i18n = {
    inputMethod = {
      type = "fcitx5";
      enable = true;
      fcitx5 = {
        waylandFrontend = true;
        plasma6Support = true;
        addons = with pkgs; [
          fcitx5-chinese-addons
          fcitx5-configtool
          fcitx5-pinyin-zhwiki
          fcitx5-gtk
          libsForQt5.fcitx5-qt
          kdePackages.fcitx5-qt
          fcitx5-fluent
          libime
        ];
        settings = {
          # 插件配置
          addons = {
            # 主题配置
            classicui.globalSection = {
              Theme = "FluentLight-solid";
              DarkTheme = "FluentLight-solid";
            };
            # 拼音配置
            pinyin.globalSection = {
              PageSize = 9;
              CloudPinyinEnabled = "True";
              CloudPinyinIndex = 2;
            };
            # 云拼音配置
            cloudpinyin.globalSection = {
              Backend = "Baidu";
            };
          };
          # 输入法配置
          inputMethod = {
            "Groups/0" = {
              Name = "Default";
              "Default Layout" = "us";
              DefaultIM = "keyboard-us";
            };
            "Groups/0/Items/0" = {
              Name = "keyboard-us";
            };
            "Groups/0/Items/1" = {
              Name = "pinyin";
            };
            GroupOrder = {
              "0" = "Default";
            };
          };
        };
      };
    };
  };
}

fcitx5-sessionVariables.nix

实际上在gnome/kde下不写也可以,但是在wayfire这种fcitx5不友好的环境下还有大量工作要做。

 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
# https://www.fcitx.cn/post/using_fcitx5_on_wayland/
{
  pkgs,
  username,
  ...
}:
{
  home-manager = {
    # gsettings set org.gnome.settings-daemon.plugins.xsettings overrides "{'Gtk/IMModule':<'fcitx'>}"
    users.${username} = {
      home.sessionVariables = {
        XMODIFIERS = "@im=fcitx"; # X11或XWayland窗口需要
        QT_IM_MODULE = "fcitx";
        QT_IM_MODULES = "fcitx;ibus;wayland"; # Qt窗口需要
        # 切记不要 GTK_IM_MODULE=fcitx,这会把wayland的fcitx5设置覆盖为x11模式
      };
      gtk = {
        enable = true;
        gtk2.extraConfig = ''
          gtk-im-module="fcitx"
        '';
        gtk3.extraConfig = {
          gtk-application-prefer-dark-theme = true;
          "gtk-decoration-layout" = "appmenu:";
          "gtk-im-module" = "fcitx";
        };
        gtk4.extraConfig = {
          "gtk-im-module" = "fcitx";
        };
      };
    };
  };
}

autofs.nix 服务类的

只是一个例子

 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
{ pkgs, ... }:
{
  environment.systemPackages = with pkgs; [
    dosfstools
    exfat
    nfs-utils
    btrfs-progs
    btrfs-snap
    ntfs3g
    davfs2
    fuse3
  ];

  # 自动挂载到  /autofs/子目录
  services.autofs = {
    enable = true;
    autoMaster =
      let
        mapConf = pkgs.writeText "autofs.mnt" ''
          ExFAT -fstype=exfat,uid=1000,gid=1000,umask=022,dmask=022,fmask=133 :/dev/disk/by-label/ExFAT
          NTFS -fstype=ntfs3,uid=1000,gid=1000,umask=022,dmask=022,fmask=133 :/dev/disk/by-label/NTFS
        '';
      in
      ''
        /mnt_auto/autofs ${mapConf} --timeout 35
      '';
  };
}

kvm.nix 服务类

其实也可以写一个服务类的vm。 强烈建议用kvm哦,尽量不要VMware/virtulbox(vmware的macos hack维护有点滞后,vbox patch后国内源经常没有二进制包要要源码编译浪费时间)

 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
{
  pkgs,
  ...
}:
{
  virtualisation.libvirtd = {
    enable = true;
    qemu = {
      package = pkgs.qemu_kvm;
      runAsRoot = true;
      swtpm.enable = true;
      ovmf = {
        enable = true;
        #packages = [(pkgs.OVMF.override {
        #  secureBoot = true;
        #  tpmSupport = true;
        #}).fd];
        packages = [
          pkgs.OVMFFull.fd
        ];
      };
    };
  };
  environment.systemPackages = with pkgs; [
    virt-manager
    swtpm
  ];
}

samba.nix 服务类

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
{
  pkgs,
  ...
}:
# sudo smbpasswd -a my_user
{
  services.samba = {
    enable = true;
    openFirewall = true;
    package = pkgs.sambaFull; # Printer sharing

    settings = {
      global = {
        "invalid users" = [
          "root"
        ];
        "passwd program" = "/run/wrappers/bin/passwd %u";
        security = "user";
      };
      public = {
        browseable = "yes";
        comment = "Public samba share.";
        "guest ok" = "yes";
        path = "/srv/public";
        "read only" = "yes";
      };
      mnt_auto = {
        path = "/mnt_auto";
        "create mask" = 644;
        "directory mask" = 755;
        available = "yes";
        writeable = "yes";
        security = "share";
        browseable = "yes";
        "guest ok " = "no";
      };
      home = {
        path = "/home";
        "create mask" = 644;
        "directory mask" = 755;
        available = "yes";
        writeable = "yes";
        security = "share";
        browseable = "yes";
        "guest ok " = "no";
      };
    };
  };

  services.samba-wsdd = {
    enable = true;
    openFirewall = true;
  };
}

database_manager.nix 简易自定义nixpkgs包

 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
42
43
44
45
46
47
48
49
50
51
52
53
{
  pkgs,
  username,
  ...
}:
let
  another-redis-desktop-manager = pkgs.appimageTools.wrapType2 {
    pname = "another-redis-desktop-manager";
    version = "1.7.1";

    src = pkgs.fetchurl {
      url = "https://gh.leiyanhui.com/https://github.com/qishibo/AnotherRedisDesktopManager/releases/download/v1.7.1/Another-Redis-Desktop-Manager-linux-1.7.1-x86_64.AppImage";
      hash =
        {
          x86_64-linux = "sha256-XuS4jsbhUproYUE2tncT43R6ErYB9WTg6d7s16OOxFQ=";
        }
        .${pkgs.stdenv.hostPlatform.system};
    };

    meta = with pkgs.lib; {
      description = "Faster, better and more stable redis desktop manager";
      homepage = "https://github.com/qishibo/AnotherRedisDesktopManager";
      license = licenses.mit;
      platforms = platforms.linux;
      mainProgram = "another-redis-desktop-manager";
    };
    extraPkgs = pkgs: with pkgs; [ xorg.libxshmfence ];
  };
in
{
  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        dbeaver-bin
        #redisinsight
        another-redis-desktop-manager
      ];
      home.file = {
        ".local/share/applications/another-redis-desktop-manager.desktop".text = ''
          [Desktop Entry]
          Name=Another Redis Desktop Manager
          Exec=another-redis-desktop-manager
          Terminal=false
          Type=Application
          Icon=/home/y/myworkspace/os-joyanhui/static_file/icons/another-redis-desktop-manager.png
          StartupWMClass=Another Redis Desktop Manager
          Comment=A faster, better and more stable redis desktop manager.
          Categories=Utility;
        '';
      };
    };
  };
}

freedownloadmanager.nix 略复杂的自定义nixpkgs包

这个复杂一些,演示代码分到两个nix包 第二个nix文件实际是一个完整的nixpkgs甚至可以规范一下后pr到官方仓库申请合并。

DownloadManager.nix

 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
{
  pkgs,
  username,
  ...
}:

let
  freedownloadmanager = import ./freedownloadmanager.nix {
    inherit (pkgs)
      lib
      stdenv
      fetchurl
      dpkg
      wrapGAppsHook
      autoPatchelfHook
      udev
      libdrm
      libpqxx
      unixODBC
      gst_all_1
      xorg
      libpulseaudio
      mysql80
      ;
  };
in
{
  # https://github.com/kreutzi/nix-FDM
  home-manager = {
    users.${username} = {
      # Xtreme(停止更新了)  文件蜈蚣  Free Download Manager(不能嗅探)
      home.packages = [
        freedownloadmanager
      ];
    };
  };
}

freedownloadmanager.nix

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{
  lib,
  stdenv,
  fetchurl,
  dpkg,
  wrapGAppsHook,
  autoPatchelfHook,
  udev,
  libdrm,
  libpqxx,
  unixODBC,
  gst_all_1,
  xorg,
  libpulseaudio,
  mysql80,
}:

stdenv.mkDerivation rec {
  pname = "freedownloadmanager";
  version = "6.21.0.5639";

  src = fetchurl {
    url = "https://files2.freedownloadmanager.org/6/latest/freedownloadmanager.deb";
    hash = "sha256-rvntnE6dNRyw4KVY+oKG1pvn1tGfk0u6btWEyV3dBTU=";
    #curlOpts = "--proxy http://127.0.0.1:7890";
  };

  unpackPhase = "dpkg-deb -x $src .";

  nativeBuildInputs = [
    dpkg
    wrapGAppsHook
    autoPatchelfHook
  ];

  buildInputs = [
    libdrm
    libpqxx
    unixODBC
    stdenv.cc.cc
    mysql80
  ]
  ++ (with gst_all_1; [
    gstreamer
    gst-libav
    gst-plugins-base
    gst-plugins-good
    gst-plugins-bad
    gst-plugins-ugly
  ])
  ++ (with xorg; [
    xcbutilwm # libxcb-icccm.so.4
    xcbutilimage # libxcb-image.so.0
    xcbutilkeysyms # libxcb-keysyms.so.1
    xcbutilrenderutil # libxcb-render-util.so.0
    libpulseaudio
  ]);

  runtimeDependencies = [
    (lib.getLib udev)
  ];

  installPhase = ''
    mkdir -p $out/bin
    cp -r opt/freedownloadmanager $out
    cp -r usr/share $out
    ln -s $out/freedownloadmanager/fdm $out/bin/${pname}

    substituteInPlace $out/share/applications/freedownloadmanager.desktop \
      --replace 'Exec=/opt/freedownloadmanager/fdm' 'Exec=${pname}' \
      --replace "Icon=/opt/freedownloadmanager/icon.png" "Icon=$out/freedownloadmanager/icon.png"
  '';

  meta = with lib; {
    description = "A smart and fast internet download manager";
    homepage = "https://www.freedownloadmanager.org";
    license = licenses.unfree;
    platforms = [ "x86_64-linux" ];
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    maintainers = with maintainers; [ ];
  };
}

font-i8n.nix

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
  pkgs,
  username,
  ...
}:
{

  i18n = {
    defaultLocale = "en_US.UTF-8";
    supportedLocales = [
      "en_US.UTF-8/UTF-8"
      "zh_CN.UTF-8/UTF-8"
    ];
  };

  fonts = {
    packages = with pkgs; [
      # icon fonts
      material-design-icons
      font-awesome
      lxgw-wenkai # 霞鹜文楷
      # Noto 系列字体是 Google 主导的,名字的含义是「没有豆腐」(no tofu),因为缺字时显示的方框或者方框被叫作 tofu
      # Noto 系列字族名只支持英文,命名规则是 Noto + Sans 或 Serif + 文字名称。
      # 其中汉字部分叫 Noto Sans/Serif CJK SC/TC/HK/JP/KR,最后一个词是地区变种。
      noto-fonts # 大部分文字的常见样式,不包含汉字
      noto-fonts-cjk-sans # 汉字部分
      noto-fonts-emoji # 彩色的表情符号字体
      # noto-fonts-extra # 提供额外的字重和宽度变种
      wqy_microhei
      wqy_zenhei
      # 思源系列字体是 Adobe 主导的。其中汉字部分被称为「思源黑体」和「思源宋体」,是由 Adobe + Google 共同开发的
      source-sans # 无衬线字体,不含汉字。字族名叫 Source Sans 3 和 Source Sans Pro,以及带字重的变体,加上 Source Sans 3 VF
      source-serif # 衬线字体,不含汉字。字族名叫 Source Code Pro,以及带字重的变体
      source-han-sans # 思源黑体
      source-han-serif # 思源宋体

      sarasa-gothic # 更纱黑体 100%缩放比例下渲染效果的最好,中文和英文2:1严格对齐的

    ];
    fontDir.enable = true; # ln -s /run/current-system/sw/share/X11/fonts ~/.local/share/fonts
    enableDefaultPackages = true;
    fontconfig = {
      enable = true;
      defaultFonts = {
        serif = [
          "Source Han Serif SC"
          "Source Han Serif TC"
          "Noto Color Emoji"
        ];
        sansSerif = [
          "Source Han Sans SC"
          "Source Han Sans TC"
          "Noto Color Emoji"
        ];
        monospace = [
          "JetBrainsMono Nerd Font"
          "Noto Color Emoji"
#          "Hack Nerd Font" "emoji" "JuliaMono" "DejaVu Sans Mono"
        ];
        emoji = [ "Noto Color Emoji"];
      };
    };
  };

  home-manager = {
    users.${username} = {
      home.file.".local/share/fonts" = {
        recursive = true;
        source = ../static_file/fonts;
      };
    };
  };

}

简易c/cpp/zig开发环境

c/cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
{
  pkgs,
  username,
  ...
}:
{

  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        gcc
        gdb
        gnumake
      ];
      home.sessionVariables = {
      };
    };
  };

}

zig

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
  pkgs,
  username,
  ...
}:
{

  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        #zls
        #zig
        unstable.zls
        unstable.zig
      ];
      home.sessionVariables = {
      };
      home.sessionPath = [
      ];
    };
  };

}

简易golang开发环境

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  pkgs,
  username,
  ...
}:
{

  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        #    jetbrains.goland
        go
        gopls
        upx
        gcc
      ];
      home.sessionVariables = {
        GOPROXY = "https://goproxy.cn,direct";
      };

    };
  };

}

简易nodejs开发环境

 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
{
  pkgs,
  username,
  ...
}:
{

  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        # nodejs_22
        pnpm
        bun
        #deno
      ];
      home.file.".local/share/pnpm/.keep".text = "";
      home.file.".local/share/pnpm/bin/.keep".text = "";
      home.file.".pnpm-store/.keep".text = "";
      home.sessionVariables = {
        PNPM_HOME = "/home/y/.local/share/pnpm";
      };

      home.file.".npmrc".text = ''
        registry=https://registry.npmmirror.com/
        global-bin-dir=/home/y/.local/share/pnpm/bin
        store-dir=/home/y/.pnpm-store
        # 或使用官方源
        # registry=https://registry.npmjs.org/
      '';
    };
  };

}

简易rust开发环境

 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
42

{
  pkgs,
  username,
  ...
}:
{

  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        rustup
        rustc
        gcc
        openssl_3
        cfssl
        pkg-config
        ninja
        upx
        cmake
        glibc
        lsof
        tree
        duckdb
      ];
      home.sessionVariables = {
        RUSTUP_HOME = "$HOME/.rustup";
        CARGO_HOME = "$HOME/.cargo";
        RUSTUP_DIST_SERVER = "https://rsproxy.cn";
        RUSTUP_UPDATE_ROOT = "https://rsproxy.cn/rustup";
        OPENSSL_DIR = "${pkgs.openssl_3.dev}";
        OPENSSL_LIB_DIR = "${pkgs.openssl_3.out}/lib";
        OPENSSL_INCLUDE_DIR = "${pkgs.openssl_3.dev}/include";
        # PKG_CONFIG_PATH = "${pkgs.openssl_3.dev}/lib/pkgconfig";
        #   sqlx 用的
        # DATABASE_URL = "postgresql://admin:[email protected]:5432/db001";
      };

    };
  };

}

flutter开发环境 略复杂

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
  pkgs,
  username,
  ...
}:
{
  environment.systemPackages = with pkgs; [
    gcc
    clang_19 # 这个版本需要和flutter 对应
    cmake
  ];
  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        #flutter327
        flutter332
        #        unstable.flutter # 3.29.2-sdk-links 2025 04 04
        jdk17
        android-tools # adb fastboot ...
        pciutils # lspic
        usbutils # lsusb
        # Browser
        #chromium
        # Code hygiene
        gitlint
        jq # Code hygiene
        ripgrep # General utilities
        # Flutter dependencies for linux desktop
        atk
        cairo
        libepoxy
        gdk-pixbuf
        glib
        glibc
        gtk3
        harfbuzz
        ninja
        pango
        pcre
        pkg-config
        xorg.libX11
        xorg.libX11.dev
        #xorg.xorgproto

      ];
      home.sessionVariables = {
        D_LIBRARY_PATH =
          with pkgs;
          lib.makeLibraryPath [
            atk
            cairo
            libepoxy
            gdk-pixbuf
            glib
            gtk3
            harfbuzz
            pango
          ];
        #CHROME_EXECUTABLE = "${pkgs.chromium}/bin/chromium";
        # flatpak info  org.chromium.Chromium
        #CHROME_EXECUTABLE = "/home/${username}/.local/share/flatpak/app/org.chromium.Chromium/current/active/files/bin/chromium";
        CHROME_EXECUTABLE = "${pkgs.brave}/bin/brave";
        ANDROID_HOME = "/home/${username}/android_flutter/android-sdk";
        ANDROID_SDK_ROOT = "/home/${username}/android_flutter/android-sdk";
        # MY_ANDROID_STUDIO_DIR = "${pkgs.android-studio}";
        MY_ANDROID_STUDIO_DIR = "/home/${username}/.local/share/JetBrains/Toolbox/apps/android-studio";
        JAVA_HOME = "${pkgs.jdk17}";
        # Fix an issue with Flutter using an older version of aapt2, which does not know
        # an used parameter.
        GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=/home/${username}/android_flutter/android-sdk/build-tools/34.0.0/aapt2";
        #GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=$ANDROID_SDK_ROOT/build-tools/34.0.0/aapt2";
        # 手动执行 flutter config --android-studio-dir $MY_ANDROID_STUDIO_DIR
        # flutter doctor --verbose
        # echo $ANDROID_HOME && echo $ANDROID_SDK_ROOT
        # flutter doctor --android-licenses
        #      $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --list_installed
        PUB_HOSTED_URL = "https://pub.flutter-io.cn";
        FLUTTER_STORAGE_BASE_URL = "https://storage.flutter-io.cn";
        CXX = "${pkgs.clang_19}/bin/clang++";
      };
    };
  };
  #programs.adb.enable = true;
}

统一home-sessionPath.nix

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
{
  username,
  ...
}:
{
  home-manager = {
    users.${username} = {
      home.sessionPath = [
        "$HOME/.cargo/bin"
        #"$HOME/go/bin"
        "$HOME/myworkspace/my-opt"
        "$HOME/.local/share/pnpm/bin"
        "$HOME/android_flutter/android-sdk/cmdline-tools/latest/bin"
        "$HOME/android_flutter/android-sdk/platform-tools"
      ];
    };
  };
}

其他的

bootload-grub-kernel.nix
 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
{ pkgs, ... }:
{
  boot = {
    kernelPackages = pkgs.linuxKernel.packages.linux_6_12;
    loader = {
      grub = {
        enable = true;
        device = "nodev";
        efiSupport = true;
        extraEntries = ''
          menuentry "Windows efi" {
              search --file --no-floppy --set=root /EFI/Microsoft/Boot/bootmgfw.efi
              chainloader (''${root})/EFI/Microsoft/Boot/bootmgfw.efi
          }
        '';
        theme = (
          pkgs.sleek-grub-theme.override {
            withStyle = "dark"; # bigSur dark light orange
            withBanner = "LYH";
          }
        );
      };
      efi = {
        canTouchEfiVariables = true;
        efiSysMountPoint = "/boot";
      };
    };
  };

}
amd-packages.nix
 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
{ pkgs, ... }:
{

  environment.systemPackages = with pkgs; [
    rocmPackages.rocminfo
    rocmPackages.rocm-smi
    rocmPackages.rpp
    rocmPackages.rocm-core
    rocmPackages.rocm-runtime
    rocmPackages.hipblas
    rocmPackages.llvm.clang
    amdgpu_top
    amdctl
  ];
  boot.kernelModules = [ "kvm-amd" ];
  boot.initrd.kernelModules = [ "amdgpu" ];
  boot.extraModprobeConfig = ''
    options kvm_amd nested=1
    options bt_coex_active=0 swcrypto=1 11n_disable=8
    options kvm ignore_msrs=1 report_ignored_msrs=0
  '';
  hardware.graphics.extraPackages = with pkgs; [
    rocmPackages.clr.icd
    amdvlk
  ];
}
gtk-theme.nix
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
{
  username,
  ...
}:
{
  home-manager.users.${username} = {
    gtk = {
      enable = true;
      theme = {
        name = "vimix-dark-laptop-beryl";
      };
      iconTheme = {
        name = "Flat-Remix-Blue-Dark";
      };
      cursorTheme = {
        name = "Bibata-Modern-Ice";
      };

    };
  };
}
networking-firewall-config.nix
 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
{ pkgs, host, ... }:
{
  networking = {
    hostName = "${host}";
    networkmanager.enable = true;
    nameservers = [
      "223.5.5.5"
      "8.8.4.4"
      "1.1.1.1"
    ];
    firewall = {
      enable = true;
      allowedTCPPorts =
        [
          22
          3389
          7890
          8180
        ]
        ++ (pkgs.lib.range 9000 9999)
        ++ (pkgs.lib.range 47988 48000);
      allowedUDPPorts =
        [
          22
          3389
          7890
          8180
        ]
        ++ (pkgs.lib.range 9000 9999)
        ++ (pkgs.lib.range 47988 48000);
    };
  };

  environment.systemPackages = with pkgs; [ networkmanagerapplet ];
}
nixpkgs-system.nix
 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
42
{ lib, ... }:
{

  nix.settings.experimental-features = "nix-command flakes";
  nix.settings.substituters = lib.mkForce [
    "https://mirror.sjtu.edu.cn/nix-channels/store"
    "https://mirrors.ustc.edu.cn/nix-channels/store"
    "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
  ];
  nixpkgs.config.allowUnfree = true;
  #system.stateVersion = "24.11";
  system.stateVersion = "25.05";
  time.timeZone = "Asia/Shanghai";
  systemd.watchdog.rebootTime = "10s"; # 避免关机或者重启的时候等待太久
  nix.settings.trusted-users = [
    # nix flake update --option substituters https://mirrors.sjtug.sjtu.edu.cn/nix-channels/store/
    "root"
    "y"
  ];
  nix.settings.trusted-substituters = [
    "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store?priority=10"
    "https://mirrors.ustc.edu.cn/nix-channels/store?priority=10"
    "https://mirrors.sjtug.sjtu.edu.cn/nix-channels/store?priority=35"
    "https://nix-mirror.freetls.fastly.net?priority=11"
    "https://cache.nixos.org?priority=12"
    "https://nix-community.cachix.org?priority=13"
    "https://nixpkgs-wayland.cachix.org"
    "https://cache.lix.systems"
  ];
  nix.settings.trusted-public-keys = [
    "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
    "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
    "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA="
    "cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o="
  ];

  nixpkgs.config.permittedInsecurePackages = [
    "another-redis-desktop-manager-1.7.1"
    "electron-31.7.7" # trilium-next-desktop 0.90.2
    "ventoy-1.1.05"
  ];
}
swap_zram.nix
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
{
  ...
}:

{
  swapDevices = [
    {
      device = "/home/swapfile";
      size = 10240;
    }
  ];
  zramSwap = {
    enable = true;
    swapDevices = 1;
    memoryPercent = 80;
    algorithm = "zstd";
  };

}
theme-with-fcitx5.nix

不建议用,仅供参考。

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{
  pkgs,
  username,
  ...
}:
{
  home-manager = {
    users.${username} = {
      home.packages = with pkgs; [
        adwaita-icon-theme
        hicolor-icon-theme
        vimix-gtk-themes
        bibata-cursors
      ];
      gtk = {
        enable = true;
        iconTheme = {
          name = "Flat-Remix-Blue-Dark";
          package = pkgs.flat-remix-icon-theme;

        };
        theme = {
          package = pkgs.vimix-gtk-themes;
          name = "vimix-dark-laptop-beryl";
        };
        gtk2.extraConfig = ''
          gtk-im-module="fcitx"
        '';
        gtk3.extraConfig = {
          gtk-decoration-layout = "appmenu:";
          gtk-application-prefer-dark-theme = true;
          gtk-cursor-theme-name = "Bibata-Modern-Ice";
          "gtk-im-module" = "fcitx";
        };
        gtk4.extraConfig = {
          "gtk-im-module" = "fcitx";
          "gtk-enable-animations" = true; # 可以提高某些程序的兼容性
        };
      };
      qt = {
        enable = true;
        platformTheme.name = "gtk";
      };
      dconf.settings = {
        "org/gnome/desktop/interface" = {
          cursor-theme = "Bibata-Modern-Ice";
          color-scheme = "prefer-dark";
          gtk-theme = "vimix-dark-laptop-beryl";
        };
        "org/gnome/shell/extensions/user-theme" = {
          name = "vimix-dark-laptop-beryl";
        };
        "org/gnome/desktop/wm/preferences" = {
          theme = "vimix-dark-laptop-beryl";
        };
      };
      home.file.".icons/default".source = "${pkgs.bibata-cursors}/share/icons/Bibata-Modern-Ice";
      home.sessionVariables = {
        XCURSOR_SIZE = 24;
        XCURSOR_THEME = "Bibata-Modern-Ice";
        FONTCONFIG_PATH = "/etc/fonts";
      };

    };
  };

}
xdg-mimes.nix
  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
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
{
  lib,
  username,
  ...
}:
with lib;
let
  defaultApps = {
    browser = [ "firefox.desktop" ];
    text = [ "dev.zed.Zed.desktop" ];
    image = [ "imv.desktop" ];
    audio = [ "mpv.desktop" ];
    video = [ "mpv.desktop" ];
    directory = [ "caja.desktop" ];
    office = [ "com.wps.Office.desktop" ];
    pdf = [ "com.wps.Office.desktop" ];
    #terminal = [ "kitty.desktop" ];
    terminal = [ "terminator.desktop" ];
    archive = [ "org.gnome.FileRoller.desktop" ];
  };

  mimeMap = {
    text = [ "text/plain" ];
    image = [
      "image/bmp"
      "image/gif"
      "image/jpeg"
      "image/jpg"
      "image/png"
      "image/svg+xml"
      "image/tiff"
      "image/vnd.microsoft.icon"
      "image/webp"
    ];
    audio = [
      "audio/aac"
      "audio/mpeg"
      "audio/ogg"
      "audio/opus"
      "audio/wav"
      "audio/webm"
      "audio/x-matroska"
    ];
    video = [
      "video/mp2t"
      "video/mp4"
      "video/mpeg"
      "video/ogg"
      "video/webm"
      "video/x-flv"
      "video/x-matroska"
      "video/x-msvideo"
    ];
    directory = [ "inode/directory" ];
    browser = [
      "text/html"
      "x-scheme-handler/about"
      "x-scheme-handler/http"
      "x-scheme-handler/https"
      "x-scheme-handler/unknown"
    ];
    office = [
      "application/vnd.oasis.opendocument.text"
      "application/vnd.oasis.opendocument.spreadsheet"
      "application/vnd.oasis.opendocument.presentation"
      "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
      "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      "application/vnd.openxmlformats-officedocument.presentationml.presentation"
      "application/msword"
      "application/vnd.ms-excel"
      "application/vnd.ms-powerpoint"
      "application/rtf"
    ];
    pdf = [ "application/pdf" ];
    terminal = [ "terminal" ];
    archive = [
      "application/zip"
      "application/rar"
      "application/7z"
      "application/*tar"
    ];
  };

  associations =
    with lists;
    listToAttrs (
      flatten (mapAttrsToList (key: map (type: attrsets.nameValuePair type defaultApps."${key}")) mimeMap)
    );
in
{
  home-manager = {
    users.${username} = {
      xdg.configFile."mimeapps.list".force = true;
      xdg.mimeApps.enable = true;
      xdg.mimeApps.associations.added = associations;
      xdg.mimeApps.defaultApplications = associations;

      home.sessionVariables = {
        # prevent wine from creating file associations
        WINEDLLOVERRIDES = "winemenubuilder.exe=d";
      };
    };
  };

}
vscode.nix
 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
{
  pkgs,
  username,
  ...
}:
{
  home-manager = {
    users.${username} = {
      programs.vscode = {
        enable = true;
        package = pkgs.unstable.vscode;

        /*
          extensions = pkgs.vscode-utils.extensionsFromVscodeMarketplace [
            {
            publisher = "ms-vscode-remote";
            name = "remote-ssh";
            version = "0.116.2024112515";
            sha256 = "080rzj3n6bf49cfkhx7rnns45jd4gsvs8yzapnncmp2svwfhkafw";
            }
            ];
            userSettings = {
            "vim.autoSwitchInputMethod.obtainIMCmd" = "${pkgs.fcitx5}/bin/fcitx5-remote";
            "vim.autoSwitchInputMethod.switchIMCmd" = "${pkgs.fcitx5}/bin/fcitx5-remote -t {im}";
            };
        */
      };
    };
  };
}
手动下载的appimage.nix

只需要desktop文件就够了

 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
{
  pkgs,
  username,
  ...
}:

{
  programs.appimage.enable = true; # 这里只是例子,在某一次写一次就可以了
  programs.appimage.binfmt = true;
  home-manager = {
    users.${username} = {
      home.file = {
        ".local/share/applications/cursor-appimage.desktop".text = ''
          [Desktop Entry]
          Name=cursor-appimage
          Exec=appimage-run  /home/y/myworkspace/my-opt/Cursor.AppImage
          Icon=/home/y/myworkspace/my-opt/cursor.png
          Terminal=false
          Type=Application
          Categories=Development;IDE;
          Version=1.0
          StartupNotify=true
          StartupWMClass=Cursor
          MimeType=text/plain;
        '';
      };
    };
  };
}
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计