summary refs log tree commit diff
path: root/nixos/modules/misc
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/modules/misc')
-rw-r--r--nixos/modules/misc/assertions.nix37
-rw-r--r--nixos/modules/misc/check-config.nix13
-rw-r--r--nixos/modules/misc/crashdump.nix77
-rw-r--r--nixos/modules/misc/ids.nix201
-rw-r--r--nixos/modules/misc/lib.nix15
-rw-r--r--nixos/modules/misc/locate.nix62
-rw-r--r--nixos/modules/misc/nixpkgs.nix87
-rw-r--r--nixos/modules/misc/passthru.nix15
-rw-r--r--nixos/modules/misc/version.nix55
9 files changed, 562 insertions, 0 deletions
diff --git a/nixos/modules/misc/assertions.nix b/nixos/modules/misc/assertions.nix
new file mode 100644
index 00000000000..9cd58550adc
--- /dev/null
+++ b/nixos/modules/misc/assertions.nix
@@ -0,0 +1,37 @@
+{ config, pkgs, ... }:
+
+with pkgs.lib;
+
+let
+
+  failed = map (x: x.message) (filter (x: !x.assertion) config.assertions);
+
+in
+
+{
+
+  options = {
+
+    assertions = mkOption {
+      default = [];
+      example = [ { assertion = false; message = "you can't enable this for that reason"; } ];
+      merge = pkgs.lib.mergeListOption;
+      description = ''
+        This option allows modules to express conditions that must
+        hold for the evaluation of the system configuration to
+        succeed, along with associated error messages for the user.
+      '';
+    };
+
+  };
+
+  config = {
+
+    # This option is evaluated always. Thus the assertions are checked as well. hacky!
+    environment.systemPackages =
+      if [] == failed then []
+      else throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failed)}";
+
+  };
+
+}
diff --git a/nixos/modules/misc/check-config.nix b/nixos/modules/misc/check-config.nix
new file mode 100644
index 00000000000..28f36ad9ae5
--- /dev/null
+++ b/nixos/modules/misc/check-config.nix
@@ -0,0 +1,13 @@
+{pkgs, ...}:
+
+{
+  options = {
+    environment.checkConfigurationOptions = pkgs.lib.mkOption {
+      default = true;
+      example = false;
+      description = ''
+        Whether to check the validity of the entire configuration.
+      '';
+    };
+  };
+}
diff --git a/nixos/modules/misc/crashdump.nix b/nixos/modules/misc/crashdump.nix
new file mode 100644
index 00000000000..6e6bc9dec0f
--- /dev/null
+++ b/nixos/modules/misc/crashdump.nix
@@ -0,0 +1,77 @@
+{pkgs, config, ...}:
+
+with pkgs.lib;
+
+let
+  crashdump = config.boot.crashDump;
+
+  kernelParams = concatStringsSep " " crashdump.kernelParams;
+
+in
+###### interface
+{
+  options = {
+    boot = {
+      crashDump = {
+        enable = mkOption {
+          default = false;
+          example = true;
+          description = ''
+            If enabled, NixOS will set up a kernel that will
+            boot on crash, and leave the user to a stage1 debug1devices
+            interactive shell to be able to save the crashed kernel dump.
+            It also activates the NMI watchdog.
+          '';
+        };
+        kernelPackages = mkOption {
+          default = pkgs.linuxPackages;
+          # We don't want to evaluate all of linuxPackages for the manual
+          # - some of it might not even evaluate correctly.
+          defaultText = "pkgs.linuxPackages";
+          example = "pkgs.linuxPackages_2_6_25";
+          description = ''
+            This will override the boot.kernelPackages, and will add some
+            kernel configuration parameters for the crash dump to work.
+          '';
+        };
+        kernelParams = mkOption {
+          default = [ "debug1devices" ];
+          description = ''
+            Parameters that will be passed to the kernel kexec-ed on crash.
+          '';
+        };
+      };
+    };
+  };
+
+###### implementation
+
+  config = mkIf crashdump.enable {
+    boot = {
+      postBootCommands = ''
+        ${pkgs.kexectools}/sbin/kexec -p /run/current-system/kernel \
+        --initrd=/run/current-system/initrd \
+        --append="init=$(readlink -f /run/current-system/init) system=$(readlink -f /run/current-system) irqpoll maxcpus=1 reset_devices ${kernelParams}" --reset-vga --console-vga
+      '';
+      kernelParams = [
+       "crashkernel=64M"
+       "nmi_watchdog=panic"
+       "softlockup_panic=1"
+       "idle=poll"
+      ];
+      kernelPackages = mkOverride 50 (crashdump.kernelPackages // {
+        kernel = crashdump.kernelPackages.kernel.override 
+          (attrs: {
+            extraConfig = (optionalString (attrs ? extraConfig) attrs.extraConfig) +
+              ''
+                CRASH_DUMP y
+                DEBUG_INFO y
+                PROC_VMCORE y
+                LOCKUP_DETECTOR y
+                HARDLOCKUP_DETECTOR y
+              '';
+          });
+      });
+    };
+  };
+}
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix
new file mode 100644
index 00000000000..adaa2b0d9ae
--- /dev/null
+++ b/nixos/modules/misc/ids.nix
@@ -0,0 +1,201 @@
+# This module defines the global list of uids and gids.  We keep a
+# central list to prevent id collisions.
+
+{ config, pkgs, ... }:
+
+{
+  options = {
+
+    ids.uids = pkgs.lib.mkOption {
+      description = ''
+        The user IDs used in NixOS.
+      '';
+    };
+
+    ids.gids = pkgs.lib.mkOption {
+      description = ''
+        The group IDs used in NixOS.
+      '';
+    };
+
+  };
+
+
+  config = {
+
+    ids.uids = {
+      root = 0;
+      nscd = 1;
+      sshd = 2;
+      ntp = 3;
+      messagebus = 4; # D-Bus
+      haldaemon = 5;
+      nagios = 6;
+      vsftpd = 7;
+      ftp = 8;
+      bitlbee = 9;
+      avahi = 10;
+      atd = 12;
+      zabbix = 13;
+      postfix = 14;
+      dovecot = 15;
+      tomcat = 16;
+      pulseaudio = 22; # must match `pulseaudio' GID
+      gpsd = 23;
+      polkituser = 28;
+      uptimed = 29;
+      ddclient = 30;
+      davfs2 = 31;
+      privoxy = 32;
+      osgi = 34;
+      tor = 35;
+      cups = 36;
+      foldingAtHome = 37;
+      sabnzbd = 38;
+      kdm = 39;
+      ghostOne = 40;
+      git = 41;
+      fourStore = 42;
+      fourStoreEndpoint = 43;
+      virtuoso = 44;
+      rtkit = 45;
+      dovecot2 = 46;
+      dovenull2 = 47;
+      unbound = 48;
+      prayer = 49;
+      mpd = 50;
+      clamav = 51;
+      fprot = 52;
+      bind = 53;
+      wwwrun = 54;
+      spamd = 56;
+      nslcd = 58;
+      nginx = 60;
+      chrony = 61;
+      smtpd = 63;
+      smtpq = 64;
+      supybot = 65;
+      iodined = 66;
+      graphite = 68;
+      statsd = 69;
+      transmission = 70;
+      postgres = 71;
+      smbguest = 74;
+      varnish = 75;
+      dd-agent = 76;
+      lighttpd = 77;
+      lightdm = 78;
+      freenet = 79;
+      ircd = 80;
+      bacula = 81;
+      almir = 82;
+      deluge = 83;
+      mysql = 84;
+      rabbitmq = 85;
+      activemq = 86;
+      gnunet = 87;
+      oidentd = 88;
+      quassel = 89;
+      amule = 90;
+      minidlna = 91;
+      elasticsearch = 92;
+      tcpcryptd = 93; # tcpcryptd uses a hard-coded uid. We patch it in Nixpkgs to match this choice.
+      zope2 = 94;
+      firebird = 95;
+
+      # When adding a uid, make sure it doesn't match an existing gid.
+
+      nixbld = 30000; # start of range of uids
+      nobody = 65534;
+    };
+
+    ids.gids = {
+      root = 0;
+      wheel = 1;
+      kmem = 2;
+      tty = 3;
+      messagebus = 4; # D-Bus
+      haldaemon = 5;
+      disk = 6;
+      vsftpd = 7;
+      ftp = 8;
+      bitlbee = 9;
+      avahi = 10;
+      atd = 12;
+      postfix = 13;
+      postdrop = 14;
+      dovecot = 15;
+      audio = 17;
+      floppy = 18;
+      uucp = 19;
+      lp = 20;
+      tomcat = 21;
+      pulseaudio = 22; # must match `pulseaudio' UID
+      gpsd = 23;
+      cdrom = 24;
+      tape = 25;
+      video = 26;
+      dialout = 27;
+      polkituser = 28;
+      utmp = 29;
+      davfs2 = 31;
+      privoxy = 32;
+      disnix = 33;
+      osgi = 34;
+      ghostOne = 40;
+      git = 41;
+      fourStore = 42;
+      fourStoreEndpoint = 43;
+      virtuoso = 44;
+      dovecot2 = 46;
+      prayer = 49;
+      mpd = 50;
+      clamav = 51;
+      fprot = 52;
+      wwwrun = 54;
+      adm = 55;
+      spamd = 56;
+      networkmanager = 57;
+      nslcd = 58;
+      scanner = 59;
+      nginx = 60;
+      systemd-journal = 62;
+      smtpd = 63;
+      smtpq = 64;
+      supybot = 65;
+      iodined = 66;
+      libvirtd = 67;
+      graphite = 68;
+      transmission = 70;
+      postgres = 71;
+      vboxusers = 72;
+      vboxsf = 73;
+      smbguest = 74;
+      varnish = 75;
+      dd-agent = 76;
+      lighttpd = 77;
+      lightdm = 78;
+      freenet = 79;
+      ircd = 80;
+      bacula = 81;
+      almir = 82;
+      deluge = 83;
+      mysql = 84;
+      rabbitmq = 85;
+      activemq = 86;
+      gnunet = 87;
+      oidentd = 88;
+      quassel = 89;
+      amule = 90;
+      minidlna = 91;
+
+      # When adding a gid, make sure it doesn't match an existing uid.
+
+      users = 100;
+      nixbld = 30000;
+      nogroup = 65534;
+    };
+
+  };
+
+}
diff --git a/nixos/modules/misc/lib.nix b/nixos/modules/misc/lib.nix
new file mode 100644
index 00000000000..18fc68a6988
--- /dev/null
+++ b/nixos/modules/misc/lib.nix
@@ -0,0 +1,15 @@
+{ config, pkgs, ... }:
+
+{
+  options = {
+    lib = pkgs.lib.mkOption {
+      default = {};
+
+      type = pkgs.lib.types.attrsOf pkgs.lib.types.attrs;
+
+      description = ''
+        This option allows modules to define helper functions, constants, etc.
+      '';
+    };
+  };
+}
diff --git a/nixos/modules/misc/locate.nix b/nixos/modules/misc/locate.nix
new file mode 100644
index 00000000000..02b1ed7b63d
--- /dev/null
+++ b/nixos/modules/misc/locate.nix
@@ -0,0 +1,62 @@
+{ config, pkgs, ... }:
+
+with pkgs.lib;
+
+let
+
+  locatedb = "/var/cache/locatedb";
+
+in
+
+{
+
+  ###### interface
+
+  options = {
+
+    services.locate = {
+
+      enable = mkOption {
+        default = false;
+        example = true;
+        description = ''
+          If enabled, NixOS will periodically update the database of
+          files used by the <command>locate</command> command.
+        '';
+      };
+
+      period = mkOption {
+        default = "15 02 * * *";
+        description = ''
+          This option defines (in the format used by cron) when the
+          locate database is updated.
+          The default is to update at 02:15 (at night) every day.
+        '';
+      };
+
+    };
+
+  };
+
+  ###### implementation
+
+  config = {
+
+    systemd.services.update-locatedb =
+      { description = "Update Locate Database";
+        path  = [ pkgs.su ];
+        script =
+          ''
+            mkdir -m 0755 -p $(dirname ${locatedb})
+            exec updatedb --localuser=nobody --output=${locatedb} --prunepaths='/tmp /var/tmp /media /run'
+          '';
+        serviceConfig.Nice = 19;
+        serviceConfig.IOSchedulingClass = "idle";
+      };
+
+    services.cron.systemCronJobs = optional config.services.locate.enable
+      "${config.services.locate.period} root ${config.systemd.package}/bin/systemctl start update-locatedb.service";
+
+  };
+
+}
diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix
new file mode 100644
index 00000000000..0df0e57c98e
--- /dev/null
+++ b/nixos/modules/misc/nixpkgs.nix
@@ -0,0 +1,87 @@
+{ config, pkgs, ... }:
+
+with pkgs.lib;
+
+let
+  isConfig = x:
+    builtins.isAttrs x || builtins.isFunction x;
+
+  optCall = f: x:
+    if builtins.isFunction f
+    then f x
+    else f;
+
+  mergeConfig = lhs_: rhs_:
+    let
+      lhs = optCall lhs_ { inherit pkgs; };
+      rhs = optCall rhs_ { inherit pkgs; };
+    in
+    lhs // rhs //
+    optionalAttrs (lhs ? packageOverrides) {
+      packageOverrides = pkgs:
+        optCall lhs.packageOverrides pkgs //
+        optCall (attrByPath ["packageOverrides"] ({}) rhs) pkgs;
+    };
+
+  configType = mkOptionType {
+    name = "nixpkgs config";
+    check = traceValIfNot isConfig;
+    merge = fold mergeConfig {};
+  };
+
+in
+
+{
+  options = {
+
+    nixpkgs.config = mkOption {
+      default = {};
+      example = literalExample
+        ''
+          { firefox.enableGeckoMediaPlayer = true;
+            packageOverrides = pkgs: {
+              firefox60Pkgs = pkgs.firefox60Pkgs.override {
+                enableOfficialBranding = true;
+              };
+            };
+          }
+        '';
+      type = configType;
+      description = ''
+        The configuration of the Nix Packages collection.  (For
+        details, see the Nixpkgs documentation.)  It allows you to set
+        package configuration options, and to override packages
+        globally through the <varname>packageOverrides</varname>
+        option.  The latter is a function that takes as an argument
+        the <emphasis>original</emphasis> Nixpkgs, and must evaluate
+        to a set of new or overridden packages.
+      '';
+    };
+
+    nixpkgs.system = mkOption {
+      default = pkgs.stdenv.system;
+      description = ''
+        Specifies the Nix platform type for which NixOS should be built.
+        If unset, it defaults to the platform type of your host system
+        (<literal>${builtins.currentSystem}</literal>).
+        Specifying this option is useful when doing distributed
+        multi-platform deployment, or when building virtual machines.
+      '';
+    };
+
+  };
+
+  config = {
+
+    # FIXME
+    nixpkgs.config.packageOverrides = pkgs: {
+      #udev = pkgs.systemd;
+      slim = pkgs.slim.override (args: if args ? consolekit then { consolekit = null; } else { });
+      lvm2 = pkgs.lvm2.override { udev = pkgs.systemd; };
+      upower = pkgs.upower.override { useSystemd = true; };
+      polkit = pkgs.polkit.override { useSystemd = true; };
+      consolekit = null;
+    };
+
+  };
+}
diff --git a/nixos/modules/misc/passthru.nix b/nixos/modules/misc/passthru.nix
new file mode 100644
index 00000000000..f68adc5e843
--- /dev/null
+++ b/nixos/modules/misc/passthru.nix
@@ -0,0 +1,15 @@
+# This module allows you to export something from configuration
+# Use case: export kernel source expression for ease of configuring
+
+{ config, pkgs, ... }:
+
+{
+  options = {
+    passthru = pkgs.lib.mkOption {
+      description = ''
+        This attribute set will be exported as a system attribute.
+        You can put whatever you want here.
+      '';
+    };
+  };
+}
diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix
new file mode 100644
index 00000000000..20a03b44a2a
--- /dev/null
+++ b/nixos/modules/misc/version.nix
@@ -0,0 +1,55 @@
+{ config, pkgs, ... }:
+
+with pkgs.lib;
+
+{
+
+  options = {
+
+    system.nixosVersion = mkOption {
+      type = types.uniq types.string;
+      description = "NixOS version.";
+    };
+
+    system.nixosVersionSuffix = mkOption {
+      type = types.uniq types.string;
+      description = "NixOS version suffix.";
+    };
+
+    system.nixosCodeName = mkOption {
+      type = types.uniq types.string;
+      description = "NixOS release code name.";
+    };
+
+  };
+
+  config = {
+
+    system.nixosVersion =
+      mkDefault (builtins.readFile ../../.version + config.system.nixosVersionSuffix);
+
+    system.nixosVersionSuffix =
+      mkDefault (if builtins.pathExists ../../.version-suffix then builtins.readFile ../../.version-suffix else "pre-git");
+
+    # Note: code names must only increase in alphabetical order.
+    system.nixosCodeName = "Aardvark";
+
+    # Generate /etc/os-release.  See
+    # http://0pointer.de/public/systemd-man/os-release.html for the
+    # format.
+    environment.etc = singleton
+      { source = pkgs.writeText "os-release"
+          ''
+            NAME=NixOS
+            ID=nixos
+            VERSION="${config.system.nixosVersion} (${config.system.nixosCodeName})"
+            VERSION_ID="${config.system.nixosVersion}"
+            PRETTY_NAME="NixOS ${config.system.nixosVersion} (${config.system.nixosCodeName})"
+            HOME_URL="http://nixos.org/"
+          '';
+        target = "os-release";
+      };
+
+  };
+
+}