From c170e251acc5d286cf21356a6ba2a21a32af3e00 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Sat, 9 Dec 2023 14:18:19 +0800 Subject: [PATCH] fix: nixConfig.extra-sbustituers https://github.com/ryan4yin/nixos-and-flakes-book/discussions/62#discussioncomment-7805510 --- flake.nix | 19 +++------------- home/linux/desktop/creative.nix | 2 +- hosts/harmonica/default.nix | 2 -- modules/common.nix | 40 +++++++++++++++++++++++++++++++++ modules/darwin/default.nix | 4 +++- modules/darwin/nix-core.nix | 10 --------- modules/nixos/core-server.nix | 23 ++++--------------- modules/nixos/user-group.nix | 2 -- 8 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 modules/common.nix diff --git a/flake.nix b/flake.nix index 8701b034..9d402eab 100644 --- a/flake.nix +++ b/flake.nix @@ -409,30 +409,17 @@ # the nixConfig here only affects the flake itself, not the system configuration! nixConfig = { - substituters = [ - # cache mirror located in China - # status: https://mirror.sjtu.edu.cn/ - "https://mirror.sjtu.edu.cn/nix-channels/store" - # status: https://mirrors.ustc.edu.cn/status/ - # "https://mirrors.ustc.edu.cn/nix-channels/store" - - # fallback to official cache server if the above mirrors are not available - "https://cache.nixos.org" - - # fallback to other non-official cache server + # substituers will be appended to the default substituters when fetching packages + extra-substituters = [ + # my own cache server "https://ryan4yin.cachix.org" "https://anyrun.cachix.org" "https://hyprland.cachix.org" - ]; - - # nix community's cache server - extra-substituters = [ "https://nix-community.cachix.org" "https://nixpkgs-wayland.cachix.org" ]; extra-trusted-public-keys = [ "ryan4yin.cachix.org-1:Gbk27ZU5AYpGS9i3ssoLlwdvMIh0NxG0w8it/cv9kbU=" - "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=" "anyrun.cachix.org-1:pqBobmOjI7nKlsUMV25u9QHa9btJK65/C8vnO3p346s=" diff --git a/home/linux/desktop/creative.nix b/home/linux/desktop/creative.nix index 36c15969..625b27e8 100644 --- a/home/linux/desktop/creative.nix +++ b/home/linux/desktop/creative.nix @@ -6,7 +6,7 @@ }: { home.packages = with pkgs; [ # creative - # blender # 3d modeling + blender # 3d modeling # gimp # image editing, I prefer using figma in browser instead of this one inkscape # vector graphics krita # digital painting diff --git a/hosts/harmonica/default.nix b/hosts/harmonica/default.nix index 23556f34..246c6a01 100644 --- a/hosts/harmonica/default.nix +++ b/hosts/harmonica/default.nix @@ -29,6 +29,4 @@ in { # DO NOT change the system's default shell to nushell! it will break some apps! # It's better to change only starship/alacritty/vscode's shell to nushell! }; - - nix.settings.trusted-users = [username]; } diff --git a/modules/common.nix b/modules/common.nix new file mode 100644 index 00000000..efccabcd --- /dev/null +++ b/modules/common.nix @@ -0,0 +1,40 @@ +{ + lib, + username, + ... +}: { + nix.settings = { + # enable flakes globally + experimental-features = ["nix-command" "flakes"]; + + # given the users in this list the right to specify additional substituters via: + # 1. `nixConfig.substituers` in `flake.nix` + # 2. command line args `--options substituers http://xxx` + trusted-users = [username]; + + substituters = [ + # cache mirror located in China + # status: https://mirror.sjtu.edu.cn/ + "https://mirror.sjtu.edu.cn/nix-channels/store" + # status: https://mirrors.ustc.edu.cn/status/ + # "https://mirrors.ustc.edu.cn/nix-channels/store" + + "https://cache.nixos.org" + ]; + + trusted-public-keys = [ + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + ]; + builders-use-substitutes = true; + }; + + # do garbage collection weekly to keep disk usage low + nix.gc = { + automatic = lib.mkDefault true; + dates = lib.mkDefault "weekly"; + options = lib.mkDefault "--delete-older-than 7d"; + }; + + # Allow unfree packages + nixpkgs.config.allowUnfree = lib.mkDefault false; +} diff --git a/modules/darwin/default.nix b/modules/darwin/default.nix index 360be3ee..65692d34 100644 --- a/modules/darwin/default.nix +++ b/modules/darwin/default.nix @@ -1,7 +1,9 @@ { imports = [ - ./apps.nix + ../common.nix ./nix-core.nix + + ./apps.nix ./system.nix ]; } diff --git a/modules/darwin/nix-core.nix b/modules/darwin/nix-core.nix index 12796ac5..99a5de71 100644 --- a/modules/darwin/nix-core.nix +++ b/modules/darwin/nix-core.nix @@ -12,9 +12,6 @@ # ################################################################################### - # enable flakes globally - nix.settings.experimental-features = ["nix-command" "flakes"]; - # Allow unfree packages nixpkgs.config.allowUnfree = true; @@ -28,13 +25,6 @@ programs.nix-index.enable = true; - # boot.loader.grub.configurationLimit = 10; - # do garbage collection weekly to keep disk usage low - nix.gc = { - automatic = lib.mkDefault true; - options = lib.mkDefault "--delete-older-than 7d"; - }; - # Disable auto-optimise-store because of this issue: # https://github.com/NixOS/nix/issues/7273 # "error: cannot link '/nix/store/.tmp-link-xxxxx-xxxxx' to '/nix/store/.links/xxxx': File exists" diff --git a/modules/nixos/core-server.nix b/modules/nixos/core-server.nix index a98fbf49..0189a57d 100644 --- a/modules/nixos/core-server.nix +++ b/modules/nixos/core-server.nix @@ -9,27 +9,12 @@ # ################################################################################### + imports = [ + ../common.nix + ]; + # for nix server, we do not need to keep too much generations boot.loader.systemd-boot.configurationLimit = lib.mkDefault 10; - # boot.loader.grub.configurationLimit = 10; - # do garbage collection weekly to keep disk usage low - nix.gc = { - automatic = lib.mkDefault true; - dates = lib.mkDefault "weekly"; - options = lib.mkDefault "--delete-older-than 7d"; - }; - - nix.settings = { - # Manual optimise storage: nix-store --optimise - # https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-auto-optimise-store - auto-optimise-store = true; - builders-use-substitutes = true; - # enable flakes globally - experimental-features = ["nix-command" "flakes"]; - }; - - # Allow unfree packages - nixpkgs.config.allowUnfree = lib.mkDefault false; # Set your time zone. time.timeZone = "Asia/Shanghai"; diff --git a/modules/nixos/user-group.nix b/modules/nixos/user-group.nix index 4a777a5a..43a53762 100644 --- a/modules/nixos/user-group.nix +++ b/modules/nixos/user-group.nix @@ -1,8 +1,6 @@ { username, ... }: { - nix.settings.trusted-users = [username]; - # Don't allow mutation of users outside the config. users.mutableUsers = false;