54 lines
1.6 KiB
Nix
54 lines
1.6 KiB
Nix
{ self, nixpkgs, system }:
|
|
|
|
let
|
|
inherit (self.lib) config;
|
|
|
|
export-config-file = builtins.toFile "config.nix" (
|
|
nixpkgs.lib.generators.toPretty {} config
|
|
);
|
|
export-config = nixpkgs.legacyPackages.${system}.runCommandLocal "config.nix" {} ''
|
|
cp ${export-config-file} $out
|
|
'';
|
|
|
|
salt-pillar-file = hostName: builtins.toFile "${hostName}.yaml" (
|
|
nixpkgs.lib.generators.toPretty {} (self.lib.saltPillarFor hostName)
|
|
);
|
|
salt-pillars = builtins.foldl' (result: hostName: result // {
|
|
"${hostName}-pillar" = nixpkgs.legacyPackages.${system}.runCommandLocal "${hostName}-pillar.nix" {} ''
|
|
cp ${salt-pillar-file hostName} $out
|
|
'';
|
|
}) {} (
|
|
builtins.filter (hostName:
|
|
builtins.elem config.site.hosts.${hostName}.role [ "server" "container" ]
|
|
) (builtins.attrNames config.site.hosts)
|
|
);
|
|
|
|
mkRootfs = hostName:
|
|
nixpkgs.legacyPackages.${system}.runCommandLocal "rootfs_${hostName}" {
|
|
src = self.nixosConfigurations.${hostName}.config.system.build.toplevel;
|
|
} ''
|
|
set -x
|
|
mkdir -p $out/{bin,dev,etc,home,mnt,nix/store,nix/var,proc,root,run,sys,tmp,var,usr}
|
|
ln -s $src/init $out/
|
|
ln -s $src/etc $out/etc/static
|
|
'';
|
|
|
|
rootfs =
|
|
builtins.foldl' (rootfs: hostName: rootfs // {
|
|
"${hostName}-rootfs" = mkRootfs hostName;
|
|
}) {} (
|
|
builtins.attrNames (
|
|
nixpkgs.lib.filterAttrs (_: { role, ... }: role == "container")
|
|
config.site.hosts
|
|
)
|
|
);
|
|
|
|
device-templates = import ./device-templates.nix {
|
|
inherit self nixpkgs system;
|
|
};
|
|
|
|
in
|
|
salt-pillars // rootfs // device-templates // {
|
|
inherit export-config;
|
|
}
|