Commit 733dbedeb04c

Vincent Demeester <vincent@sbr.pm>
2016-12-25 20:00:38
Refactoring of the nix-configuration
- Clean `configuration` and use concept of `profiles` instead. - Add `location` for location-specific configuration (like printers, scanner, …) Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent c88bc95
configuration/common.nix
@@ -6,14 +6,7 @@
 {
 	imports =
 		[
-			./system.nix
-			./keyboard.nix
-                        ./acpi.nix
-			./network.nix
-			./network-gui.nix
-			./gui.nix
-			./virtualisation.nix
-			./security.nix
+			# ./security.nix
 			./users.nix
 			./packages.nix
 		];
configuration/gui.nix
@@ -1,95 +0,0 @@
-{ config, pkgs, ... }:
-
-{
-  imports =
-    [
-      <nixpkgs/nixos/modules/services/hardware/sane_extra_backends/brscan4.nix>
-    ];
-	environment = {
-	systemPackages = with pkgs; [
-		dmenu2
-		dunst
-		emacs
-		firefox
-		# google-chrome
-		gnome3.defaultIconTheme
-		gnome3.gnome_themes_standard
-		# adapta-gtk-theme # wait for 16.09 on this one
-		i3status
-		i3lock
-		libnotify
-		pythonPackages.udiskie
-		scrot
-		termite
-		xdg-user-dirs
-		xlibs.xmodmap
-		xorg.xbacklight
-		xss-lock
-		];
-	};
-
-	hardware.opengl.extraPackages = [ pkgs.vaapiIntel ];
-	hardware.sane = {
-		enable = true;
-		brscan4.enable = true;
-		brscan4.netDevices = {
-      			docker = { model = "MFC-9330CDW"; ip = "192.168.1.57"; };
-    		};
-	};
-	services = {
-		printing = {
-			enable = true;
-			drivers = [ pkgs.gutenprint ];
-		};
-		xserver = {
-			enable = true;
-			enableTCP = false;
-			libinput.enable = true;
-			windowManager = {
-				i3 = {
-					enable = true;
-				};
-				default = "i3";
-			};
-			displayManager = {
-				slim = {
-					enable = true;
-					defaultUser = "vincent";
-				};
-				sessionCommands = ''
-${pkgs.xss-lock}/bin/xss-lock i3lock -- -i $HOME/.background-image &
-${pkgs.xlibs.xmodmap}/bin/xmodmap ~/.Xmodmap &
-${pkgs.networkmanagerapplet}/bin/nm-applet &
-${pkgs.pythonPackages.udiskie}/bin/udiskie -a -t -n -F &
-'';
-			};
-			xkbOptions = "compose:caps";
-		};
-		unclutter.enable = true;
-		redshift = {
-			enable = true;
-			brightness.day = "0.95";
-			brightness.night = "0.7";
-			latitude = "48.3";
-			longitude = "7.5";
-		};
-	};
-
-	fonts = {
-		enableFontDir = true;
-		enableGhostscriptFonts = true;
-		fonts = with pkgs; [
-			corefonts
-			inconsolata
-			dejavu_fonts
-			ubuntu_font_family
-			unifont
-			# google-fonts
-			symbola
-			fira
-			fira-code
-			fira-mono
-			font-droid
-		];
-	};
-}
configuration/keyboard.nix
@@ -1,39 +0,0 @@
-{ config, pkgs, ... }:
-
-{
-	services = {
-		xserver =  {
-			layout = "fr";
-			xkbVariant = "oss";
-			inputClassSections = [
-					''
-					Identifier      "TypeMatrix"
-					MatchIsKeyboard "on"
-					MatchVendor     "TypeMatrix.com"
-					MatchProduct    "USB Keyboard"
-					Driver          "evdev"
-					Option          "XbkModel"      "tm2030USB"
-					Option          "XkbLayout"     "fr"
-					Option          "XkbVariant"    "bepo"
-					''
-					''
-					Identifier      "ErgoDox"
-					MatchIsKeyboard "on"
-					#MatchVendor     "ErgoDox_EZ"
-					#MatchProduct    "ErgoDox_EZ"
-                                        MatchUSBID      "feed:1307"
-					Driver          "evdev"
-					Option          "XkbLayout"     "fr"
-					Option          "XkbVariant"    "bepo"
-					''				
-					''
-					Identifier "evdev touchpad off"
-					MatchIsTouchpad "on"
-					MatchDevicePath "/dev/input/event*"
-					Driver "evdev"
-					Option "Ignore" "true"
-					''
-			];
-		};
-	};
-}
configuration/network-gui.nix
@@ -1,15 +0,0 @@
-{ config, pkgs, ... }:
-
-{
-	networking.networkmanager.enable = true;
-
-	environment.systemPackages = with pkgs; [
-		networkmanagerapplet
-	];
-
-	services.avahi = {
-		enable = true;
-		nssmdns = true;
-		publish.enable = true;
-	};
-}
configuration/packages.nix
@@ -2,9 +2,6 @@
 
 {
 	environment = {
-		variables = {
-			EDITOR = pkgs.lib.mkOverride 0 "vim";
-		};
 		systemPackages = with pkgs; [
 				aspell
 				aspellDicts.en
@@ -13,24 +10,13 @@
 				direnv
 				dobi
 				doctl
-				file
 				gcc
-				gptfdisk
-				git
 				gnumake
 				gnupg
+				gptfdisk
 				haskellPackages.git-annex
-				htop
-				iotop
-				lsof
 				msmtp
-				netcat
 				offlineimap
-				psmisc
-				tmux
-				tree
-				vim
-				wget
 		];
 	};
 }
configuration/system.nix
@@ -1,31 +0,0 @@
-
-{ configs, pkgs, ...}:
-
-{
-	boot.loader.systemd-boot.enable = true;
-	boot.loader.efi.canTouchEfiVariables = true;
-	boot.kernelPackages = pkgs.linuxPackages_4_8;
-
-	time.timeZone = "Europe/Paris";
-
-	system = {
-		stateVersion = "16.09";	
-		autoUpgrade = {
-			enable = true;
-			dates = "13:00";
-		};
-	};
-
-	nix = {
-		useSandbox = true;
-		# if hydra is down, don't wait forever
-		extraOptions = ''
-		    connect-timeout = 20
-		'';
-	};
-	nixpkgs = {
-		config = {
-			allowUnfree = true;
-		};
-	};
-}
configuration/users.nix
@@ -1,9 +1,6 @@
 { config, pkgs, ... }:
 
 {
-	programs = {
-		 zsh.enable = true;
-	};
 	users = {
 		extraUsers = {
 			vincent = {
location/docker.nix
@@ -0,0 +1,14 @@
+{ config, pkgs, ... }:
+
+{
+	imports =[
+		<nixpkgs/nixos/modules/services/hardware/sane_extra_backends/brscan4.nix>
+	];
+
+	hardware.sane = {
+		brscan4.enable = true;
+		brscan4.netDevices = {
+      			docker = { model = "MFC-9330CDW"; ip = "192.168.1.57"; };
+    		};
+	};
+}
location/home.nix
@@ -0,0 +1,4 @@
+{ config, pkgs, ... }:
+
+{
+}
machine/hokkaido.nix
@@ -6,7 +6,10 @@
 			../hardware-configuration.nix
 			../configuration/custom-packages.nix
 			../configuration/common.nix
-			../profiles/audio.nix
+			../profiles/laptop.nix
+			../profiles/virtualization.nix
+			../profiles/dockerization.nix
+			../location/docker.nix
 			../hardware/thinkpad-x220.nix
 			../service/ssh-tunnel.nix
 		];
machine/honshu.nix
@@ -6,7 +6,10 @@
 			../hardware-configuration.nix
 			../configuration/custom-packages.nix
 			../configuration/common.nix
-			../profiles/audio.nix
+			../profiles/laptop.nix
+			../profiles/virtualization.nix
+			../profiles/dockerization.nix
+			../location/home.nix
 			../hardware/dell-latitude-e6540.nix
 		];
 
machine/kobe.nix
@@ -4,11 +4,11 @@
 	imports =
 		[ # Include the results of the hardware scan.
 			../hardware-configuration.nix
-			../configuration/users.nix
-			../configuration/system.nix
-			../configuration/network.nix
-			../configuration/docker.nix
 			../configuration/custom-packages.nix
+			../configuration/users.nix
+			../profiles/server.nix
+			../profiles/dockerization.nix
+			../location/docker.nix
 			../service/ssh-tunnel.nix
 		];
 
machine/wakasu.nix
@@ -6,7 +6,11 @@
 			../hardware-configuration.nix
 			../configuration/custom-packages.nix
 			../configuration/common.nix
-			../profiles/audio.nix
+			../profiles/laptop.nix
+			../profiles/virtualization.nix
+			../profiles/dockerization.nix
+			../location/docker.nix
+			../location/home.nix
 			../hardware/thinkpad-t460s.nix
 		];
 
profiles/default.nix
@@ -1,10 +1,52 @@
 { config, pkgs, ... }:
 
 {
+	programs = {
+		 zsh.enable = true;
+	};
+	environment = {
+		variables = {
+			EDITOR = pkgs.lib.mkOverride 0 "vim";
+		};
+		systemPackages = with pkgs; [
+				file
+				git
+				htop
+				iotop
+				lsof
+				netcat
+				psmisc
+				tmux
+				tree
+				vim
+				wget
+				zsh
+		];
+	};
 	i18n = {
 		consoleFont = "Lat2-Terminus16";
 		consoleKeyMap = "fr";
 		defaultLocale = "en_US.UTF-8";
 		# supportedLocales = [ "en_US/ISO-8859-1" "fr_FR/ISO-8859-1" "fr_FR@euro/ISO-8859-15" ];
 	};
+	nix = {
+		useSandbox = true;
+		# if hydra is down, don't wait forever
+		extraOptions = ''
+		    connect-timeout = 20
+		'';
+	};
+	nixpkgs = {
+		config = {
+			allowUnfree = true;
+		};
+	};
+
+	system = {
+		stateVersion = "16.09";	
+		autoUpgrade = {
+			enable = true;
+			dates = "13:00";
+		};
+	};
 }
profiles/desktop.nix
@@ -0,0 +1,126 @@
+# Common configuration for any desktop (not that laptop are a superset of desktop)
+
+{ configs, pkgs, ...}:
+
+{
+	imports = [
+		./printing.nix
+		./scanning.nix
+	];
+
+	time.timeZone = "Europe/Paris";
+
+	boot.loader.systemd-boot.enable = true;
+	boot.loader.efi.canTouchEfiVariables = true;
+	boot.kernelPackages = pkgs.linuxPackages_4_8;
+
+	environment.systemPackages = with pkgs; [
+		dmenu2
+		dunst
+		emacs
+		firefox
+		gnome3.defaultIconTheme
+		gnome3.gnome_themes_standard
+		# adapta-gtk-theme # wait for 16.09 on this one
+		i3status
+		i3lock
+		libnotify
+		pythonPackages.udiskie
+		scrot
+		termite
+		xdg-user-dirs
+		xdg_utils
+		xlibs.xmodmap
+		xorg.xbacklight
+		xss-lock
+	];
+	hardware.opengl.extraPackages = [ pkgs.vaapiIntel ];
+	services = {
+		avahi = {
+			enable = true;
+			nssmdns = true;
+			publish = {
+				enable = true;
+			};
+		};
+		xserver = {
+			enable = true;
+			enableTCP = false;
+			libinput.enable = true;
+			layout = "fr";
+			xkbVariant = "oss";
+			inputClassSections = [
+					''
+Identifier      "TypeMatrix"
+MatchIsKeyboard "on"
+MatchVendor     "TypeMatrix.com"
+MatchProduct    "USB Keyboard"
+Driver          "evdev"
+Option          "XbkModel"      "tm2030USB"
+Option          "XkbLayout"     "fr"
+Option          "XkbVariant"    "bepo"
+					''
+					''
+Identifier      "ErgoDox"
+MatchIsKeyboard "on"
+#MatchVendor     "ErgoDox_EZ"
+#MatchProduct    "ErgoDox_EZ"
+MatchUSBID      "feed:1307"
+Driver          "evdev"
+Option          "XkbLayout"     "fr"
+Option          "XkbVariant"    "bepo"
+					''
+					''
+Identifier "evdev touchpad off"
+MatchIsTouchpad "on"
+MatchDevicePath "/dev/input/event*"
+Driver "evdev"
+Option "Ignore" "true"
+					''
+			];
+			windowManager = {
+				i3 = {
+					enable = true;
+				};
+				default = "i3";
+			};
+			displayManager = {
+				slim = {
+					enable = true;
+					# Probably put this into users instead ?
+					defaultUser = "vincent";
+				};
+				sessionCommands = ''
+${pkgs.xlibs.xmodmap}/bin/xmodmap ~/.Xmodmap &
+${pkgs.pythonPackages.udiskie}/bin/udiskie -a -t -n -F &
+				'';
+			};
+			xkbOptions = "compose:caps";
+		};
+		unclutter.enable = true;
+		redshift = {
+			enable = true;
+			brightness.day = "0.95";
+			brightness.night = "0.7";
+			latitude = "48.3";
+			longitude = "7.5";
+		};
+	};
+	fonts = {
+		enableFontDir = true;
+		enableGhostscriptFonts = true;
+		fonts = with pkgs; [
+			corefonts
+			inconsolata
+			dejavu_fonts
+			ubuntu_font_family
+			unifont
+			# google-fonts
+			symbola
+			fira
+			fira-code
+			fira-mono
+			font-droid
+		];
+	};
+}
configuration/docker.nix → profiles/dockerization.nix
@@ -1,6 +1,10 @@
+# Docker configuration
 { config, pkgs, ...}:
 
 {
+	environment.systemPackages = with pkgs; [
+		python27Packages.docker_compose
+	];
 	virtualisation = {
 		docker = {
 			enable = true;
@@ -11,5 +15,4 @@
 		};
 	};
 	networking.firewall.trustedInterfaces = [ "docker0" ];
-
 }
profiles/laptop.nix
@@ -0,0 +1,24 @@
+# Common configuration for any laptops
+
+{ configs, pkgs, ...}:
+
+{
+	imports = [
+		./audio.nix
+		./desktop.nix
+	];
+
+	environment.systemPackages = with pkgs; [
+		acpi
+		lm_sensors
+		networkmanagerapplet
+		powertop
+	];
+
+	services.xserver.displayManager.sessionCommands = ''
+${pkgs.xss-lock}/bin/xss-lock i3lock -- -i $HOME/.background-image &
+${pkgs.networkmanagerapplet}/bin/nm-applet &
+	'';
+
+	networking.networkmanager.enable = true;
+}
profiles/printing.nix
@@ -0,0 +1,10 @@
+{ configs, pkgs, ...}:
+
+{
+	services = {
+		printing = {
+			enable = true;
+			drivers = [ pkgs.gutenprint ];
+		};
+	};
+}
configuration/acpi.nix → profiles/scanning.nix
@@ -2,7 +2,10 @@
 
 {
 	environment.systemPackages = with pkgs; [
-		acpi
-		lm_sensors
+		saneFrontends
+		simple-scan
 	];
+	hardware.sane = {
+		enable = true;
+	};
 }
profiles/server.nix
@@ -0,0 +1,9 @@
+# Common configuration for any server
+
+{ configs, pkgs, ...}:
+
+{
+	boot.loader.systemd-boot.enable = true;
+	boot.loader.efi.canTouchEfiVariables = true;
+	boot.kernelPackages = pkgs.linuxPackages_4_8;
+}
configuration/network.nix → profiles/ssh.nix
File renamed without changes
configuration/virtualisation.nix → profiles/virtualization.nix
@@ -1,14 +1,11 @@
+# Virtualization configuration
 { config, pkgs, ... }:
 
 {
-	imports =
-		[
-			./docker.nix
-		];
 	virtualisation = {
 		virtualbox.host.enable = true;
 	};
-	networking.firewall.trustedInterfaces = [ "docker0" "vboxnet0" ];
+	networking.firewall.trustedInterfaces = [ "vboxnet0" ];
 	environment = {
 		systemPackages = with pkgs; [
 			vagrant