network/flake.nix

92 lines
2.9 KiB
Nix
Raw Normal View History

2021-03-05 20:05:50 +01:00
{
description = "Zentralwerk network";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-22.05";
nixpkgs-master.url = "github:NixOS/nixpkgs";
openwrt = {
url = "git+https://git.openwrt.org/openwrt/openwrt.git?ref=openwrt-21.02";
flake = false;
};
openwrt-imagebuilder = {
url = "github:astro/nix-openwrt-imagebuilder";
inputs.nixpkgs.follows = "nixpkgs";
};
2021-03-05 20:05:50 +01:00
};
2022-04-29 00:49:45 +02:00
outputs = inputs@{ self, nixpkgs, nixpkgs-master, openwrt, openwrt-imagebuilder }:
2021-03-05 20:05:50 +01:00
let
system = "x86_64-linux";
systems = [ system ];
forAllSystems = nixpkgs.lib.genAttrs systems;
nixosConfig = name:
2021-03-22 22:38:59 +01:00
self.lib.nixosSystem {
inherit system;
modules = [ self.nixosModule ];
specialArgs.hostName = name;
2021-03-22 22:38:59 +01:00
specialArgs.lib = self.lib;
2021-03-22 23:37:25 +01:00
specialArgs.self = self;
specialArgs.inputs = inputs;
specialArgs.nixpkgs-master = nixpkgs-master;
};
in {
2021-04-10 14:52:13 +02:00
# Config, and utilities
2022-03-22 18:13:17 +01:00
lib = nixpkgs.lib.extend (_final: _prev:
2021-03-19 23:25:31 +01:00
import ./nix/lib {
2021-03-22 20:25:50 +01:00
inherit self;
inherit openwrt;
2021-03-22 20:25:50 +01:00
pkgs = nixpkgs.legacyPackages.x86_64-linux;
});
2021-03-05 20:05:50 +01:00
2021-04-10 14:52:13 +02:00
# Everything that can be built locally outside of NixOS
packages = forAllSystems (system:
2022-04-29 00:49:45 +02:00
import ./nix/pkgs { inherit self nixpkgs system openwrt-imagebuilder; }
);
2021-03-05 20:05:50 +01:00
2021-04-10 14:52:13 +02:00
# Configuration for nixosConfigurations
# (see nix/nixos-module/default.nix)
2022-01-13 19:49:33 +01:00
nixosModule = import ./nix/nixos-module;
2021-03-05 20:05:50 +01:00
2021-04-10 14:52:13 +02:00
# NixOS host systems (servers, and containers)
nixosConfigurations =
builtins.mapAttrs (hostName: _: nixosConfig hostName) (
nixpkgs.lib.filterAttrs (_: { role, ... }:
builtins.elem role [ "server" "container" ]
2021-03-22 20:25:50 +01:00
) self.lib.config.site.hosts
);
2021-04-02 03:09:06 +02:00
2021-04-10 14:52:13 +02:00
# For `nix flake check`, and Hydra
2021-04-02 03:09:06 +02:00
checks = self.packages;
hydraJobs =
with self.lib;
let
exportFileWrapper = pkg:
hydraJob (
nixpkgs.legacyPackages.${system}.runCommand "${pkg.name}-exported" {
src = pkg;
} ''
NAME="${pkg.name}"
mkdir -p $out/nix-support
ln -s ${pkg} $out/$NAME
echo file source-dist $out/$NAME >> $out/nix-support/hydra-build-products
''
);
wrappers = {
2022-05-31 21:57:21 +02:00
"all-device-scripts" = hydraJob;
"export-config" = exportFileWrapper;
"switch-.*" = exportFileWrapper;
"ap.*" = exportFileWrapper;
};
in
builtins.mapAttrs (name: pkg:
builtins.foldl' (result: wrapperName:
if builtins.match wrapperName name != null
then wrappers.${wrapperName} pkg
else result
) pkg (builtins.attrNames wrappers)
) self.packages.${system};
2021-03-05 20:05:50 +01:00
};
}