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"; nixos.url = "nixpkgs/nixos-unstable";
override.url = "nixpkgs"; 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 = { ci-agent = {
url = "github:hercules-ci/hercules-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"; }; 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.url = "github:LnL7/nix-darwin";
darwin.inputs.nixpkgs.follows = "override"; 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.url = "github:BBBSnowball/flake-compat/pr-1";
flake-compat.flake = false; flake-compat.flake = false;
home.url = "github:nix-community/home-manager"; home.url = "github:nix-community/home-manager";
@ -23,32 +28,27 @@
naersk.url = "github:nmattia/naersk"; naersk.url = "github:nmattia/naersk";
naersk.inputs.nixpkgs.follows = "override"; naersk.inputs.nixpkgs.follows = "override";
nixos-hardware.url = "github:nixos/nixos-hardware"; nixos-hardware.url = "github:nixos/nixos-hardware";
utils.url = "github:numtide/flake-utils";
pkgs.url = "path:./pkgs"; pkgs.url = "path:./pkgs";
pkgs.inputs.nixpkgs.follows = "nixos"; pkgs.inputs.nixpkgs.follows = "nixos";
}; };
outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: outputs = inputs@{ self, devos, nixos, nur, ... }:
let devos.lib.mkFlake {
lib = import ./lib { inherit self nixos utils inputs; }; inherit self;
in hosts = ./hosts;
lib.mkFlake packages = import ./pkgs;
{ suites = import ./suites;
inherit self; extern = import ./extern;
hosts = ./hosts; overrides = import ./overrides;
packages = import ./pkgs; overlays = ./overlays;
suites = import ./suites; profiles = ./profiles;
extern = import ./extern; userProfiles = ./users/profiles;
overrides = import ./overrides; modules = import ./modules/module-list.nix;
overlays = ./overlays; userModules = import ./users/modules/module-list.nix;
profiles = ./profiles; } // {
userProfiles = ./users/profiles; defaultTemplate = self.templates.flk;
modules = import ./modules/module-list.nix; templates.flk.path = ./.;
userModules = import ./users/modules/module-list.nix; templates.flk.description = "flk template";
} // { };
inherit lib;
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 -> Pkgs
pkgImport = nixpkgs: overlays: system: pkgImport = nixpkgs: overlays: system:

View File

@ -1,4 +1,4 @@
{ lib, nixos, self, inputs, ... }: { lib, nixpkgs, self, inputs, ... }:
{ modules, ... } @ args: { modules, ... } @ args:
lib.nixosSystem (args // { lib.nixosSystem (args // {
@ -13,7 +13,7 @@ lib.nixosSystem (args // {
(args // { (args // {
modules = moduleList ++ [ 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, ... }: { ({ config, suites, ... }: {

View File

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

View File

@ -1,4 +1,4 @@
{ lib, dev, nixos, self, inputs, ... }: { lib, dev, nixpkgs, self, inputs, ... }:
{ extern, overrides }: { extern, overrides }:
(inputs.utils.lib.eachDefaultSystem (inputs.utils.lib.eachDefaultSystem
@ -22,6 +22,6 @@
++ extern.overlays ++ extern.overlays
++ (lib.attrValues self.overlays); ++ (lib.attrValues self.overlays);
in in
{ pkgs = dev.os.pkgImport nixos overlays system; } { pkgs = dev.os.pkgImport nixpkgs overlays system; }
) )
).pkgs ).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 let
inherit (dev) os; inherit (dev) os;
inherit (inputs) utils deploy; inherit (inputs) utils deploy;

View File

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

View File

@ -1,8 +1,8 @@
{ self, dev, nixos, inputs, ... }: { self, dev, lib, inputs, ... }:
{ args }: { args }:
let let
argOpts = with nixos.lib; { config, options, ... }: argOpts = with lib; { config, options, ... }:
let let
inherit (dev) os; inherit (dev) os;
@ -17,7 +17,7 @@ let
{ {
options = with types; { options = with types; {
self = mkOption { self = mkOption {
type = addCheck attrs nixos.lib.isStorePath; type = addCheck attrs lib.isStorePath;
description = "The flake to create the devos outputs for"; description = "The flake to create the devos outputs for";
}; };
hosts = mkOption { hosts = mkOption {
@ -149,6 +149,6 @@ let
}; };
}; };
in in
nixos.lib.evalModules { lib.evalModules {
modules = [ argOpts args ]; 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.genAttrs utils.lib.defaultSystems (system:
lib.makeExtensible (final: lib.makeExtensible (final:
let let
pkgs = import nixos { inherit system; }; pkgs = import nixpkgs { inherit system; };
callLibs = file: import file callLibs = file: import file
(args // { (args // {
inherit pkgs system; inherit pkgs system;

View File

@ -1,4 +1,4 @@
{ lib, dev, inputs, system, nixos, ... }: { lib, dev, inputs, system, nixpkgs, ... }:
let let
overlays = [ overlays = [
inputs.devshell.overlay 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 { }; flk = pkgs.callPackage ./flk.nix { };

View File

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

View File

@ -1,11 +1,11 @@
{ pkgs, lib, dev, ... }: { pkgs, lib }:
pkgs.runCommandNoCC "devos-lib-tests" pkgs.runCommandNoCC "devos-lib-tests"
{ {
buildInputs = [ buildInputs = [
pkgs.nix 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 if tests == [ ] then null
else throw (builtins.toJSON tests) else throw (builtins.toJSON tests)
) )

View File

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