ref: extract lib into subflake

This commit is contained in:
David Arnold 2021-04-01 21:10:24 -05:00
parent 863c17621c
commit 5f89d27428
15 changed files with 131 additions and 91 deletions

View File

@ -5,17 +5,22 @@
{
nixos.url = "nixpkgs/nixos-unstable";
override.url = "nixpkgs";
devos.url = "path:./lib"; # TODO: outfactor into separate repo
devos.inputs = {
nixpkgs.follows = "nixos";
deploy.inputs = {
flake-compat.follows = "flake-compat";
naersk.follows = "naersk";
nixpkgs.follows = "nixos";
};
};
ci-agent = {
url = "github:hercules-ci/hercules-ci-agent";
inputs = { nix-darwin.follows = "darwin"; flake-compat.follows = "flake-compat"; nixos-20_09.follows = "nixos"; nixos-unstable.follows = "override"; };
};
darwin.url = "github:LnL7/nix-darwin";
darwin.inputs.nixpkgs.follows = "override";
deploy = {
url = "github:serokell/deploy-rs";
inputs = { flake-compat.follows = "flake-compat"; naersk.follows = "naersk"; nixpkgs.follows = "override"; utils.follows = "utils"; };
};
devshell.url = "github:numtide/devshell";
flake-compat.url = "github:BBBSnowball/flake-compat/pr-1";
flake-compat.flake = false;
home.url = "github:nix-community/home-manager";
@ -23,32 +28,27 @@
naersk.url = "github:nmattia/naersk";
naersk.inputs.nixpkgs.follows = "override";
nixos-hardware.url = "github:nixos/nixos-hardware";
utils.url = "github:numtide/flake-utils";
pkgs.url = "path:./pkgs";
pkgs.inputs.nixpkgs.follows = "nixos";
};
outputs = inputs@{ deploy, nixos, nur, self, utils, ... }:
let
lib = import ./lib { inherit self nixos utils 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;
} // {
inherit lib;
defaultTemplate = self.templates.flk;
templates.flk.path = ./.;
templates.flk.description = "flk template";
};
outputs = inputs@{ self, devos, nixos, nur, ... }:
devos.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";
};
}

View File

@ -1,32 +0,0 @@
args@{ nixos, self, ... }:
let inherit (nixos) lib; in
lib.makeExtensible (final:
let callLibs = file: import file
({
inherit lib;
dev = final;
} // args);
in
with final;
{
inherit callLibs;
attrs = callLibs ./attrs.nix;
os = callLibs ./devos;
lists = callLibs ./lists.nix;
strings = callLibs ./strings.nix;
mkFlake = {
__functor = callLibs ./mkFlake;
evalArgs = callLibs ./mkFlake/evalArgs.nix;
evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix;
};
pkgs-lib = callLibs ./pkgs-lib;
inherit (attrs) mapFilterAttrs genAttrs' safeReadDir
pathsToImportedAttrs concatAttrs filterPackages;
inherit (lists) pathsIn;
inherit (strings) rgxToString;
})

View File

@ -1,4 +1,4 @@
{ lib, nixos, dev, ... }:
{ lib, dev, ... }:
{
# pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs
pkgImport = nixpkgs: overlays: system:

View File

@ -1,4 +1,4 @@
{ lib, nixos, self, inputs, ... }:
{ lib, nixpkgs, self, inputs, ... }:
{ modules, ... } @ args:
lib.nixosSystem (args // {
@ -13,7 +13,7 @@ lib.nixosSystem (args // {
(args // {
modules = moduleList ++ [
"${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix"
"${nixpkgs}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix"
({ config, suites, ... }: {

View File

@ -1,4 +1,4 @@
{ lib, dev, nixos, inputs, self, ... }:
{ lib, dev, nixpkgs, inputs, self, ... }:
{ dir, extern, suites, overrides, multiPkgs, ... }:
let
@ -36,7 +36,7 @@ let
hardware.enableRedistributableFirmware = lib.mkDefault true;
nix.nixPath = [
"nixpkgs=${nixos}"
"nixpkgs=${nixpkgs}"
"nixos-config=${self}/compat/nixos"
"home-manager=${inputs.home}"
];
@ -45,7 +45,7 @@ let
nix.registry = {
devos.flake = self;
nixos.flake = nixos;
nixos.flake = nixpkgs;
override.flake = inputs.override;
};

View File

@ -1,4 +1,4 @@
{ lib, dev, nixos, self, inputs, ... }:
{ lib, dev, nixpkgs, self, inputs, ... }:
{ extern, overrides }:
(inputs.utils.lib.eachDefaultSystem
@ -22,6 +22,6 @@
++ extern.overlays
++ (lib.attrValues self.overlays);
in
{ pkgs = dev.os.pkgImport nixos overlays system; }
{ pkgs = dev.os.pkgImport nixpkgs overlays system; }
)
).pkgs

72
lib/flake.nix Normal file
View File

@ -0,0 +1,72 @@
{
description = "DevOS environment configuriguration library.";
inputs =
{
deploy.url = "github:serokell/deploy-rs";
deploy.inputs = {
utils.follows = "flake-utils";
};
devshell.url = "github:numtide/devshell";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = inputs@{ self, nixpkgs, deploy, devshell, flake-utils, ... }: let
inherit (nixpkgs) lib;
# We work with a combined lib, internally ...
combinedLib = lib.extend (final: prev:
let callLibs = file: import file
({
lib = final;
dev = final;
inputs = inputs;
} // inputs);
in
with final;
{
inherit callLibs;
attrs = callLibs ./attrs.nix;
os = callLibs ./devos;
lists = callLibs ./lists.nix;
strings = callLibs ./strings.nix;
mkFlake = {
__functor = callLibs ./mkFlake;
evalArgs = callLibs ./mkFlake/evalArgs.nix;
evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix;
};
pkgs-lib = callLibs ./pkgs-lib;
inherit (attrs) mapFilterAttrs genAttrs' safeReadDir
pathsToImportedAttrs concatAttrs filterPackages;
inherit (lists) pathsIn;
inherit (strings) rgxToString;
});
in {
# ... but don't force that choice onto the user
lib = {
mkFlake = combinedLib.mkFlake;
pkgs-lib = combinedLib.pkgs-lib;
};
checks = flake-utils.lib.eachDefaultSystem (system: let
nixpkgs = import nixpkgs { inherit system; overlays = []; config = {}; };
in
{
tests = import ./tests {
inherit (nixpkgs) pkgs;
inherit (self) lib;
};
}
);
};
}

View File

@ -1,4 +1,4 @@
{ dev, nixos, inputs, ... }:
{ dev, inputs, ... }:
let
inherit (dev) os;
inherit (inputs) utils deploy;

View File

@ -1,8 +1,8 @@
{ self, dev, nixos, inputs, utils, ... }:
{ self, dev, lib, inputs, utils, ... }:
{ args }:
let
argOpts = with nixos.lib; { config, ... }:
argOpts = with lib; { config, ... }:
let
inherit (dev) os;
@ -25,7 +25,7 @@ let
description = "valid Nixpkgs overlay";
};
systemType = types.enum config.supportedSystems;
flakeType = with types; (addCheck attrs nixos.lib.isStorePath) // {
flakeType = with types; (addCheck attrs lib.isStorePath) // {
description = "nix flake";
};
@ -54,10 +54,10 @@ let
options = with types; {
input = mkOption {
type = flakeType;
default = inputs.nixos;
default = inputs.nixpkgs;
description = ''
nixpkgs flake input to use for this channel
'';
'';
};
overlays = mkOption {
type = pathTo (listOf overlayType);
@ -199,7 +199,7 @@ let
let
default = {
nixpkgs = {
input = inputs.nixos;
input = inputs.nixpkgs;
};
};
in
@ -228,6 +228,6 @@ let
};
};
in
nixos.lib.evalModules {
lib.evalModules {
modules = [ argOpts args ];
}

View File

@ -1,8 +1,8 @@
{ self, dev, nixos, inputs, ... }:
{ self, dev, lib, inputs, ... }:
{ args }:
let
argOpts = with nixos.lib; { config, options, ... }:
argOpts = with lib; { config, options, ... }:
let
inherit (dev) os;
@ -17,7 +17,7 @@ let
{
options = with types; {
self = mkOption {
type = addCheck attrs nixos.lib.isStorePath;
type = addCheck attrs lib.isStorePath;
description = "The flake to create the devos outputs for";
};
hosts = mkOption {
@ -149,6 +149,6 @@ let
};
};
in
nixos.lib.evalModules {
lib.evalModules {
modules = [ argOpts args ];
}

View File

@ -1,8 +1,8 @@
args@{ lib, dev, utils, nixos, ... }:
args@{ lib, dev, utils, nixpkgs, ... }:
lib.genAttrs utils.lib.defaultSystems (system:
lib.makeExtensible (final:
let
pkgs = import nixos { inherit system; };
pkgs = import nixpkgs { inherit system; };
callLibs = file: import file
(args // {
inherit pkgs system;

View File

@ -1,4 +1,4 @@
{ lib, dev, inputs, system, nixos, ... }:
{ lib, dev, inputs, system, nixpkgs, ... }:
let
overlays = [
inputs.devshell.overlay
@ -8,7 +8,7 @@ let
})
];
pkgs = dev.os.pkgImport nixos overlays system;
pkgs = dev.os.pkgImport nixpkgs overlays system;
flk = pkgs.callPackage ./flk.nix { };

View File

@ -1,4 +1,4 @@
{ pkgs, system, inputs, nixos, lib, ... }:
{ pkgs, system, inputs, nixpkgs, lib, ... }:
let
mkChecks = { hosts, nodes, homes ? { } }:
let
@ -17,7 +17,7 @@ let
mkTest = host:
let
nixosTesting =
(import "${nixos}/nixos/lib/testing-python.nix" {
(import "${nixpkgs}/nixos/lib/testing-python.nix" {
inherit system;
inherit (host.config.lib) specialArgs;
inherit pkgs;

View File

@ -1,11 +1,11 @@
{ pkgs, lib, dev, ... }:
{ pkgs, lib }:
pkgs.runCommandNoCC "devos-lib-tests"
{
buildInputs = [
pkgs.nix
(
let tests = import ./lib.nix { inherit pkgs lib dev; }; in
let tests = import ./lib.nix { inherit pkgs lib; }; in
if tests == [ ] then null
else throw (builtins.toJSON tests)
)

View File

@ -1,5 +1,5 @@
{ pkgs, lib, dev, ... }:
with dev;
{ pkgs, lib }:
with lib;
lib.runTests {
testConcatAttrs = {
expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }];