Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A series of "clenups" #5

Merged
merged 6 commits into from
Apr 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,30 @@
outputs = inputs@{ deploy, nixos, nur, self, utils, ... }:
let
lib = import ./lib { inherit self nixos inputs; };
in
lib.mkFlake {
inherit self;
hosts = ./hosts;
packages = import ./pkgs;
suites = import ./suites;
extern = import ./extern;
overrides = import ./overrides;
overlays = ./overlays;
profiles = ./profiles;
userProfiles = ./users/profiles;
modules = import ./modules/module-list.nix;
userModules = import ./users/modules/module-list.nix;
} // {
defaultTemplate = self.templates.flk;
templates.flk.path = ./.;
templates.flk.description = "flk template";
templates.mkflake.path =
let
excludes = [ "lib" "tests" "cachix" "nix" "theme" ".github" "bors.toml" "cachix.nix" ];
filter = path: type: ! builtins.elem (baseNameOf path) excludes;
in
builtins.filterSource filter ./.;
templates.mkflake.description = "template with necessary folders for mkFlake usage";
};
in lib.mkFlake {
inherit self;
hosts = ./hosts;
packages = import ./pkgs;
suites = import ./suites;
extern = import ./extern;
overrides = import ./overrides;
overlays = ./overlays;
profiles = ./profiles;
userProfiles = ./users/profiles;
modules = import ./modules/module-list.nix;
userModules = import ./users/modules/module-list.nix;
} // {
inherit lib;
defaultTemplate = self.templates.flk;
templates.flk.path = ./.;
templates.flk.description = "flk template";
templates.mkflake.path =
let
excludes = [ "lib" "tests" "cachix" "nix" "theme" ".github" "bors.toml" "cachix.nix" ];
filter = path: type: ! builtins.elem (baseNameOf path) excludes;
in
builtins.filterSource filter ./.;
templates.mkflake.description = "template with necessary folders for mkFlake usage";
};

}
20 changes: 8 additions & 12 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
args@{ nixos, self, ... }:
let inherit (nixos) lib; in
lib.makeExtensible (final:
let callLibs = file: import file
({
inherit lib;

dev = final;
} // args);
args@{ nixos, self, ... }: # TODO: craft well-defined api for devos-lib
let
inherit (nixos) lib;
in lib.makeExtensible (final:
let
callLibs = file: import file ({ lib = final; } // args);
in
with final;
{
inherit callLibs;

Expand All @@ -18,8 +14,8 @@ lib.makeExtensible (final:
strings = callLibs ./strings.nix;

mkFlake = callLibs ./mkFlake;
evalFlakeArgs = callLibs ./mkFlake/evalArgs.nix;

} //
with final; {
inherit (attrs) mapFilterAttrs genAttrs' safeReadDir
pathsToImportedAttrs concatAttrs filterPackages;
inherit (lists) pathsIn;
Expand Down
20 changes: 10 additions & 10 deletions lib/devos/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, nixos, dev, ... }:
{ lib, ... }:
{
# pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs
pkgImport = nixpkgs: overlays: system:
Expand All @@ -9,22 +9,22 @@

profileMap = map (profile: profile.default);

mkNodes = dev.callLibs ./mkNodes.nix;
mkNodes = lib.callLibs ./mkNodes.nix;

mkHosts = dev.callLibs ./mkHosts.nix;
mkHosts = lib.callLibs ./mkHosts.nix;

mkSuites = dev.callLibs ./mkSuites.nix;
mkSuites = lib.callLibs ./mkSuites.nix;

mkProfileAttrs = dev.callLibs ./mkProfileAttrs.nix;
mkProfileAttrs = lib.callLibs ./mkProfileAttrs.nix;

mkPkgs = dev.callLibs ./mkPkgs.nix;
mkPkgs = lib.callLibs ./mkPkgs.nix;

recImport = dev.callLibs ./recImport.nix;
recImport = lib.callLibs ./recImport.nix;

devosSystem = dev.callLibs ./devosSystem.nix;
devosSystem = lib.callLibs ./devosSystem.nix;

mkHomeConfigurations = dev.callLibs ./mkHomeConfigurations.nix;
mkHomeConfigurations = lib.callLibs ./mkHomeConfigurations.nix;

mkPackages = dev.callLibs ./mkPackages.nix;
mkPackages = lib.callLibs ./mkPackages.nix;
}

12 changes: 6 additions & 6 deletions lib/devos/mkHosts.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, dev, nixos, inputs, self, ... }:
{ lib, nixos, inputs, ... }:

{ dir, devos, extern, suites, overrides, multiPkgs, ... }:
{ self, dir, extern, suites, overrides, multiPkgs, ... }:
let
defaultSystem = "x86_64-linux";

Expand Down Expand Up @@ -44,7 +44,7 @@ let
nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system};

nix.registry = {
devos.flake = self;
self.flake = self;
nixos.flake = nixos;
override.flake = inputs.override;
};
Expand All @@ -61,7 +61,7 @@ let
# Everything in `./modules/list.nix`.
flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; };

cachix = "${devos}/cachix.nix";
cachix = "${self}/cachix.nix";
};

specialArgs = extern.specialArgs // { suites = suites.system; };
Expand All @@ -88,13 +88,13 @@ let
};
};
in
dev.os.devosSystem {
lib.os.devosSystem {
inherit specialArgs;
system = defaultSystem;
modules = modules // { inherit local lib; };
};

hosts = dev.os.recImport
hosts = lib.os.recImport
{
inherit dir;
_import = mkHostConfig;
Expand Down
4 changes: 2 additions & 2 deletions lib/devos/mkPackages.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ lib, dev, self, ... }:
{ lib, self, ... }:

{ pkgs }:
let
inherit (self) overlay overlays;
packagesNames = lib.attrNames (overlay null null)
++ lib.attrNames (dev.concatAttrs
++ lib.attrNames (lib.concatAttrs
(lib.attrValues
(lib.mapAttrs (_: v: v null null) overlays)
)
Expand Down
14 changes: 3 additions & 11 deletions lib/devos/mkPkgs.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
{ lib, dev, nixos, self, inputs, ... }:
{ lib, nixos, self, inputs, ... }:

{ extern, overrides }:
(inputs.utils.lib.eachDefaultSystem
(system:
let
overridePkgs = dev.os.pkgImport inputs.override [ ] system;
overridePkgs = lib.os.pkgImport inputs.override [ ] system;
overridesOverlay = overrides.packages;

overlays = [
(final: prev: {
lib = prev.lib.extend (lfinal: lprev: {
inherit dev;
inherit (lib) nixosSystem;

utils = inputs.utils.lib;
});
})
(overridesOverlay overridePkgs)
self.overlay
]
++ extern.overlays
++ (lib.attrValues self.overlays);
in
{ pkgs = dev.os.pkgImport nixos overlays system; }
{ pkgs = lib.os.pkgImport nixos overlays system; }
)
).pkgs
4 changes: 2 additions & 2 deletions lib/devos/mkProfileAttrs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, dev, ... }:
{ lib, ... }:

let mkProfileAttrs =
/**
Expand All @@ -16,7 +16,7 @@ let mkProfileAttrs =
let
imports =
let
files = dev.safeReadDir dir;
files = lib.safeReadDir dir;

p = n: v:
v == "directory"
Expand Down
5 changes: 2 additions & 3 deletions lib/devos/mkSuites.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{ lib, dev, ... }:
{ lib, ... }:

{ users, profiles, userProfiles, suites } @ args:
let
inherit (dev) os;

definedSuites = suites {
inherit (args) users profiles userProfiles;
Expand All @@ -16,7 +15,7 @@ let
let defaults = lib.collect (x: x ? default) users;
in map (x: x.default) defaults;

createSuites = _: suites: lib.mapAttrs (_: v: os.profileMap v) suites // {
createSuites = _: suites: lib.mapAttrs (_: v: lib.os.profileMap v) suites // {
inherit allProfiles allUsers;
};

Expand Down
6 changes: 3 additions & 3 deletions lib/devos/recImport.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{ lib, dev, ... }:
{ lib, ... }:

{ dir, _import ? base: import "${dir}/${base}.nix" }:
dev.mapFilterAttrs
lib.mapFilterAttrs
(_: v: v != null)
(n: v:
if n != "default.nix" && lib.hasSuffix ".nix" n && v == "regular"
then
let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name)
else
lib.nameValuePair ("") (null))
(dev.safeReadDir dir)
(lib.safeReadDir dir)
4 changes: 2 additions & 2 deletions lib/lists.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ lib, dev, ... }:
{ lib, ... }:
{
pathsIn = dir:
let
fullPath = name: "${toString dir}/${name}";
in
map fullPath (lib.attrNames (dev.safeReadDir dir));
map fullPath (lib.attrNames (lib.safeReadDir dir));
}
25 changes: 9 additions & 16 deletions lib/mkFlake/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
{ self, nixos, inputs, ... }:
{ lib, inputs, ... }:
let
devos = self;
inherit (lib) os; # TODO: find a more approriate naming scheme
inherit (inputs) utils deploy; # TODO: make this direct inputs of future devos-lib flake
evalFlakeArgs = lib.callLibs ./evalArgs.nix;
in

{ self, ... } @ args:
let
inherit (self) lib;
inherit (lib) os;

inherit (inputs) utils deploy;

cfg = (lib.evalFlakeArgs { inherit args; }).config;
cfg = (evalFlakeArgs { inherit args; }).config;

multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; };

outputs = {
nixosConfigurations = os.mkHosts {
inherit devos multiPkgs;
inherit self multiPkgs;
inherit (cfg) extern suites overrides;
dir = cfg.hosts;
};
Expand All @@ -30,11 +28,6 @@ let
overlay = cfg.packages;
inherit (cfg) overlays;

lib = import "${devos}/lib" {
inherit self nixos;
inputs = inputs // self.inputs;
};

deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
};

Expand All @@ -48,7 +41,7 @@ let
checks =
let
tests = nixos.lib.optionalAttrs (system == "x86_64-linux")
(import "${devos}/tests" { inherit pkgs; self = devos; });
(import "${self}/tests" { inherit self pkgs; });
deployHosts = nixos.lib.filterAttrs
(n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) self.deploy.nodes;
deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; };
Expand All @@ -58,10 +51,10 @@ let
inherit legacyPackages;
packages = lib.filterPackages system legacyPackages;

devShell = import "${devos}/shell" {
devShell = import "${self}/shell" {
inherit self system;
};
});
in
nixos.lib.recursiveUpdate outputs systemOutputs
outputs // systemOutputs

Loading