about summary refs log tree commit diff
path: root/modules/nix/default.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-01-05 17:24:38 +0000
committerAlyssa Ross <hi@alyssa.is>2019-01-27 15:08:16 +0000
commitfa3351f0099096419ef72d4fbc71b32c178396bc (patch)
treeb2200d2a29ebe7806f6a2fe218caf52010ca519d /modules/nix/default.nix
parentf0a202366786b44ffd486c588d9150d1fb5ecea3 (diff)
downloadnixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar.gz
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar.bz2
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar.lz
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar.xz
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar.zst
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.zip
Add config
Diffstat (limited to 'modules/nix/default.nix')
-rw-r--r--modules/nix/default.nix49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/nix/default.nix b/modules/nix/default.nix
new file mode 100644
index 000000000000..eb2f41c49697
--- /dev/null
+++ b/modules/nix/default.nix
@@ -0,0 +1,49 @@
+{ config, pkgs, options, lib, ... }:
+
+let
+  # Most of the standard Darwin-detection methods cause infinite recursion.
+  isDarwin = options.environment ? "darwinConfig";
+
+  # Copy entire nixlib tree to the store.
+  root =
+    let
+      # Just needed for runCommand and git.
+      bootstrapPkgs = import ../.. {};
+
+      # Remove .git before adding to the store, because it's likely to
+      # be large. Ideally, we would also remove files in .gitignore
+      # here too, but that would require either a builtin for running a
+      # shell command, or a gitignore parser written in Nix (eww).
+      workingTree = builtins.filterSource (path: type: baseNameOf path != ".git") ../..;
+    in
+      # Now, use a derivation to delete any gitignored files. Then, we
+      # can use the resulting Nix store path as root tree.
+      toString (bootstrapPkgs.runCommand "nixlib-root" {} ''
+        cp -R ${workingTree} "$out"
+        chmod -R u+w "$out"
+        ${bootstrapPkgs.git}/bin/git init "$out"
+        ${bootstrapPkgs.git}/bin/git -C "$out" clean -fX
+        rm -rf "$out/.git"
+      '');
+
+in {
+  nix.nixPath = [
+    "nixos-config=${root}/sys/${config.networking.hostName}.nix"
+    root
+  ];
+
+  nixpkgs.overlays =
+    let
+      inherit (builtins) attrNames readDir;
+      dir = ../../nixpkgs-overlays;
+      names = attrNames (readDir dir);
+    in
+      map (o: import "${root}/nixpkgs-overlays/${o}") names;
+
+  services = lib.optionalAttrs isDarwin
+    { nix-daemon.enable = true; };
+
+  nix.package = pkgs.nixUnstable;
+
+  nix.daemonNiceLevel = 2;
+}