Skip to content

Commit

Permalink
default.nix: init
Browse files Browse the repository at this point in the history
  • Loading branch information
wegank committed May 16, 2024
1 parent 17c5cb6 commit 894d3ba
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
7 changes: 7 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{system ? builtins.currentSystem}: let
# Import nixpkgs and dream2nix
helpers = import ./helpers.nix {inherit system;};
inherit (helpers) importNgiPackages pkgs;
ngiPackages = importNgiPackages pkgs;
in
ngiPackages
17 changes: 17 additions & 0 deletions flake-inputs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{system ? builtins.currentSystem}: let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);

# Import flake inputs using flake-compat from dream2nix
flake = let
dream2nix = with lock.nodes.dream2nix.locked;
fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
in
import (dream2nix + "/dev-flake/flake-compat.nix") {
inherit system;
src = ./.;
};
in
flake.defaultNix.inputs
77 changes: 77 additions & 0 deletions helpers.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
system ? builtins.currentSystem,
inputs ? import ./flake-inputs.nix {inherit system;},
nixpkgs ? inputs.nixpkgs,
dream2nix ? inputs.dream2nix,
sops-nix ? inputs.sops-nix,
}: let
pkgs = import nixpkgs.outPath {inherit system;};

lib = pkgs.lib.recursiveUpdate pkgs.lib (import ./lib.nix {inherit (pkgs) lib;});

helpers = rec {
# NGI packages are imported from ./pkgs/by-name/default.nix.
importNgiPackages = pkgs: let
callPackage = pkgs.newScope (
ngiPackages // {inherit callPackage;}
);

ngiPackages = import ./pkgs/by-name {
inherit (pkgs) lib;
inherit callPackage pkgs;
dream2nix = import dream2nix.outPath {inherit pkgs;};
};
in
ngiPackages;

# NGI projects are imported from ./projects/default.nix.
# Each project includes packages, and optionally, modules, configurations and tests.
importNgiProjects = pkgs: let
ngiProjects = import ./projects {
inherit lib pkgs;
sources = {
configurations = rawNixosConfigurations;
modules = extendedNixosModules;
};
};
in
ngiProjects;

# The above definition reimports `rawNixosConfigurations` and `extendedNixosModules` into `sources`.
# As configurations and modules are system-agnostic, they are defined by passing `{}` to `importNgiProjects`.
rawNgiProjects = importNgiProjects {};

rawNixosConfigurations = lib.flattenAttrsSlash (lib.mapAttrs (_: v: lib.mapAttrs (_: v: v.path) v) (
lib.mapAttrByPath ["nixos" "configurations"] {} rawNgiProjects
));

rawNixosModules = lib.flattenAttrsDot (lib.foldl lib.recursiveUpdate {} (lib.attrValues (
lib.mapAttrByPath ["nixos" "modules"] {} rawNgiProjects
)));

rawOutputs = rec {
nixosModules =
{
unbootable = ./modules/unbootable.nix;
# The default module adds the default overlay on top of Nixpkgs.
# This is so that `ngipkgs` can be used alongside `nixpkgs` in a configuration.
default.nixpkgs.overlays = [overlays.default];
}
// (lib.filterAttrs (_: v: v != null) rawNixosModules);

overlays.default = final: prev: importNgiPackages prev;
};

extendedNixosModules =
rawOutputs.nixosModules
// {
sops-nix = sops-nix.nixosModules.default;
};

extendedNixosConfigurations =
lib.mapAttrs
(_: config: lib.nixosSystem {modules = [config ./dummy.nix] ++ lib.attrValues extendedNixosModules;})
rawNixosConfigurations;
};
in
helpers // {inherit inputs pkgs;}

0 comments on commit 894d3ba

Please sign in to comment.