Merge pull request #42 from nrdxp/flake-clean
flake: clean up by moving implementation to utils
This commit is contained in:
commit
e7ce2fb21b
8
DOC.md
8
DOC.md
@ -74,8 +74,8 @@ directly from this flake via `nixosModules.cachix.<your-cachix>`.
|
|||||||
All expressions in both [modules/list.nix](modules/list.nix) and
|
All expressions in both [modules/list.nix](modules/list.nix) and
|
||||||
[pkgs/default.nix](pkgs/default.nix) are available globally, anywhere else in the
|
[pkgs/default.nix](pkgs/default.nix) are available globally, anywhere else in the
|
||||||
repo. They are additionally included in the `nixosModules` and `overlay` flake
|
repo. They are additionally included in the `nixosModules` and `overlay` flake
|
||||||
outputs, respectively. Packages can manually be added to [flake.nix](flake.nix)
|
outputs, respectively. Packages are automatically included in the `packages`
|
||||||
for inclusion in the `packages` output as well.
|
output as well.
|
||||||
|
|
||||||
The directory structure is identical to nixpkgs to provide a kind of staging area
|
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
|
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
|
`nixpkgs-overlays` in `NIX_PATH`. And of course they will be exported via the
|
||||||
flake output `overlays` as well.
|
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
|
[home-manager]: https://github.com/rycee/home-manager
|
||||||
|
67
flake.nix
67
flake.nix
@ -13,76 +13,43 @@
|
|||||||
inherit (builtins) attrNames attrValues readDir;
|
inherit (builtins) attrNames attrValues readDir;
|
||||||
inherit (nixos) lib;
|
inherit (nixos) lib;
|
||||||
inherit (lib) removeSuffix recursiveUpdate genAttrs filterAttrs;
|
inherit (lib) removeSuffix recursiveUpdate genAttrs filterAttrs;
|
||||||
inherit (utils) pathsToImportedAttrs;
|
inherit (utils) pathsToImportedAttrs genPkgset overlayPaths modules
|
||||||
|
genPackages;
|
||||||
|
|
||||||
utils = import ./lib/utils.nix { inherit lib; };
|
utils = import ./lib/utils.nix { inherit lib; };
|
||||||
|
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
|
|
||||||
pkgImport = pkgs:
|
externOverlays = [ ];
|
||||||
import pkgs {
|
|
||||||
inherit system;
|
pkgset =
|
||||||
overlays = attrValues self.overlays;
|
let overlays = (attrValues self.overlays) ++ externOverlays; in
|
||||||
config = { allowUnfree = true; };
|
genPkgset {
|
||||||
|
inherit master nixos overlays system;
|
||||||
};
|
};
|
||||||
|
|
||||||
pkgset = {
|
|
||||||
osPkgs = pkgImport nixos;
|
|
||||||
pkgs = pkgImport master;
|
|
||||||
};
|
|
||||||
|
|
||||||
in
|
in
|
||||||
with pkgset;
|
with pkgset;
|
||||||
{
|
{
|
||||||
nixosConfigurations =
|
nixosConfigurations =
|
||||||
import ./hosts (recursiveUpdate inputs {
|
import ./hosts (recursiveUpdate inputs {
|
||||||
inherit lib pkgset system utils;
|
inherit lib pkgset system utils;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
devShell."${system}" = import ./shell.nix {
|
devShell."${system}" = import ./shell.nix {
|
||||||
inherit pkgs;
|
pkgs = osPkgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
overlay = import ./pkgs;
|
overlay = import ./pkgs;
|
||||||
|
|
||||||
overlays =
|
overlays = pathsToImportedAttrs overlayPaths;
|
||||||
let
|
|
||||||
overlayDir = ./overlays;
|
|
||||||
fullPath = name: overlayDir + "/${name}";
|
|
||||||
overlayPaths = map fullPath (attrNames (readDir overlayDir));
|
|
||||||
in
|
|
||||||
pathsToImportedAttrs overlayPaths;
|
|
||||||
|
|
||||||
packages."${system}" =
|
packages."${system}" = genPackages {
|
||||||
let
|
overlay = self.overlay;
|
||||||
packages = self.overlay osPkgs osPkgs;
|
overlays = self.overlays;
|
||||||
overlays = lib.filterAttrs (n: v: n != "pkgs") self.overlays;
|
pkgs = osPkgs;
|
||||||
overlayPkgs =
|
};
|
||||||
genAttrs
|
|
||||||
(attrNames overlays)
|
|
||||||
(name: (overlays."${name}" osPkgs osPkgs)."${name}");
|
|
||||||
in
|
|
||||||
recursiveUpdate packages overlayPkgs;
|
|
||||||
|
|
||||||
nixosModules =
|
nixosModules = 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;
|
|
||||||
|
|
||||||
templates.flk.path = ./.;
|
templates.flk.path = ./.;
|
||||||
templates.flk.description = "flk template";
|
templates.flk.description = "flk template";
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
let
|
let
|
||||||
inherit (utils) recImport;
|
inherit (utils) recImport;
|
||||||
inherit (builtins) attrValues removeAttrs;
|
inherit (builtins) attrValues removeAttrs;
|
||||||
inherit (pkgset) osPkgs pkgs;
|
inherit (pkgset) osPkgs unstablePkgs;
|
||||||
|
|
||||||
config = hostName:
|
config = hostName:
|
||||||
lib.nixosSystem {
|
lib.nixosSystem {
|
||||||
@ -37,7 +37,7 @@ let
|
|||||||
"home-manager=${home}"
|
"home-manager=${home}"
|
||||||
];
|
];
|
||||||
|
|
||||||
nixpkgs = { pkgs = osPkgs; };
|
nixpkgs.pkgs = osPkgs;
|
||||||
|
|
||||||
nix.registry = {
|
nix.registry = {
|
||||||
master.flake = master;
|
master.flake = master;
|
||||||
@ -52,7 +52,7 @@ let
|
|||||||
overrides = {
|
overrides = {
|
||||||
nixpkgs.overlays =
|
nixpkgs.overlays =
|
||||||
let
|
let
|
||||||
override = import ../pkgs/override.nix pkgs;
|
override = import ../pkgs/override.nix unstablePkgs;
|
||||||
|
|
||||||
overlay = pkg: final: prev: {
|
overlay = pkg: final: prev: {
|
||||||
"${pkg.pname}" = pkg;
|
"${pkg.pname}" = pkg;
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
let
|
let
|
||||||
inherit (builtins) attrNames isAttrs readDir listToAttrs;
|
inherit (builtins) attrNames isAttrs readDir listToAttrs;
|
||||||
|
|
||||||
inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix;
|
inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix
|
||||||
|
recursiveUpdate genAttrs;
|
||||||
|
|
||||||
# mapFilterAttrs ::
|
# mapFilterAttrs ::
|
||||||
# (name -> value -> bool )
|
# (name -> value -> bool )
|
||||||
@ -13,21 +14,11 @@ let
|
|||||||
# Generate an attribute set by mapping a function over a list of values.
|
# Generate an attribute set by mapping a function over a list of values.
|
||||||
genAttrs' = values: f: listToAttrs (map f values);
|
genAttrs' = values: f: listToAttrs (map f values);
|
||||||
|
|
||||||
in
|
pkgImport = { pkgs, system, overlays }:
|
||||||
{
|
import pkgs {
|
||||||
inherit mapFilterAttrs genAttrs';
|
inherit system overlays;
|
||||||
|
config = { allowUnfree = true; };
|
||||||
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);
|
|
||||||
|
|
||||||
# Convert a list to file paths to attribute set
|
# Convert a list to file paths to attribute set
|
||||||
# that has the filenames stripped of nix extension as keys
|
# that has the filenames stripped of nix extension as keys
|
||||||
@ -38,4 +29,68 @@ in
|
|||||||
value = import path;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user