Commit febc99046526

Vincent Demeester <vincent@sbr.pm>
2018-11-23 16:27:09
modules: add some default modules and desktop/laptop…
… it's a start ! Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 1a46389
machine/wakasu.nix
@@ -14,6 +14,7 @@
     ../hardware/lenovo-p50.nix
   ];
 
+  profiles.laptop.enable = true;
   security.pam.loginLimits = [
     { domain = "@audio"; item = "memlock"; type = "-"; value = "unlimited"; }
     { domain = "@audio"; item = "rtprio";  type = "-"; value = "99"; }
modules/profiles/desktop.nix
@@ -0,0 +1,20 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+let
+  cfg = config.profiles.desktop;
+in
+{
+  options = {
+    profiles.desktop = {
+      enable = mkOption {
+        default = false;
+        description = "Enable desktop profile";
+        type = types.bool;
+      };
+    };
+  };
+  config = mkIf cfg.enable {
+  
+  };
+}
modules/profiles/laptop.nix
@@ -0,0 +1,25 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+let
+  cfg = config.profiles.laptop;
+in
+{
+  options = {
+    profiles.laptop = {
+      enable = mkOption {
+        default = false;
+        description = "Enable laptop profile";
+        type = types.bool;
+      };
+    };
+  };
+  config = mkIf cfg.enable {
+    profiles.desktop.enable = true;
+    environment.systemPackages = with pkgs; [
+      lm_sensors
+      powertop
+      acpi
+    ];
+  };
+}
modules/profiles/nix-auto-update.nix
@@ -0,0 +1,48 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+let
+  cfg = config.profiles.nix-auto-update;
+in
+{
+  options = {
+    profiles.nix-auto-update = {
+      enable = mkOption {
+        default = true;
+        description = "Enable nix-auto-update profile";
+        type = types.bool;
+      };
+      dates = mkOption {
+        default = "weekly";
+        description = "Specification (in the format described by systemd.time(7)) of the time at which the auto-update will run. ";
+        type = types.str;
+      };
+      version = mkOption {
+        default = "18.09";
+        description = "System version (NixOS)";
+        type = types.str;
+      };
+    };
+  };
+  config = mkIf cfg.enable {
+    system = {
+      stateVersion = cfg.version;
+    };
+    systemd.services.nixos-update = {
+      description = "NixOS Upgrade";
+      unitConfig.X-StopOnRemoval = false;
+      serviceConfig.Type = "oneshot";
+      environment = config.nix.envVars //
+      { inherit (config.environment.sessionVariables) NIX_PATH;
+        HOME = "/root";
+      };
+      path = [ pkgs.gnutar pkgs.xz pkgs.git config.nix.package.out ];
+      script = ''
+        cd /etc/nixos/
+        git pull --autostash --rebase
+        nix-channel --update
+      '';
+      startAt = cfg.dates;
+    };
+  };
+}
modules/profiles/nix-config.nix
@@ -0,0 +1,64 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+let
+  cfg = config.profiles.nix-config;
+in
+{
+  options = {
+    profiles.nix-config = {
+      enable = mkOption {
+        default = true;
+        description = "Enable nix-config profile";
+        type = types.bool;
+      };
+      gcDates = mkOption {
+        default = "weekly";
+        description = "Specification (in the format described by systemd.time(7)) of the time at which the garbage collector will run. ";
+        type = types.str;
+      };
+      olderThan = mkOption {
+        default = "15d";
+        description = "Number of day to keep when garbage collect";
+        type = types.str;
+      };
+    };
+  };
+  config = mkIf cfg.enable {
+    nix = {
+      useSandbox = true;
+      gc = {
+        automatic = true;
+        dates = cfg.gcDates;
+        options = "--delete-older-than ${cfg.olderThan}";
+      };
+      # if hydra is down, don't wait forever
+      extraOptions = ''
+        connect-timeout = 20
+        build-cores = 0
+      '';
+      binaryCaches = [
+        "https://cache.nixos.org/"
+        "https://r-ryantm.cachix.org"
+        "https://vdemeester.cachix.org"
+        "https://shortbrain.cachix.org"
+      ];
+      binaryCachePublicKeys = [
+        "r-ryantm.cachix.org-1:gkUbLkouDAyvBdpBX0JOdIiD2/DP1ldF3Z3Y6Gqcc4c="
+        "vdemeester.cachix.org-1:uCECG6so7v1rs77c5NFz2dCePwd+PGNeZ6E5DrkT7F0="
+        "shortbrain.cachix.org-1:dqXcXzM0yXs3eo9ChmMfmob93eemwNyhTx7wCR4IjeQ="
+      ];
+      trustedUsers = [ "root" "vincent" ];
+    };
+    nixpkgs = {
+      config = {
+        allowUnfree = true;
+        packageOverrides = pkgs: {
+          nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
+            inherit pkgs;
+          };
+        };
+      };
+    };
+  };
+}
modules/module-list.nix
@@ -3,8 +3,10 @@
 {
   imports = [
     ./profiles/fish.nix
-    #./profiles/desktop.nix
-    #./profiles/laptop.nix
+    ./profiles/desktop.nix
+    ./profiles/nix-config.nix
+    ./profiles/nix-auto-update.nix
+    ./profiles/laptop.nix
     ./programs/podman.nix
     ./services/syncthing.nix
     ./services/wireguard.client.nix
profiles/default.nix
@@ -32,60 +32,4 @@
     consoleKeyMap = "fr-bepo";
     defaultLocale = "en_US.UTF-8";
   };
-  nix = {
-    useSandbox = true;
-    gc = {
-      automatic = true;
-      dates = "monthly";
-      options = "--delete-older-than 30d";
-    };
-    # if hydra is down, don't wait forever
-    extraOptions = ''
-      connect-timeout = 20
-      build-cores = 0
-    '';
-    binaryCaches = [
-      "https://cache.nixos.org/"
-      "https://r-ryantm.cachix.org"
-      "https://vdemeester.cachix.org"
-      "https://shortbrain.cachix.org"
-    ];
-    binaryCachePublicKeys = [
-      "r-ryantm.cachix.org-1:gkUbLkouDAyvBdpBX0JOdIiD2/DP1ldF3Z3Y6Gqcc4c="
-      "vdemeester.cachix.org-1:uCECG6so7v1rs77c5NFz2dCePwd+PGNeZ6E5DrkT7F0="
-      "shortbrain.cachix.org-1:dqXcXzM0yXs3eo9ChmMfmob93eemwNyhTx7wCR4IjeQ="
-    ];
-    trustedUsers = [ "root" "vincent" ];
-  };
-  nixpkgs = {
-    config = {
-      allowUnfree = true;
-      packageOverrides = pkgs: {
-        nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
-          inherit pkgs;
-        };
-      };
-    };
-  };
-
-  system = {
-    stateVersion = "18.09";
-  };
-  systemd.services.nixos-update = {
-    description = "NixOS Upgrade";
-    unitConfig.X-StopOnRemoval = false;
-    serviceConfig.Type = "oneshot";
-
-    environment = config.nix.envVars //
-    { inherit (config.environment.sessionVariables) NIX_PATH;
-      HOME = "/root";
-    };
-    path = [ pkgs.gnutar pkgs.xz pkgs.git config.nix.package.out ];
-    script = ''
-      cd /etc/nixos/
-      git pull --autostash --rebase
-      nix-channel --update
-    '';
-    startAt = "weekly";
-  };
 }
profiles/desktop.nix
@@ -2,7 +2,6 @@
 
 {
   imports = [
-    ./default.nix
     ./printing.nix
     ./scanning.nix
     ./avahi.nix