From 768caf988205c4ab2b0594a22e41cb024d39374f Mon Sep 17 00:00:00 2001 From: servius Date: Wed, 4 Feb 2026 23:33:40 +0530 Subject: [PATCH] feat: Unify all of the nixos substituters --- modules/nixos/substituters.nix | 50 ++++++++++++++++++++++++++++++++++ nixos/ryu/configuration.nix | 18 ++++-------- nixos/tako/configuration.nix | 15 +++------- nixos/tsuba/configuration.nix | 12 +++----- 4 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 modules/nixos/substituters.nix diff --git a/modules/nixos/substituters.nix b/modules/nixos/substituters.nix new file mode 100644 index 00000000..54d3e939 --- /dev/null +++ b/modules/nixos/substituters.nix @@ -0,0 +1,50 @@ +{ + config, + lib, + ... +}: +with lib; let + cfg = config.nix.substituters; +in { + options.nix.substituters = { + enableCuda = mkOption { + type = types.bool; + default = false; + description = "Enable NixOS CUDA cache"; + }; + + enableLlamaCpp = mkOption { + type = types.bool; + default = false; + description = "Enable llama-cpp cache"; + }; + }; + + config = { + nix.settings = { + trusted-substituters = + [ + "https://nix-community.cachix.org" + "https://nixos-raspberrypi.cachix.org" + ] + ++ optionals cfg.enableLlamaCpp [ + "https://llama-cpp.cachix.org" + ] + ++ optionals cfg.enableCuda [ + "https://cache.nixos-cuda.org" + ]; + + trusted-public-keys = + [ + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI=" + ] + ++ optionals cfg.enableLlamaCpp [ + "llama-cpp.cachix.org-1:H75X+w83wUKTIPSO1KWy9ADUrzThyGs8P5tmAbkWhQc=" + ] + ++ optionals cfg.enableCuda [ + "cache.nixos-cuda.org:74DUi4Ye579gUqzH4ziL9IyiJBlDpMRn9MBN8oNan9M=" + ]; + }; + }; +} diff --git a/nixos/ryu/configuration.nix b/nixos/ryu/configuration.nix index 3daac741..8d74e33b 100644 --- a/nixos/ryu/configuration.nix +++ b/nixos/ryu/configuration.nix @@ -12,6 +12,7 @@ ./apps ./vms ./games + ../../modules/nixos/substituters.nix ]; security.tpm2 = { @@ -46,18 +47,6 @@ auto-optimise-store = true; extra-experimental-features = "nix-command flakes auto-allocate-uids"; trusted-users = [device.user]; - trusted-substituters = [ - "https://nix-community.cachix.org" - "https://nixos-raspberrypi.cachix.org" - "https://llama-cpp.cachix.org" - "https://cuda-maintainers.cachix.org" - ]; - trusted-public-keys = [ - "cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E=" - "llama-cpp.cachix.org-1:H75X+w83wUKTIPSO1KWy9ADUrzThyGs8P5tmAbkWhQc=" - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI=" - ]; }; extraOptions = '' build-users-group = nixbld @@ -76,6 +65,11 @@ # ../../builders/tsuba.nix ]; distributedBuilds = true; + # Enable CUDA and llama-cpp caches + substituters = { + enableCuda = true; + enableLlamaCpp = true; + }; }; users.users.${device.user} = { diff --git a/nixos/tako/configuration.nix b/nixos/tako/configuration.nix index a4446dac..38db7f2d 100644 --- a/nixos/tako/configuration.nix +++ b/nixos/tako/configuration.nix @@ -9,6 +9,7 @@ ./services ./tako.nix # ./docker.nix + ../../modules/nixos/substituters.nix ]; virtualisation.docker.enable = true; @@ -35,7 +36,6 @@ # Use the systemd-boot EFI boot loader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - nix = { settings = { max-jobs = 1; @@ -43,16 +43,6 @@ auto-optimise-store = true; extra-experimental-features = "nix-command flakes auto-allocate-uids"; trusted-users = [device.user "remotebuilder"]; - trusted-substituters = [ - "https://nix-community.cachix.org" - "https://nixos-raspberrypi.cachix.org" - # "https://sh.darksailor.dev" - ]; - trusted-public-keys = [ - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI=" - # "tako:bcVPoFGBZ0i7JAKMXIqLj2GY3CulLC4kP7rQyqes1RM=" - ]; }; extraOptions = '' build-users-group = nixbld @@ -67,6 +57,9 @@ }; package = pkgs.nixVersions.nix_2_32; # deploy-rs doesn't work with nix >= 2.32 distributedBuilds = true; + substituters = { + enableCuda = true; + }; }; users.users.${device.user} = { diff --git a/nixos/tsuba/configuration.nix b/nixos/tsuba/configuration.nix index dab2bdd1..3f0bdf55 100644 --- a/nixos/tsuba/configuration.nix +++ b/nixos/tsuba/configuration.nix @@ -5,6 +5,10 @@ device, ... }: { + imports = [ + ../../modules/nixos/substituters.nix + ]; + users.extraUsers.servius.extraGroups = ["docker"]; networking.firewall.enable = false; services.openssh.enable = true; @@ -16,14 +20,6 @@ auto-optimise-store = true; extra-experimental-features = "nix-command flakes auto-allocate-uids"; trusted-users = ["root" "remotebuilder" device.user]; - trusted-substituters = [ - "https://nix-community.cachix.org" - "https://nixos-raspberrypi.cachix.org" - ]; - trusted-public-keys = [ - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI=" - ]; }; extraOptions = '' build-users-group = nixbld