I’m converting my nixos system configuration to flakes, and unsure of the correct way to set up Cachix.
My (non-flake) configuration.nix contains:
{ config, pkgs, ... }:
{
imports = [
./cachix.nix
# etc.
];
# and plenty more...
}
where /etc/nixos/cachix.nix
was generated imperatively by running:
cachix use nix-community
which generated /etc/nixos/cachix.nix
:
# WARN: this file will get overwritten by $ cachix use <name>
{ pkgs, lib, ... }:
let
folder = ./cachix;
toImport = name: value: folder + ("/" + name);
filterCaches = key: value: value == "regular" && lib.hasSuffix ".nix" key;
imports = lib.mapAttrsToList toImport (lib.filterAttrs filterCaches (builtins.readDir folder));
in {
inherit imports;
nix.settings.substituters = ["https://cache.nixos.org/"];
}
and /etc/nixos/cachix/nix-community.nix
{
nix = {
settings = {
substituters = [
"https://nix-community.cachix.org"
];
trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};
};
}
I’m guessing I could leave it as is, but is there a more idiomatic way to do it in a flake-based system?
Would it make sense to do something like this in flake.nix
?
{
outputs = { self, nixpkgs }: {
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration
{
nix.settings = {
substituters = [
"https://cache.nixos.org/"
"https://nix-community.cachix.org"
];
trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};
}
];
};
};
}