home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

systems.nix (1759B)


      1 { sources ? import ./nix
      2 , lib ? sources.lib
      3 , pkgs ? sources.pkgs { }
      4 , pkgs-unstable ? sources.pkgs-unstable { }
      5 , nixpkgs ? sources.nixpkgs { }
      6 }:
      7 with builtins; with lib;
      8 let
      9   /*
     10     mkNixOS: make a nixos system build with the given name and cfg.
     11 
     12     cfg is an attributeSet:
     13     - arch is architecture
     14     - type is weither we want to use nixos (stable) or nixos-unstable
     15 
     16     Example:
     17       hokkaido = { arch = "x86_64-linux"; };
     18       honshu = { arch = "x86_64-linux"; type = "unstable"; };
     19     */
     20   mkNixOS = name: cfg:
     21     let
     22       configuration = ./systems + "/hosts/${name}.nix";
     23       system = cfg.arch;
     24       # If type == unstable, use nixos-unstable (pkgs-unstable) otherwise use nixos (pkgs)
     25       p =
     26         if cfg ? type && cfg.type == "unstable"
     27         then pkgs-unstable
     28         else pkgs;
     29       # If vm == true, build a VM, otherwise build the system
     30       nixos = import (p.path + "/nixos") { inherit configuration system; };
     31       main =
     32         if cfg ? vm && cfg.vm
     33         then nixos.vm
     34         else nixos.config.system.build;
     35     in
     36     main;
     37   mkSystem = name: cfg:
     38     if cfg ? vm && cfg.vm
     39     then (mkNixOS name cfg)
     40     else (mkNixOS name cfg).toplevel;
     41   # mkDigitalOceanImage = name: arch: (mkNixOS name arch).digitalocean
     42 
     43   systemAttrs = (mapAttrs mkSystem (import ./hosts.nix));
     44 
     45   filterSystems = arch: attrValues (filterAttrs (_:v: v.system == arch) systemAttrs);
     46   x86_64Systems = filterSystems "x86_64-linux";
     47   aarch64Systems = filterSystems "aarch64-linux";
     48   allSystems = attrValues systemAttrs;
     49 in
     50 {
     51   systems = nixpkgs.linkFarmFromDrvs "systems" allSystems;
     52   aarch64 = nixpkgs.linkFarmFromDrvs "aarch64" aarch64Systems;
     53   x86_64-linux = nixpkgs.linkFarmFromDrvs "x86_64-linux" x86_64Systems;
     54 } // systemAttrs