From b277551d6a387d0372b8ea9d81bf5af3e2fb5844 Mon Sep 17 00:00:00 2001 From: Jean-Pierre PRUNARET Date: Sat, 9 Jul 2016 21:12:20 +0200 Subject: [PATCH 1/4] =?UTF-8?q?moulinette=20de=20configuration=20par=20fla?= =?UTF-8?q?gs=20de=20fonctionalit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-generator.nix | 129 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 config-generator.nix diff --git a/config-generator.nix b/config-generator.nix new file mode 100644 index 0000000..61c24e4 --- /dev/null +++ b/config-generator.nix @@ -0,0 +1,129 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) mkEnableOption mkIf mkMerge mkOption singleton types; + #inherit (pkgs) bird; + cfg = config.r6d.config-generator; + + # configFile = pkgs.writeText "bird.conf" '' + # ${cfg.config} + #''; +in + +{ + imports = [ + ]; + + ###### interface + + options = { + + r6d.config-generator = { + + enable = mkEnableOption "Generation de la configuration d'une machine"; + + auto-upgrade = mkOption { + type = types.bool; + default = true; + description = '' + Profil pour activer les mises à jour automatiques. + ''; + }; + + docker = mkOption { + type = types.bool; + default = false; + description = '' + Profil pour l'utilisation de Docker. + ''; + }; + + jeux = mkOption { + type = types.bool; + default = false; + description = '' + Profil pour les jeux vidéos. + ''; + }; + + laptop = mkOption { + type = types.bool; + default = false; + description = '' + Profil pour les outils spécifiques aux ordinateurs portables.. + ''; + }; + + locate = mkOption { + type = types.bool; + default = true; + description = '' + Profil pour activer la fonction locate. + ''; + }; + + nix-serve-server = mkOption { + type = types.bool; + default = false; + description = '' + Profil pour que la machine soit un serveur de cache nix. + ''; + }; + + swap = mkOption { + type = types.bool; + default = false; + description = '' + Profil pour que le swap soit activé. + ''; + }; + + virtualbox = mkOption { + type = types.bool; + default = false; + description = '' + Profil pour l'utilisation de VirtualBox. + ''; + }; + }; + }; + + + ###### implementation + # https://nixos.org/releases/nixos/14.12-small/nixos-14.12.374.61adf9e/manual/sec-writing-modules.html + # https://nixos.org/wiki/NixOS:extend_NixOS + config = mkMerge + [ # Unconditional stuff. + { + #environment.systemPackages = [ ... ]; + r6d.config-generator.enable = true; + } + + # Conditional stuff. + ## Affectation des profils aux machines + (mkIf (config.networking.hostName == "radx.prunetwork.fr") { + r6d.config-generator = { + docker = true; + jeux = true; + laptop = true; + nix-serve-server = true; + swap = true; + virtualbox = true; + }; + }) + + (mkIf (config.networking.hostName == "phenom.dubronetwork.fr") { + r6d.config-generator = { + docker = true; + jeux = true; + laptop = true; + nix-serve-server = true; + swap = true; + virtualbox = true; + }; + }) + + ## Contenu des Profils + # -> voir les sources des dépots base & desktop + ]; +} From d03f8cbfc26fe79efaff409ba055eeffabb3220a Mon Sep 17 00:00:00 2001 From: Jean-Pierre PRUNARET Date: Sat, 9 Jul 2016 21:14:25 +0200 Subject: [PATCH 2/4] ajustement de la configuration --- config-generator.nix | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config-generator.nix b/config-generator.nix index 61c24e4..3189f14 100644 --- a/config-generator.nix +++ b/config-generator.nix @@ -105,10 +105,8 @@ in r6d.config-generator = { docker = true; jeux = true; - laptop = true; nix-serve-server = true; swap = true; - virtualbox = true; }; }) @@ -116,9 +114,7 @@ in r6d.config-generator = { docker = true; jeux = true; - laptop = true; nix-serve-server = true; - swap = true; virtualbox = true; }; }) From 3d1feebee0b97b129812b2d00939dee47db68357 Mon Sep 17 00:00:00 2001 From: Jean-Pierre PRUNARET Date: Sat, 9 Jul 2016 21:25:59 +0200 Subject: [PATCH 3/4] ajout de machines (latitude, neo-nomade) --- config-generator.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config-generator.nix b/config-generator.nix index 3189f14..c2dc81a 100644 --- a/config-generator.nix +++ b/config-generator.nix @@ -110,6 +110,18 @@ in }; }) + (mkIf (config.networking.hostName == "latitude.dubronetwork.fr") { + r6d.config-generator = { + docker = true; + jeux = true; + laptop = true; + }; + }) + (mkIf (config.networking.hostName == "nro-nomade.dubronetwork.fr") { + r6d.config-generator = { + laptop = true; + }; + }) (mkIf (config.networking.hostName == "phenom.dubronetwork.fr") { r6d.config-generator = { docker = true; From 0a8c50303241c0d11b54a3e366d7b1aa34cb5af4 Mon Sep 17 00:00:00 2001 From: Jean-Pierre PRUNARET Date: Sat, 9 Jul 2016 21:26:20 +0200 Subject: [PATCH 4/4] =?UTF-8?q?les=20services=20"activation=20manuelle"=20?= =?UTF-8?q?sont=20g=C3=A9r=C3=A9s=20par=20config-generator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- activation-manuelle/auto-upgrade.nix | 5 +++-- activation-manuelle/locate.nix | 4 ++-- activation-manuelle/nix-serve.nix | 5 +++-- activation-manuelle/swap.nix | 5 +++-- base.nix | 10 +++++++--- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/activation-manuelle/auto-upgrade.nix b/activation-manuelle/auto-upgrade.nix index 0c1c58c..fa61df3 100644 --- a/activation-manuelle/auto-upgrade.nix +++ b/activation-manuelle/auto-upgrade.nix @@ -2,6 +2,7 @@ { # Automatic update & automatic clean - system.autoUpgrade.enable = true; - nix.gc.automatic = true; + + system.autoUpgrade.enable = config.r6d.config-generator.auto-upgrade; + nix.gc.automatic = config.r6d.config-generator.auto-upgrade; } diff --git a/activation-manuelle/locate.nix b/activation-manuelle/locate.nix index bd5c602..072d930 100644 --- a/activation-manuelle/locate.nix +++ b/activation-manuelle/locate.nix @@ -4,8 +4,8 @@ imports = [ ]; - services.locate= { - enable = true; + services.locate = { + enable = config.r6d.config-generator.locate; interval = "hourly"; }; } diff --git a/activation-manuelle/nix-serve.nix b/activation-manuelle/nix-serve.nix index 4dfc384..f5ff4a1 100644 --- a/activation-manuelle/nix-serve.nix +++ b/activation-manuelle/nix-serve.nix @@ -2,6 +2,7 @@ { # Cache http pour le store - services.nix-serve.enable = true; - networking.firewall.allowedTCPPorts = [5000]; + + services.nix-serve.enable = config.r6d.config-generator.nix-serve-server; + networking.firewall.allowedTCPPorts = pkgs.lib.mkIf config.r6d.config-generator.nix-serve-server [5000]; } diff --git a/activation-manuelle/swap.nix b/activation-manuelle/swap.nix index 95d9071..ea92882 100644 --- a/activation-manuelle/swap.nix +++ b/activation-manuelle/swap.nix @@ -1,9 +1,10 @@ { config, pkgs, ... }: { - + # Gestion du swap + # https://en.wikipedia.org/wiki/Swappiness - boot.kernel.sysctl = { + boot.kernel.sysctl = pkgs.lib.mkIf config.r6d.config-generator.swap { # le swap est activé (!= 0) # le swap est utilisé lorsque (100 - x) % de la mémoire est déja allouée "vm.swappiness" = 10; diff --git a/base.nix b/base.nix index 7f73836..b357590 100644 --- a/base.nix +++ b/base.nix @@ -2,12 +2,16 @@ { imports = [ - #./activation-manuelle/auto-upgrade.nix - #./activation-manuelle/locate.nix - #./activation-manuelle/swap.nix ./environment.nix ./localisation.nix ./networking.nix ./services.nix + + # inclusion conditionnelle + ./config-generator.nix + ./activation-manuelle/auto-upgrade.nix + ./activation-manuelle/locate.nix + ./activation-manuelle/nix-serve.nix + ./activation-manuelle/swap.nix ]; }