diff --git a/devices/pc/default.nix b/devices/pc/default.nix index 2afaa53f..16a3f2eb 100644 --- a/devices/pc/default.nix +++ b/devices/pc/default.nix @@ -69,7 +69,7 @@ inputs: ); extraInterfaces = [ "wlo1" ]; }; - harmonia.store = "/nix/tf/nix/store"; + harmonia.store = "/nix/tf"; beesd = { "/".hashTableSizeMB = 2 * 128; "/nix/tf".hashTableSizeMB = 128; }; slurm = { diff --git a/flake.lock b/flake.lock index 6e5b49bb..13cae2ad 100644 --- a/flake.lock +++ b/flake.lock @@ -175,6 +175,21 @@ "type": "github" } }, + "crane": { + "locked": { + "lastModified": 1763938834, + "narHash": "sha256-j8iB0Yr4zAvQLueCZ5abxfk6fnG/SJ5JnGUziETjwfg=", + "owner": "ipetkov", + "repo": "crane", + "rev": "d9e753122e51cee64eb8d2dddfe11148f339f5a2", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, "dankmaterialshell": { "inputs": { "dgop": "dgop", @@ -356,7 +371,7 @@ "flake-parts": { "inputs": { "nixpkgs-lib": [ - "nur-linyinfeng", + "harmonia", "nixpkgs" ] }, @@ -375,6 +390,27 @@ } }, "flake-parts_2": { + "inputs": { + "nixpkgs-lib": [ + "nur-linyinfeng", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1763759067, + "narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_3": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" }, @@ -464,6 +500,28 @@ "type": "github" } }, + "harmonia": { + "inputs": { + "crane": "crane", + "flake-parts": "flake-parts", + "nix": "nix", + "nixpkgs": "nixpkgs_2", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1765044966, + "narHash": "sha256-stn5uyhgEpNxvIr3nTkqbIf4CedMf0+IjkOAO2MNhIg=", + "owner": "nix-community", + "repo": "harmonia", + "rev": "27bef83e88aea6fab6d70f073977133804540334", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "harmonia", + "type": "github" + } + }, "hextra": { "flake": false, "locked": { @@ -726,6 +784,22 @@ "type": "github" } }, + "nix": { + "flake": false, + "locked": { + "lastModified": 1764972171, + "narHash": "sha256-rZf5zbxu0eCz3Lb4IrelWNuegoQHUjCguuJzcyPFvt0=", + "owner": "nixos", + "repo": "nix", + "rev": "0db70b8184c1037a606d9cbd6c277c78f7adf647", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nix", + "type": "github" + } + }, "nix-flatpak": { "locked": { "lastModified": 1754777568, @@ -972,6 +1046,22 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1764426117, + "narHash": "sha256-rTslB7dCKLKCCDg4/6OJ+ZFmU7ctNAKeyYZ4VBnU/TQ=", + "owner": "Mic92", + "repo": "nixpkgs", + "rev": "65037cffdb986acb08035988674765b6cf0f34e7", + "type": "github" + }, + "original": { + "owner": "Mic92", + "ref": "harmonia-coverage", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1764896285, "narHash": "sha256-FN8wHTKO859sBo9nEWeydMo9UT+wAGKAggqHVm5G7Zo=", @@ -1027,14 +1117,14 @@ "inputs": { "devshell": "devshell", "flake-compat": "flake-compat_2", - "flake-parts": "flake-parts", + "flake-parts": "flake-parts_2", "flake-utils": "flake-utils", "nixos-stable": "nixos-stable", "nixpkgs": [ "nixpkgs" ], "nvfetcher": "nvfetcher", - "treefmt-nix": "treefmt-nix" + "treefmt-nix": "treefmt-nix_2" }, "locked": { "lastModified": 1764853090, @@ -1053,13 +1143,13 @@ "nur-xddxdd": { "inputs": { "devshell": "devshell_2", - "flake-parts": "flake-parts_2", + "flake-parts": "flake-parts_3", "nix-index-database": "nix-index-database_2", "nixpkgs": [ "nixpkgs" ], "pre-commit-hooks-nix": "pre-commit-hooks-nix", - "treefmt-nix": "treefmt-nix_2" + "treefmt-nix": "treefmt-nix_3" }, "locked": { "lastModified": 1764843512, @@ -1226,6 +1316,7 @@ "dankmaterialshell": "dankmaterialshell", "date": "date", "fancy-motd": "fancy-motd", + "harmonia": "harmonia", "hextra": "hextra", "home-manager": "home-manager", "impermanence": "impermanence", @@ -1242,7 +1333,7 @@ "nix-index-database": "nix-index-database", "nix4vscode": "nix4vscode", "nixos-wallpaper": "nixos-wallpaper", - "nixpkgs": "nixpkgs_2", + "nixpkgs": "nixpkgs_3", "nixpkgs-2305": "nixpkgs-2305", "nixpkgs-2311": "nixpkgs-2311", "nixpkgs-2411": "nixpkgs-2411", @@ -1491,6 +1582,27 @@ } }, "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "harmonia", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1761311587, + "narHash": "sha256-Msq86cR5SjozQGCnC6H8C+0cD4rnx91BPltZ9KK613Y=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "2eddae033e4e74bf581c2d1dfa101f9033dbd2dc", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, + "treefmt-nix_2": { "inputs": { "nixpkgs": [ "nur-linyinfeng", @@ -1511,7 +1623,7 @@ "type": "github" } }, - "treefmt-nix_2": { + "treefmt-nix_3": { "inputs": { "nixpkgs": [ "nur-xddxdd", diff --git a/flake.nix b/flake.nix index 4acd2e68..ec738531 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,7 @@ niri = { url = "github:sodiboo/niri-flake"; inputs.nixpkgs.follows = "nixpkgs"; }; nix4vscode = { url = "github:nix-community/nix4vscode"; inputs.nixpkgs.follows = "nixpkgs"; }; dankmaterialshell = { url = "github:AvengeMedia/DankMaterialShell"; inputs.nixpkgs.follows = "nixpkgs"; }; + harmonia.url = "github:nix-community/harmonia"; misskey = { url = "git+https://github.com/CHN-beta/misskey?submodules=1"; flake = false; }; rsshub = { url = "github:DIYgod/RSSHub"; flake = false; }; diff --git a/modules/default.nix b/modules/default.nix index 0e19b259..a0296224 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -14,6 +14,7 @@ inputs: let inherit (inputs) topInputs; in topInputs.nixvirt.nixosModules.default topInputs.niri.nixosModules.niri { config.niri-flake.cache.enable = false; } + topInputs.harmonia.nixosModules.harmonia { config.home-manager.sharedModules = [ topInputs.catppuccin.homeModules.catppuccin diff --git a/modules/services/harmonia.nix b/modules/services/harmonia.nix deleted file mode 100644 index 7130c9d0..00000000 --- a/modules/services/harmonia.nix +++ /dev/null @@ -1,26 +0,0 @@ -inputs: -{ - options.nixos.services.harmonia = let inherit (inputs.lib) mkOption types; in mkOption - { - type = types.nullOr (types.submodule { options = - { - hostname = mkOption { type = types.nonEmptyStr; default = "nix-store.chn.moe"; }; - store = mkOption { type = types.nullOr types.nonEmptyStr; default = null; }; - };}); - default = null; - }; - config = let inherit (inputs.config.nixos.services) harmonia; in inputs.lib.mkIf (harmonia != null) - { - services.harmonia = - { - enable = true; - signKeyPaths = [ inputs.config.nixos.system.sops.secrets."store/signingKey".path ]; - settings = inputs.lib.mkIf (harmonia.store != null) { real_nix_store = harmonia.store; }; - }; - nixos = - { - system.sops.secrets."store/signingKey" = {}; - services.nginx.https.${harmonia.hostname}.location."/".proxy.upstream = "http://127.0.0.1:5000"; - }; - }; -} diff --git a/modules/services/harmonia/default.nix b/modules/services/harmonia/default.nix new file mode 100644 index 00000000..fb44c972 --- /dev/null +++ b/modules/services/harmonia/default.nix @@ -0,0 +1,41 @@ +inputs: +{ + options.nixos.services.harmonia = let inherit (inputs.lib) mkOption types; in mkOption + { + type = types.nullOr (types.submodule { options = + { + hostname = mkOption { type = types.nonEmptyStr; default = "nix-store.chn.moe"; }; + store = mkOption { type = types.nullOr types.nonEmptyStr; default = null; }; + };}); + default = null; + }; + config = let inherit (inputs.config.nixos.services) harmonia; in inputs.lib.mkIf (harmonia != null) + { + services.harmonia-dev = + { + package = inputs.options.services.harmonia-dev.package.default.overrideAttrs + (prev: { patches = prev.patches or [] ++ [ ./harmonia.patch ]; }); + cache = + { + enable = true; + signKeyPaths = [ inputs.config.nixos.system.sops.secrets."store/signingKey".path ]; + settings = inputs.lib.mkIf (harmonia.store != null) + { + virtual_nix_store = "/nix/store"; + real_nix_store = "${harmonia.store}/nix/store"; + daemon_store = "/nix/store"; + }; + }; + daemon = + { + enable = true; + dbPath = inputs.lib.mkIf (harmonia.store != null) "${harmonia.store}/nix/var/nix/db/db.sqlite"; + }; + }; + nixos = + { + system.sops.secrets."store/signingKey" = {}; + services.nginx.https.${harmonia.hostname}.location."/".proxy.upstream = "http://127.0.0.1:5000"; + }; + }; +} diff --git a/modules/services/harmonia/harmonia.patch b/modules/services/harmonia/harmonia.patch new file mode 100644 index 00000000..76dc735e --- /dev/null +++ b/modules/services/harmonia/harmonia.patch @@ -0,0 +1,45 @@ +From 310e2b2c6583710c52531785f1245d9621284310 Mon Sep 17 00:00:00 2001 +From: Jack O'Sullivan +Date: Sat, 6 Dec 2025 14:50:23 +0000 +Subject: [PATCH] Expose `daemon_store` in cache as config option + +--- + harmonia-cache/src/config.rs | 14 +++++++++++--- + 1 file changed, 11 insertions(+), 3 deletions(-) + +diff --git a/harmonia-cache/src/config.rs b/harmonia-cache/src/config.rs +index a683d78a..5dd9f801 100644 +--- a/harmonia-cache/src/config.rs ++++ b/harmonia-cache/src/config.rs +@@ -68,6 +68,8 @@ pub(crate) struct Config { + + #[serde(default = "default_daemon_socket")] + pub(crate) daemon_socket: PathBuf, ++ #[serde(default)] ++ pub(crate) daemon_store: Option, + + #[serde(skip, default)] + pub(crate) secret_keys: Vec, +@@ -152,13 +154,19 @@ pub(crate) fn load(pool_metrics: Option>) -> Result { + .as_encoded_bytes() + .to_vec() + }); +- // For daemon communication, use real_nix_store if set (chroot mode), ++ // For daemon communication, use daemon_store, then real_nix_store if set (chroot mode), + // otherwise use the virtual store path + let daemon_store_dir = settings +- .real_nix_store ++ .daemon_store + .as_ref() + .map(|p| p.as_os_str().as_encoded_bytes().to_vec()) +- .unwrap_or_else(|| virtual_store_dir.clone()); ++ .unwrap_or_else(|| { ++ settings ++ .real_nix_store ++ .as_ref() ++ .map(|p| p.as_os_str().as_encoded_bytes().to_vec()) ++ .unwrap_or_else(|| virtual_store_dir.clone()) ++ }); + settings.store = Store::new( + virtual_store_dir, + daemon_store_dir,