From 3300b5d582db7f92c65cba16a9147256568711ef Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Fri, 25 Dec 2020 12:53:57 -0700 Subject: [PATCH 1/2] flake: clean up by moving implementation to utils Fixes #28 by adding an `externOverlays` list to easily import overlays from external flakes. --- flake.nix | 67 +++++++++--------------------------- hosts/default.nix | 6 ++-- lib/utils.nix | 87 ++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 91 insertions(+), 69 deletions(-) diff --git a/flake.nix b/flake.nix index 9d70c00..9019113 100644 --- a/flake.nix +++ b/flake.nix @@ -13,76 +13,43 @@ inherit (builtins) attrNames attrValues readDir; inherit (nixos) lib; inherit (lib) removeSuffix recursiveUpdate genAttrs filterAttrs; - inherit (utils) pathsToImportedAttrs; + inherit (utils) pathsToImportedAttrs genPkgset overlayPaths modules + genPackages; utils = import ./lib/utils.nix { inherit lib; }; system = "x86_64-linux"; - pkgImport = pkgs: - import pkgs { - inherit system; - overlays = attrValues self.overlays; - config = { allowUnfree = true; }; + externOverlays = [ ]; + + pkgset = + let overlays = (attrValues self.overlays) ++ externOverlays; in + genPkgset { + inherit master nixos overlays system; }; - - pkgset = { - osPkgs = pkgImport nixos; - pkgs = pkgImport master; - }; - in with pkgset; { nixosConfigurations = import ./hosts (recursiveUpdate inputs { inherit lib pkgset system utils; - } - ); + }); devShell."${system}" = import ./shell.nix { - inherit pkgs; + pkgs = osPkgs; }; overlay = import ./pkgs; - overlays = - let - overlayDir = ./overlays; - fullPath = name: overlayDir + "/${name}"; - overlayPaths = map fullPath (attrNames (readDir overlayDir)); - in - pathsToImportedAttrs overlayPaths; + overlays = pathsToImportedAttrs overlayPaths; - packages."${system}" = - let - packages = self.overlay osPkgs osPkgs; - overlays = lib.filterAttrs (n: v: n != "pkgs") self.overlays; - overlayPkgs = - genAttrs - (attrNames overlays) - (name: (overlays."${name}" osPkgs osPkgs)."${name}"); - in - recursiveUpdate packages overlayPkgs; + packages."${system}" = genPackages { + overlay = self.overlay; + overlays = self.overlays; + pkgs = osPkgs; + }; - nixosModules = - let - # binary cache - cachix = import ./cachix.nix; - cachixAttrs = { inherit cachix; }; - - # modules - moduleList = import ./modules/list.nix; - modulesAttrs = pathsToImportedAttrs moduleList; - - # profiles - profilesList = import ./profiles/list.nix; - profilesAttrs = { profiles = pathsToImportedAttrs profilesList; }; - - in - recursiveUpdate - (recursiveUpdate cachixAttrs modulesAttrs) - profilesAttrs; + nixosModules = modules; templates.flk.path = ./.; templates.flk.description = "flk template"; diff --git a/hosts/default.nix b/hosts/default.nix index 7e65763..56366dd 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -11,7 +11,7 @@ let inherit (utils) recImport; inherit (builtins) attrValues removeAttrs; - inherit (pkgset) osPkgs pkgs; + inherit (pkgset) osPkgs unstablePkgs; config = hostName: lib.nixosSystem { @@ -37,7 +37,7 @@ let "home-manager=${home}" ]; - nixpkgs = { pkgs = osPkgs; }; + nixpkgs.pkgs = osPkgs; nix.registry = { master.flake = master; @@ -52,7 +52,7 @@ let overrides = { nixpkgs.overlays = let - override = import ../pkgs/override.nix pkgs; + override = import ../pkgs/override.nix unstablePkgs; overlay = pkg: final: prev: { "${pkg.pname}" = pkg; diff --git a/lib/utils.nix b/lib/utils.nix index f1aae4b..1e86118 100644 --- a/lib/utils.nix +++ b/lib/utils.nix @@ -2,7 +2,8 @@ let inherit (builtins) attrNames isAttrs readDir listToAttrs; - inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix; + inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix + recursiveUpdate genAttrs; # mapFilterAttrs :: # (name -> value -> bool ) @@ -13,21 +14,11 @@ let # Generate an attribute set by mapping a function over a list of values. genAttrs' = values: f: listToAttrs (map f values); -in -{ - inherit mapFilterAttrs genAttrs'; - - recImport = { dir, _import ? base: import "${dir}/${base}.nix" }: - mapFilterAttrs - (_: v: v != null) - (n: v: - if n != "default.nix" && hasSuffix ".nix" n && v == "regular" - then - let name = removeSuffix ".nix" n; in nameValuePair (name) (_import name) - - else - nameValuePair ("") (null)) - (readDir dir); + pkgImport = { pkgs, system, overlays }: + import pkgs { + inherit system overlays; + config = { allowUnfree = true; }; + }; # Convert a list to file paths to attribute set # that has the filenames stripped of nix extension as keys @@ -38,4 +29,68 @@ in value = import path; }); +in +{ + inherit mapFilterAttrs genAttrs' pkgImport pathsToImportedAttrs; + + genPkgset = { master, nixos, overlays, system }: + { + osPkgs = pkgImport { + inherit system overlays; + pkgs = nixos; + }; + + unstablePkgs = pkgImport { + inherit system overlays; + pkgs = master; + }; + }; + + overlayPaths = + let + overlayDir = ../overlays; + fullPath = name: overlayDir + "/${name}"; + in + map fullPath (attrNames (readDir overlayDir)); + + recImport = { dir, _import ? base: import "${dir}/${base}.nix" }: + mapFilterAttrs + (_: v: v != null) + (n: v: + if n != "default.nix" && hasSuffix ".nix" n && v == "regular" + then + let name = removeSuffix ".nix" n; in nameValuePair (name) (_import name) + else + nameValuePair ("") (null)) + (readDir dir); + + modules = + let + # binary cache + cachix = import ../cachix.nix; + cachixAttrs = { inherit cachix; }; + + # modules + moduleList = import ../modules/list.nix; + modulesAttrs = pathsToImportedAttrs moduleList; + + # profiles + profilesList = import ../profiles/list.nix; + profilesAttrs = { profiles = pathsToImportedAttrs profilesList; }; + in + recursiveUpdate + (recursiveUpdate cachixAttrs modulesAttrs) + profilesAttrs; + + genPackages = { overlay, overlays, pkgs }: + let + packages = overlay pkgs pkgs; + overlays' = lib.filterAttrs (n: v: n != "pkgs") overlays; + overlayPkgs = + genAttrs + (attrNames overlays') + (name: (overlays'."${name}" pkgs pkgs)."${name}"); + in + recursiveUpdate packages overlayPkgs; + } From 211fc1d5f5194bff9593f2c9decdc7f8b1e2b34a Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Fri, 25 Dec 2020 12:55:18 -0700 Subject: [PATCH 2/2] DOC.md: update docs to reflect changes. --- DOC.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/DOC.md b/DOC.md index ae35ab1..7474099 100644 --- a/DOC.md +++ b/DOC.md @@ -74,8 +74,8 @@ directly from this flake via `nixosModules.cachix.`. All expressions in both [modules/list.nix](modules/list.nix) and [pkgs/default.nix](pkgs/default.nix) are available globally, anywhere else in the repo. They are additionally included in the `nixosModules` and `overlay` flake -outputs, respectively. Packages can manually be added to [flake.nix](flake.nix) -for inclusion in the `packages` output as well. +outputs, respectively. Packages are automatically included in the `packages` +output as well. The directory structure is identical to nixpkgs to provide a kind of staging area for any modules or packages we might be wanting to merge there later. If your not @@ -88,4 +88,8 @@ line tools will be able to read overlays from here as well since it is set as `nixpkgs-overlays` in `NIX_PATH`. And of course they will be exported via the flake output `overlays` as well. +If you wish to use an overlay from an external flake, simply add it to the +`externOverlays` list in the `let` block of the `outputs` attribute in +[flake.nix](flake.nix). + [home-manager]: https://github.com/rycee/home-manager