Commit f6852d81ea2b

Vincent Demeester <vincent@sbr.pm>
2020-06-30 20:23:28
nix-darwin: experimenting with it…
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent f7758ee
nix/default.nix
@@ -12,4 +12,5 @@ rec {
   gitignore = import sources.gitignore;
   nixos-hardware = import sources.nixos-hardware;
   nur = import sources.NUR;
+  nix-darwin = import sources.nix-darwin;
 }
nix/sources.json
@@ -59,6 +59,18 @@
         "url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz",
         "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
     },
+    "nix-darwin": {
+        "branch": "master",
+        "description": "nix modules for darwin",
+        "homepage": "",
+        "owner": "LnL7",
+        "repo": "nix-darwin",
+        "rev": "47fe6db9c9cd22c4ba57df3281f98f454880bea7",
+        "sha256": "198lxy1q7z6cmlyxd0rigrabjab4i49w2dk3xqm3bs4y0s0qimwy",
+        "type": "tarball",
+        "url": "https://github.com/LnL7/nix-darwin/archive/47fe6db9c9cd22c4ba57df3281f98f454880bea7.tar.gz",
+        "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
+    },
     "nixos": {
         "branch": "nixos-20.03",
         "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
systems/honshu.nix
@@ -0,0 +1,10 @@
+{ config, pkgs, ... }:
+
+{
+  environment.systemPackages = with pkgs; [
+    htop
+    vim
+  ];
+
+  programs.zsh.enable = true;
+}
default.nix
@@ -2,6 +2,7 @@
 , lib ? sources.lib
 , pkgs ? sources.pkgs { }
 , pkgs-unstable ? sources.pkgs-unstable { }
+, pkgs-darwin ? sources.nix-darwin
 , nixpkgs ? sources.nixpkgs { }
 }:
 with builtins; with lib;
@@ -10,20 +11,21 @@ let
   mkNixOS: make a nixos system build with the given name and cfg.
 
   cfg is an attributeSet:
-  - arch is architecture
-  - type is weither we want to use nixos (stable) or nixos-unstable
+  - arch is architecture (darwin is a special one)
+  - channel is the "channel" to use (nixos stable, nixos unstable, …)
+  - vm is whether it is a vm, or not
 
   Example:
     hokkaido = { arch = "x86_64-linux"; };
-    honshu = { arch = "x86_64-linux"; type = "unstable"; };
+    naruhodo = { arch = "x86_64-linux"; channel = "unstable"; };
   */
   mkNixOS = name: cfg:
     let
       configuration = ./systems + "/${name}.nix";
       system = cfg.arch;
-      # If type == unstable, use nixos-unstable (pkgs-unstable) otherwise use nixos (pkgs)
+      # If channel == unstable, use nixos-unstable (pkgs-unstable) otherwise use nixos (pkgs)
       p =
-        if cfg ? type && cfg.type == "unstable"
+        if cfg ? channel && cfg.channel == "unstable"
         then pkgs-unstable
         else pkgs;
       # If vm == true, build a VM, otherwise build the system
@@ -31,9 +33,15 @@ let
       main =
         if cfg ? vm && cfg.vm
         then nixos.vm
-        else nixos.config.system.build;
+        else
+          if system == "x86_64-darwin"
+          then (import (pkgs.darwin.path) { inherit nixpkgs configuration; }).system
+          else nixos.config.system.build;
     in
     main;
+  /*
+  mkSystem: make a system build with the given name and cfg.
+  */
   mkSystem = name: cfg:
     if cfg ? vm && cfg.vm
     then (mkNixOS name cfg)
hosts.nix
@@ -1,10 +1,11 @@
 {
-  hokkaido = { arch = "x86_64-linux"; type = "unstable"; };
-  wakasu = { arch = "x86_64-linux"; type = "unstable"; };
+  hokkaido = { arch = "x86_64-linux"; channel = "unstable"; };
+  wakasu = { arch = "x86_64-linux"; channel = "unstable"; };
   kerkouane = { arch = "x86_64-linux"; };
   okinawa = { arch = "x86_64-linux"; };
   sakhalin = { arch = "x86_64-linux"; };
+  honshu = { arch = "x86_64-darwin"; channel = "unstable"; };
   # Test VM
-  foo = { arch = "x86_64-linux"; type = "unstable"; vm = true; };
+  foo = { arch = "x86_64-linux"; channel = "unstable"; vm = true; };
   # mypi = { arch = "aarch64-linux" };
 }