From f15bb721d220109a64c68b9ded8caaf000fbab34 Mon Sep 17 00:00:00 2001 From: Astro Date: Fri, 19 Mar 2021 01:41:12 +0100 Subject: [PATCH] pkgs/device-templates.nix: update --- flake.nix | 8 +++---- nix/lib/config/default.nix | 1 - nix/lib/config/salt-support/salt-pillar.nix | 2 +- nix/pkgs/device-templates.nix | 24 ++++++++++----------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index 11b0f71..78a7ae3 100644 --- a/flake.nix +++ b/flake.nix @@ -12,8 +12,8 @@ forAllSystems = nixpkgs.lib.genAttrs systems; in rec { - lib = forAllSystems (system: - import ./nix/lib { inherit nixpkgs system; } + lib = + import ./nix/lib { inherit nixpkgs; } ); packages = forAllSystems (system: { @@ -25,9 +25,7 @@ ln -s $src/init $out/ ln -s $src/etc $out/etc/static ''; - }); - - #defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello; + } // (import ./nix/pkgs/device-templates.nix { inherit self nixpkgs system; })); nixosModule = { ... }: { imports = nixpkgs.lib.filesystem.listFilesRecursive ./nix/nixos-modules; diff --git a/nix/lib/config/default.nix b/nix/lib/config/default.nix index 0ff706a..07f5a27 100644 --- a/nix/lib/config/default.nix +++ b/nix/lib/config/default.nix @@ -6,7 +6,6 @@ let modules = [ ./options.nix ./legacy.nix - ./device-templates.nix ]; }; in diff --git a/nix/lib/config/salt-support/salt-pillar.nix b/nix/lib/config/salt-support/salt-pillar.nix index 2ffa5dc..0452b12 100644 --- a/nix/lib/config/salt-support/salt-pillar.nix +++ b/nix/lib/config/salt-support/salt-pillar.nix @@ -6,4 +6,4 @@ let in builtins.foldl' (result: filename: recursiveUpdate result (loadYaml filename) -) {} (filesystem.listFilesRecursive ../../salt-pillar) +) {} (filesystem.listFilesRecursive ../../../../salt-pillar) diff --git a/nix/pkgs/device-templates.nix b/nix/pkgs/device-templates.nix index 006c07f..3186364 100644 --- a/nix/pkgs/device-templates.nix +++ b/nix/pkgs/device-templates.nix @@ -1,6 +1,9 @@ -{ config, lib, pkgs, ... }: -with lib; +{ self, nixpkgs, system }: +with nixpkgs.lib; let + pkgs = nixpkgs.legacyPackages.${system}; + config = self.lib.${system}.config; + templates = role: { ap = _: ../salt/cpe/ap.sh; switch = model: ../salt/switches + "/${model}.expect"; @@ -15,16 +18,8 @@ let import ./salt-support/expand-template.nix { inherit pkgs; } name (replaceNetmasks template) data; -in -{ - options.site.device-scripts = mkOption { - type = with types; attrsOf path; - }; - options.site.all-device-scripts = mkOption { - type = types.path; - }; - config.site.device-scripts = + device-scripts = builtins.mapAttrs (hostname: { role, model, ... }: expandTemplate "${hostname}.sh" (templates role model) ({ inherit hostname; @@ -40,7 +35,7 @@ in role == "ap" || role == "switch" ) config.site.hosts); - config.site.all-device-scripts = + all-device-scripts = pkgs.runCommandLocal "all-device-scripts" {} ( '' mkdir -p $out/bin @@ -51,4 +46,7 @@ in ) (builtins.attrNames config.site.device-scripts) ) ); -} +in +{ + inherit all-device-scripts; +} // device-scripts