2024-12-16 09:34:15 +01:00
# SPDX-FileCopyrightText: 2024 Lubin Bailly <lubin.bailly@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
2024-12-15 20:40:51 +01:00
{
config ,
lib ,
pkgs ,
name ,
. . .
} :
2024-12-09 11:55:57 +01:00
let
inherit ( lib ) mapAttrs mkOption ;
inherit ( lib . types )
attrsOf
bool
str
2024-12-10 13:38:44 +01:00
any
2024-12-09 11:55:57 +01:00
submodule
2024-12-15 20:40:51 +01:00
package
2024-12-09 11:55:57 +01:00
;
mandatory . options = {
supportPoE = mkOption {
type = bool ;
example = true ;
description = ''
2024-12-10 09:11:30 +01:00
Whether this interface supports PoE .
2024-12-09 11:55:57 +01:00
'' ;
} ;
} ;
in
{
imports = [
./interfaces.nix
./poe.nix
./protocols.nix
./system.nix
./vlans.nix
] ;
options = {
2024-12-10 13:38:44 +01:00
# Hack because of this https://git.dgnum.eu/DGNum/colmena/src/commit/71b1b660f2cda2e34e134d0028cafbd56bb22008/src/nix/hive/eval.nix#L166 which defines nixpkgs option but we don't have it here. What about liminix ?
nixpkgs = mkOption {
type = attrsOf any ;
default = { } ;
} ;
2024-12-15 20:40:51 +01:00
netconf = {
xmls . configuration = mkOption {
type = str ;
readOnly = true ;
description = ''
The full configuration to send to a JunOS .
'' ;
} ;
mandatoryInterfaces = mkOption {
type = attrsOf ( submodule mandatory ) ;
example = {
" g e - 0 / 0 / 0 " = {
supportPoE = true ;
} ;
" g e - 0 / 0 / 1 " = {
supportPoE = true ;
} ;
" x e - 0 / 0 / 0 " = {
supportPoE = false ;
} ;
2024-12-09 11:55:57 +01:00
} ;
2024-12-15 20:40:51 +01:00
description = ''
JunOS require some interfaces to always be configured ( even if they are disabled ) ,
which correspond to physical interfaces of the switch . They have to be declared here
with some information about it ( only if it supports PoE for now ) .
'' ;
2024-12-09 11:55:57 +01:00
} ;
2024-12-15 20:40:51 +01:00
rpc = mkOption {
type = package ;
readOnly = true ;
} ;
} ;
} ;
config = {
interfaces =
let
mkIntf = _ : _ : { } ;
in
mapAttrs mkIntf config . netconf . mandatoryInterfaces ;
netconf = {
xmls . configuration = with config . netconf . xmls ; ''
<configuration>
$ { system }
$ { interfaces }
$ { protocols }
$ { vlans }
$ { poe }
< /configuration >
'' ;
rpc = pkgs . writeText " ${ name } . r p c " ''
<rpc>
<edit-config>
<config>
$ { config . netconf . xmls . configuration }
< /config >
<target>
< candidate / >
< /target >
< /edit-config >
< /rpc >
<rpc>
< commit / >
< /rpc >
2024-12-09 11:55:57 +01:00
'' ;
} ;
} ;
}