Skip to content

Commit

Permalink
misc: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelCoding committed Nov 10, 2024
1 parent 4a72656 commit 07725ee
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 29 deletions.
5 changes: 5 additions & 0 deletions checks/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ self, pkgs }:

{
bird = import ./bird.nix { inherit self pkgs; };
}
34 changes: 34 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 13 additions & 21 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, ... }:
let
systems = [
"x86_64-linux"
# "aarch64-linux"
];

in
{
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = (import nixpkgs) {
inherit system;
};
in
{
checks = import ./checks { inherit self pkgs; };
}
) // {
nixosModules = rec {
bird = ./modules;
default = bird;
};

checks = builtins.listToAttrs (map
(system: {
name = system;
value = {
bird = import ./checks/bird.nix {
inherit self;
pkgs = nixpkgs.legacyPackages.${system};
};
};
})
systems);
};
}
20 changes: 12 additions & 8 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ in
};

protocols = lib.mkOption {
type = with lib.types; attrsOf str;
type = with lib.types; attrsOf lines;
};
};

config = lib.mkIf cfg.enable {
services.bird2 = {
config = ''
router id ${cfg.routerId};
${builtins.concatStringsSep "\n" (builtins.attrValues
(builtins.mapAttrs
config =
let
protocols = lib.mapAttrsToList
(name: conf: ''
protocol ${name} {
${conf}
}
'') cfg.protocols))}
'';
'')
cfg.protocols;
in
''
router id ${cfg.routerId};
${builtins.concatStringsSep "\n" protocols}
'';
};
};
}

0 comments on commit 07725ee

Please sign in to comment.