From f7d4878472fdbdcc5615bdfbcb55f07b2f54b560 Mon Sep 17 00:00:00 2001 From: Guanran Wang Date: Sat, 14 Oct 2023 10:20:42 +0800 Subject: [PATCH] nix: modify nix configurations --- darwin/default.nix | 1 + darwin/main.nix | 20 ++++---------------- darwin/nix/default.nix | 9 +++++++++ darwin/nix/flake.nix | 5 +++++ darwin/nix/gc.nix | 16 ++++++++++++++++ darwin/nix/nix.nix | 29 +++++++++++++++++++++++++++++ nixos/nix/gc.nix | 10 +++++++--- nixos/nix/nix.nix | 10 +++++----- 8 files changed, 76 insertions(+), 24 deletions(-) create mode 100644 darwin/nix/default.nix create mode 100755 darwin/nix/flake.nix create mode 100755 darwin/nix/gc.nix create mode 100755 darwin/nix/nix.nix diff --git a/darwin/default.nix b/darwin/default.nix index c86e6fe..160a79f 100644 --- a/darwin/default.nix +++ b/darwin/default.nix @@ -6,5 +6,6 @@ ./packages ./main.nix ./input.nix + ./nix ]; } \ No newline at end of file diff --git a/darwin/main.nix b/darwin/main.nix index 1259670..a366d5a 100644 --- a/darwin/main.nix +++ b/darwin/main.nix @@ -14,18 +14,10 @@ # List packages installed in system profile. To search by name, run: # $ nix-env -qaP | grep wget - environment.systemPackages = with pkgs; [ - #neovim - #vscode - ]; - - # Auto upgrade nix package and the daemon service. - services.nix-daemon.enable = true; - nix.package = pkgs.nix; - - # Necessary for using flakes on this system. - #nix.settings.experimental-features = "nix-command flakes"; - nix.settings.experimental-features = [ "nix-command" "flakes" ]; + #environment.systemPackages = with pkgs; [ + # neovim + # vscode + #]; # Create /etc/zshrc that loads the nix-darwin environment. programs.zsh.enable = true; # default shell on catalina @@ -154,8 +146,4 @@ # Set Git commit hash for darwin-version. #system.configurationRevision = self.rev or self.dirtyRev or null; - - # Used for backwards compatibility, please read the changelog before changing. - # $ darwin-rebuild changelog - system.stateVersion = 4; } \ No newline at end of file diff --git a/darwin/nix/default.nix b/darwin/nix/default.nix new file mode 100644 index 0000000..bc04325 --- /dev/null +++ b/darwin/nix/default.nix @@ -0,0 +1,9 @@ +{ ... }: + +{ + imports = [ + ./flake.nix + ./nix.nix + ./gc.nix + ]; +} \ No newline at end of file diff --git a/darwin/nix/flake.nix b/darwin/nix/flake.nix new file mode 100755 index 0000000..0e62a9f --- /dev/null +++ b/darwin/nix/flake.nix @@ -0,0 +1,5 @@ +{ ... }: + +{ + nix.settings.experimental-features = [ "nix-command" "flakes" ]; # enable flakes +} diff --git a/darwin/nix/gc.nix b/darwin/nix/gc.nix new file mode 100755 index 0000000..ecbf147 --- /dev/null +++ b/darwin/nix/gc.nix @@ -0,0 +1,16 @@ +{ ... }: + +{ + nix = { + ### optimiser + settings = { + auto-optimise-store = true; + }; + + ### auto delete older NixOS builds + gc = { + automatic = true; + options = "--delete-older-than 7d"; + }; + }; +} diff --git a/darwin/nix/nix.nix b/darwin/nix/nix.nix new file mode 100755 index 0000000..2978ac7 --- /dev/null +++ b/darwin/nix/nix.nix @@ -0,0 +1,29 @@ +{ pkgs, ... }: + +{ + nix.settings = { + trusted-users = [ "@admin" ]; + substituters = [ + "https://mirrors.ustc.edu.cn/nix-channels/store" # USTC - 中国科学技术大学 Mirror + "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" # TUNA - 清华大学 Mirror + "https://mirrors.bfsu.edu.cn/nix-channels/store" # BFSU - 北京外国语大学 Mirror + "https://mirror.sjtu.edu.cn/nix-channels/store" # SJTU - 上海交通大学 Mirror + + "https://nix-community.cachix.org" + "https://cache.garnix.io" + ]; + trusted-public-keys = [ + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" + ]; + use-xdg-base-directories = true; + }; + + # Auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + nix.package = pkgs.nix; + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 4; +} diff --git a/nixos/nix/gc.nix b/nixos/nix/gc.nix index dbdb2ee..311ffa6 100755 --- a/nixos/nix/gc.nix +++ b/nixos/nix/gc.nix @@ -2,15 +2,19 @@ { nix = { - # hard linking - settings.auto-optimise-store = true; + ### optimiser + settings = { + auto-optimise-store = true; + }; - # auto delete older NixOS builds + ### auto delete older NixOS builds gc = { automatic = true; dates = "weekly"; options = "--delete-older-than 7d"; }; + + ### optimiser optimise = { automatic = true; dates = [ "03:45" ]; diff --git a/nixos/nix/nix.nix b/nixos/nix/nix.nix index 5651e21..389d216 100755 --- a/nixos/nix/nix.nix +++ b/nixos/nix/nix.nix @@ -2,13 +2,13 @@ { nix.settings = { - allowed-users = [ "@wheel" ]; + trusted-users = [ "@wheel" ]; substituters = [ - "https://mirrors.ustc.edu.cn/nix-channels/store" - "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" - "https://mirror.sjtu.edu.cn/nix-channels/store" + "https://mirrors.ustc.edu.cn/nix-channels/store" # USTC - 中国科学技术大学 Mirror + "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" # TUNA - 清华大学 Mirror + "https://mirrors.bfsu.edu.cn/nix-channels/store" # BFSU - 北京外国语大学 Mirror + "https://mirror.sjtu.edu.cn/nix-channels/store" # SJTU - 上海交通大学 Mirror - # TODO: actually figure out what is Cachix "https://nix-community.cachix.org" "https://berberman.cachix.org" "https://hyprland.cachix.org"