Merge pull request #251 from divnix/api-next

Intermediate version of api-next
This commit is contained in:
David Arnold 2021-04-21 19:02:51 -05:00 committed by GitHub
commit a44fcf6d9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 871 additions and 344 deletions

4
extern/default.nix vendored
View file

@ -7,10 +7,6 @@
overlays = [
nur.overlay
devshell.overlay
(final: prev: {
deploy-rs = deploy.packages.${prev.system}.deploy-rs;
})
pkgs.overlay
];

View file

@ -52,25 +52,17 @@
},
"deploy": {
"inputs": {
"flake-compat": [
"flake-compat"
],
"naersk": [
"naersk"
],
"nixpkgs": [
"override"
],
"utils": [
"utils"
]
"flake-compat": "flake-compat",
"naersk": "naersk",
"nixpkgs": "nixpkgs",
"utils": "utils"
},
"locked": {
"lastModified": 1614654775,
"narHash": "sha256-3mLxoxIXSWUuKE8YgIuqM5AZzXFd1aWxkTlplEDeXIA=",
"lastModified": 1616406726,
"narHash": "sha256-n9zmgxR03QNrvs9/fHewqE0j3SjL7Y+cglBCFu3U3rg=",
"owner": "serokell",
"repo": "deploy-rs",
"rev": "6278b9bef5ad624676a565980417cbbef42d5227",
"rev": "9e405fbc5ab5bacbd271fd78c6b6b6877c4d9f8d",
"type": "github"
},
"original": {
@ -79,13 +71,32 @@
"type": "github"
}
},
"devos": {
"inputs": {
"deploy": "deploy",
"devshell": "devshell",
"nixpkgs": [
"nixos"
],
"utils": "utils_2"
},
"locked": {
"narHash": "sha256-aGpcPxOBIPnwj6uLNtpKefZjEbDkZnMHZ2mH12veHnY=",
"path": "./lib",
"type": "path"
},
"original": {
"path": "./lib",
"type": "path"
}
},
"devshell": {
"locked": {
"lastModified": 1613641255,
"narHash": "sha256-iSvjFK4WYAKhuXCCtkY7uy/cFQTzS3D3Ml5WZqjEfL0=",
"lastModified": 1618523768,
"narHash": "sha256-Gev9da35pHUey3kGz/zrJFc/9ICs++vPCho7qB1mqd8=",
"owner": "numtide",
"repo": "devshell",
"rev": "ff6cffba08600f5b7b43f398fcb58bef023bc4c4",
"rev": "709fe4d04a9101c9d224ad83f73416dce71baf21",
"type": "github"
},
"original": {
@ -95,6 +106,22 @@
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1606424373,
"narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1611461076,
@ -132,6 +159,27 @@
}
},
"naersk": {
"inputs": {
"nixpkgs": [
"override"
]
},
"locked": {
"lastModified": 1610392286,
"narHash": "sha256-3wFl5y+4YZO4SgRYK8WE7JIS3p0sxbgrGaQ6RMw+d98=",
"owner": "nmattia",
"repo": "naersk",
"rev": "d7bfbad3304fd768c0f93a4c3b50976275e6d4be",
"type": "github"
},
"original": {
"owner": "nmattia",
"ref": "master",
"repo": "naersk",
"type": "github"
}
},
"naersk_2": {
"inputs": {
"nixpkgs": [
"override"
@ -181,6 +229,22 @@
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1610942247,
"narHash": "sha256-PKo1ATAlC6BmfYSRmX0TVmNoFbrec+A5OKcabGEu2yU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "7d71001b796340b219d1bfa8552c81995017544a",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nur": {
"locked": {
"lastModified": 1615921934,
@ -245,26 +309,39 @@
"inputs": {
"ci-agent": "ci-agent",
"darwin": "darwin",
"deploy": "deploy",
"devshell": "devshell",
"flake-compat": "flake-compat",
"devos": "devos",
"flake-compat": "flake-compat_2",
"home": "home",
"naersk": "naersk",
"naersk": "naersk_2",
"nixos": "nixos",
"nixos-hardware": "nixos-hardware",
"nur": "nur",
"override": "override",
"pkgs": "pkgs",
"utils": "utils"
"pkgs": "pkgs"
}
},
"utils": {
"locked": {
"lastModified": 1614513358,
"narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=",
"lastModified": 1610051610,
"narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5466c5bbece17adaab2d82fae80b46e807611bf3",
"rev": "3982c9903e93927c2164caa727cd3f6a0e6d14cc",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"utils_2": {
"locked": {
"lastModified": 1618217525,
"narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544",
"type": "github"
},
"original": {

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,18 +28,14 @@
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;
outputs = inputs@{ self, devos, nixos, nur, ... }:
devos.lib.mkFlake {
inherit self inputs nixos;
hosts = ./hosts;
packages = import ./pkgs;
suites = import ./profiles/suites.nix;
@ -46,7 +47,6 @@
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";

View file

@ -1,4 +1,4 @@
{ lib, ... }:
{ lib }:
rec {
# mapFilterAttrs ::
# (name -> value -> bool )

View file

@ -1,28 +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 = callLibs ./mkFlake;
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, utils }:
{
# pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs
pkgImport = nixpkgs: overlays: system:
@ -9,22 +9,22 @@
profileMap = list: map (profile: profile.default) (lib.flatten list);
mkNodes = dev.callLibs ./mkNodes.nix;
mkNodes = import ./mkNodes.nix { inherit lib; };
mkHosts = dev.callLibs ./mkHosts.nix;
mkHosts = import ./mkHosts.nix { inherit lib; };
mkSuites = dev.callLibs ./mkSuites.nix;
mkSuites = import ./mkSuites.nix { inherit lib; };
mkProfileAttrs = dev.callLibs ./mkProfileAttrs.nix;
mkProfileAttrs = import ./mkProfileAttrs.nix { inherit lib; };
mkPkgs = dev.callLibs ./mkPkgs.nix;
mkPkgs = import ./mkPkgs.nix { inherit lib utils; };
recImport = dev.callLibs ./recImport.nix;
recImport = import ./recImport.nix { inherit lib; };
devosSystem = dev.callLibs ./devosSystem.nix;
devosSystem = import ./devosSystem.nix { inherit lib; };
mkHomeConfigurations = dev.callLibs ./mkHomeConfigurations.nix;
mkHomeConfigurations = import ./mkHomeConfigurations.nix { inherit lib; };
mkPackages = dev.callLibs ./mkPackages.nix;
mkPackages = import ./mkPackages.nix { inherit lib; };
}

View file

@ -1,4 +1,6 @@
{ lib, nixos, self, inputs, ... }:
{ lib }:
{ userFlakeNixOS, userFlakeSelf, userFlakeInputs }:
{ modules, ... } @ args:
lib.nixosSystem (args // {
@ -13,7 +15,7 @@ lib.nixosSystem (args // {
(args // {
modules = moduleList ++ [
"${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix"
"${userFlakeNixOS}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix"
({ config, suites, ... }: {
@ -23,15 +25,15 @@ lib.nixosSystem (args // {
disabledModules = map (x: [ x ])
(lib.remove modules.core suites.allProfiles);
nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs;
nix.registry = lib.mapAttrs (n: v: { flake = v; }) userFlakeInputs;
isoImage.isoBaseName = "nixos-" + config.networking.hostName;
isoImage.contents = [{
source = self;
source = userFlakeSelf;
target = "/devos/";
}];
isoImage.storeContents = [
self.devShell.${config.nixpkgs.system}
userFlakeSelf.devShell.${config.nixpkgs.system}
# include also closures that are "switched off" by the
# above profile filter on the local config attribute
fullHostConfig.system.build.toplevel

View file

@ -1,4 +1,6 @@
{ lib, self, ... }:
{ lib }:
{ userFlakeSelf }:
with lib;
let
@ -6,7 +8,7 @@ let
mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home)
config.config.system.build.homes;
hmConfigs = mapAttrs mkHomes self.nixosConfigurations;
hmConfigs = mapAttrs mkHomes userFlakeSelf.nixosConfigurations;
in
foldl recursiveUpdate { } (attrValues hmConfigs)

View file

@ -1,6 +1,8 @@
{ lib, dev, nixos, inputs, self, ... }:
{ lib }:
{ dir, extern, suites, overrides, multiPkgs, ... }:
{ userFlakeNixOS, userFlakeInputs, userFlakeSelf }:
{ dir, extern, suites, overrides, multiPkgs }:
let
defaultSystem = "x86_64-linux";
@ -29,24 +31,24 @@ let
useUserPackages = true;
extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; };
sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules);
sharedModules = extern.userModules ++ (builtins.attrValues userFlakeSelf.homeModules);
};
users.mutableUsers = lib.mkDefault false;
hardware.enableRedistributableFirmware = lib.mkDefault true;
nix.nixPath = [
"nixpkgs=${nixos}"
"nixos-config=${self}/lib/compat/nixos"
"home-manager=${inputs.home}"
"nixpkgs=${userFlakeNixOS}"
"nixos-config=${userFlakeSelf}/lib/compat/nixos"
"home-manager=${userFlakeInputs.home}"
];
nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system};
nix.registry = {
devos.flake = self;
nixos.flake = nixos;
override.flake = inputs.override;
devos.flake = userFlakeSelf;
nixos.flake = userFlakeNixOS;
override.flake = userFlakeInputs.override;
};
nix.package = pkgs.nixFlakes;
@ -57,13 +59,13 @@ let
}
'';
system.configurationRevision = lib.mkIf (self ? rev) self.rev;
system.configurationRevision = lib.mkIf (userFlakeSelf ? rev) userFlakeSelf.rev;
};
# Everything in `./modules/list.nix`.
flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; };
flakeModules = { imports = builtins.attrValues userFlakeSelf.nixosModules ++ extern.modules; };
cachix = let rootCachix = ../../cachix.nix; in
cachix = let rootCachix = "${userFlakeSelf}/cachix.nix"; in
if builtins.pathExists rootCachix
then rootCachix
else { }
@ -82,25 +84,27 @@ let
networking = { inherit hostName; };
_module.args = {
inherit self;
self = userFlakeSelf;
hosts = builtins.mapAttrs (_: host: host.config)
(removeAttrs hosts [ hostName ]);
};
};
lib = {
lib = { inherit specialArgs; };
lib.testModule = {
imports = builtins.attrValues modules;
};
};
in
dev.os.devosSystem {
lib.os.devosSystem {
inherit userFlakeNixOS userFlakeInputs userFlakeSelf;
} {
inherit specialArgs;
system = defaultSystem;
modules = modules // { inherit local lib; };
modules = modules // { inherit local; };
};
hosts = dev.os.recImport
hosts = lib.os.recImport
{
inherit dir;
_import = mkHostConfig;

View file

@ -1,4 +1,4 @@
{ lib, ... }:
{ lib }:
/**
Synopsis: mkNodes _nixosConfigurations_

View file

@ -1,10 +1,12 @@
{ lib, dev, self, ... }:
{ lib }:
{ userFlakeSelf }:
{ pkgs }:
let
inherit (self) overlay overlays;
inherit (userFlakeSelf) 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)
)

View file

@ -1,27 +1,27 @@
{ lib, dev, nixos, self, inputs, ... }:
{ lib, utils }:
{ userFlakeNixOS, userFlakeSelf, userFlakeInputs }:
{ extern, overrides }:
(inputs.utils.lib.eachDefaultSystem
(utils.lib.eachDefaultSystem
(system:
let
overridePkgs = dev.os.pkgImport inputs.override [ ] system;
overridePkgs = lib.os.pkgImport userFlakeInputs.override [ ] system;
overridesOverlay = overrides.packages;
overlays = [
(final: prev: {
lib = prev.lib.extend (lfinal: lprev: {
inherit dev;
inherit lib;
inherit (lib) nixosSystem;
utils = inputs.utils.lib;
});
})
(overridesOverlay overridePkgs)
self.overlay
userFlakeSelf.overlay
]
++ extern.overlays
++ (lib.attrValues self.overlays);
++ (lib.attrValues userFlakeSelf.overlays);
in
{ pkgs = dev.os.pkgImport nixos overlays system; }
{ pkgs = lib.os.pkgImport userFlakeNixOS overlays system; }
)
).pkgs

View file

@ -1,4 +1,4 @@
{ lib, dev, ... }:
{ lib }:
let mkProfileAttrs =
/**
@ -16,7 +16,7 @@ let mkProfileAttrs =
let
imports =
let
files = dev.safeReadDir dir;
files = lib.safeReadDir dir;
p = n: v:
v == "directory"

View file

@ -1,8 +1,8 @@
{ lib, dev, ... }:
{ lib }:
{ users, profiles, userProfiles, suites } @ args:
let
inherit (dev) os;
inherit (lib) os;
definedSuites = suites {
inherit (args) users profiles userProfiles;

View file

@ -1,7 +1,7 @@
{ 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"
@ -9,4 +9,4 @@ dev.mapFilterAttrs
let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name)
else
lib.nameValuePair ("") (null))
(dev.safeReadDir dir)
(lib.safeReadDir dir)

90
lib/flake.nix Normal file
View file

@ -0,0 +1,90 @@
{
description = "DevOS environment configuriguration library.";
inputs =
{
deploy.url = "github:serokell/deploy-rs";
deploy.inputs = {
utils.follows = "utils";
};
devshell.url = "github:numtide/devshell";
utils.url = "github:numtide/flake-utils";
};
outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let
lib = nixpkgs.lib.makeExtensible (self:
let
attrs = import ./attrs.nix { lib = nixpkgs.lib // self; };
lists = import ./lists.nix { lib = nixpkgs.lib // self; };
strings = import ./strings.nix { lib = nixpkgs.lib // self; };
in
utils.lib
//
{
os = import ./devos {
lib = nixpkgs.lib // self;
inherit utils;
};
mkFlake = {
__functor = import ./mkFlake {
lib = nixpkgs.lib // self;
inherit deploy;
};
evalArgs = import ./mkFlake/evalArgs.nix { lib = nixpkgs.lib // self; };
evalOldArgs = import ./mkFlake/evalOldArgs.nix { lib = nixpkgs.lib // self; };
};
pkgs-lib = import ./pkgs-lib {
lib = nixpkgs.lib // self;
inherit nixpkgs deploy devshell;
};
inherit (attrs)
mapFilterAttrs
genAttrs'
safeReadDir
pathsToImportedAttrs
concatAttrs
filterPackages;
inherit (lists) pathsIn;
inherit (strings) rgxToString;
}
);
jobs = import ./jobs { inherit nixpkgs; lib = nixpkgs.lib // lib; };
in
{
inherit jobs;
lib = utils.lib // {
inherit (lib)
mkFlake;
};
}
//
utils.lib.eachDefaultSystem (system:
let
nixpkgs' = import nixpkgs { inherit system; overlays = []; config = {}; };
in
{
checks = {
tests = import ./tests {
inherit (nixpkgs') pkgs;
lib = nixpkgs.lib // lib;
};
};
}
);
}

5
lib/jobs/default.nix Normal file
View file

@ -0,0 +1,5 @@
{ nixpkgs, lib, system ? "x86_64-linux" }: let
pkgs = import nixpkgs { inherit system; overlays = []; config = {}; };
in {
mkFlakeDoc = import ./mkFlakeDoc.nix { inherit pkgs lib; };
}

35
lib/jobs/mkFlakeDoc.nix Normal file
View file

@ -0,0 +1,35 @@
{ pkgs, lib, ... }:
let
singleDoc = name: value: ''
## ${name}
${value.description}
${lib.optionalString (value ? type) ''
*_Type_*:
${value.type}
''}
${lib.optionalString (value ? default) ''
*_Default_*
```
${builtins.toJSON value.default}
```
''}
${lib.optionalString (value ? example) ''
*_Example_*
```
${value.example}
```
''}
'';
options = (
lib.mkFlake.evalArgs
{ userFlakeSelf = {}; userFlakeNixOS = {}; }
{ args = { }; }
).options;
processedOptions = (pkgs.nixosOptionsDoc { inherit options; }).optionsNix;
fullDoc = lib.concatStringsSep "" (lib.mapAttrsToList singleDoc processedOptions);
in
pkgs.writeText "devosOptions.md" fullDoc

View file

@ -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));
}

View file

@ -1,25 +1,36 @@
{ dev, nixos, inputs, ... }:
{ lib, deploy }:
let
inherit (dev) os;
inherit (inputs) utils deploy;
evalFlakeArgs = dev.callLibs ./evalArgs.nix;
inherit (lib) os;
in
{ self, ... } @ args:
_: { self, inputs, nixos, ... } @ args:
let
cfg = (evalFlakeArgs { inherit args; }).config;
userFlakeSelf = self;
userFlakeInputs = inputs;
userFlakeNixOS = nixos;
multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; };
cfg = (
lib.mkFlake.evalOldArgs
{ inherit userFlakeSelf userFlakeInputs; }
{ inherit args; }
).config;
multiPkgs = os.mkPkgs
{ inherit userFlakeSelf userFlakeInputs userFlakeNixOS; }
{ inherit (cfg) extern overrides; };
outputs = {
nixosConfigurations = os.mkHosts {
inherit self multiPkgs;
nixosConfigurations = os.mkHosts
{ inherit userFlakeSelf userFlakeInputs userFlakeNixOS; }
{
inherit multiPkgs;
inherit (cfg) extern suites overrides;
dir = cfg.hosts;
};
homeConfigurations = os.mkHomeConfigurations;
homeConfigurations = os.mkHomeConfigurations
{ inherit userFlakeSelf; };
nixosModules = cfg.modules;
@ -28,25 +39,27 @@ let
overlay = cfg.packages;
inherit (cfg) overlays;
deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
deploy.nodes = os.mkNodes deploy userFlakeSelf.nixosConfigurations;
};
systemOutputs = utils.lib.eachDefaultSystem (system:
systemOutputs = lib.eachDefaultSystem (system:
let
pkgs = multiPkgs.${system};
pkgs-lib = dev.pkgs-lib.${system};
pkgs-lib = lib.pkgs-lib.${system};
# all packages that are defined in ./pkgs
legacyPackages = os.mkPackages { inherit pkgs; };
legacyPackages = os.mkPackages
{ inherit userFlakeSelf; }
{ inherit pkgs; };
in
{
checks = pkgs-lib.tests.mkChecks {
inherit (self.deploy) nodes;
hosts = self.nixosConfigurations;
homes = self.homeConfigurations;
inherit (userFlakeSelf.deploy) nodes;
hosts = userFlakeSelf.nixosConfigurations;
homes = userFlakeSelf.homeConfigurations;
};
inherit legacyPackages;
packages = dev.filterPackages system legacyPackages;
packages = lib.filterPackages system legacyPackages;
devShell = pkgs-lib.shell;
});

View file

@ -1,154 +1,235 @@
{ self, dev, nixos, inputs, ... }:
{ lib }:
{ userFlakeSelf, userFlakeNixOS }:
{ args }:
let
argOpts = with nixos.lib; { config, options, ... }:
argOpts = with lib; { config, ... }:
let
inherit (dev) os;
inherit (lib) os;
inherit (config) self;
inputAttrs = with types; functionTo attrs;
maybeImport = obj:
if (builtins.typeOf obj == "path") || (builtins.typeOf obj == "string") then
import obj
else
obj;
/* Custom types needed for arguments */
moduleType = with types; anything // {
inherit (submodule { }) check;
description = "valid module";
};
overlayType = types.anything // {
check = builtins.isFunction;
description = "valid Nixpkgs overlay";
};
systemType = types.enum config.supportedSystems;
flakeType = with types; (addCheck attrs lib.isStorePath) // {
description = "nix flake";
};
# Applys maybeImport during merge and before check
# To simplify apply keys and improve type checking
pathTo = elemType: mkOptionType {
name = "pathTo";
description = "path that evaluates to a(n) ${elemType.name}";
check = x: elemType.check (maybeImport x);
merge = loc: defs:
(mergeDefinitions loc elemType (map
(x: {
inherit (x) file;
value = maybeImport x.value;
})
defs)).mergedValue;
getSubOptions = elemType.getSubOptions;
getSubModules = elemType.getSubModules;
substSubModules = m: pathTo (elemType.substSubModules m);
};
/* Submodules needed for API containers */
channelsModule = {
options = with types; {
input = mkOption {
type = flakeType;
default = userFlakeNixOS;
description = ''
nixpkgs flake input to use for this channel
'';
};
overlays = mkOption {
type = pathTo (listOf overlayType);
default = [ ];
description = ''
overlays to apply to this channel
these will get exported under the 'overlays' flake output as <channel>/<name>
'';
};
externalOverlays = mkOption {
type = pathTo (listOf overlayType);
default = [ ];
description = ''
overlays to apply to the channel that don't get exported to the flake output
useful to include overlays from inputs
'';
};
config = mkOption {
type = pathTo attrs;
default = { };
description = ''
nixpkgs config for this channel
'';
};
};
};
configModule = {
options = with types; {
system = mkOption {
type = systemType;
default = "x86_64-linux";
description = ''
system for this config
'';
};
channelName = mkOption {
type = types.enum (builtins.attrValues config.channels);
default = "nixpkgs";
description = ''
Channel this config should follow
'';
};
modules = mkOption {
type = pathTo moduleType;
default = [ ];
description = ''
The configuration for this config
'';
};
externalModules = mkOption {
type = pathTo moduleType;
default = [ ];
description = ''
The configuration for this config
'';
};
};
};
# Home-manager's configs get exported automatically from nixos.hosts
# So there is no need for a config options in the home namespace
# This is only needed for nixos
includeConfigsModule = { name, ... }: {
options = with types; {
configDefaults = mkOption {
type = submodule configModule;
default = { };
description = ''
defaults for all configs
'';
};
configs = mkOption {
type = pathTo (attrsOf (submodule configModule));
default = { };
description = ''
configurations to include in the ${name}Configurations output
'';
};
};
};
# Options to import: modules, profiles, suites
importsModule = { name, ... }: {
options = with types; {
modules = mkOption {
type = pathTo (listOf moduleType);
default = [ ];
apply = lib.pathsToImportedAttrs;
description = ''
list of modules to include in confgurations and export in '${name}Modules' output
'';
};
externalModules = mkOption {
type = pathTo (listOf moduleType);
default = [ ];
apply = lib.pathsToImportedAttrs;
description = ''
list of modules to include in confguration but these are not exported to the '${name}Modules' output
'';
};
profiles = mkOption {
type = path;
default = "${userFlakeSelf}/profiles";
defaultText = "\${userFlakeSelf}/profiles";
apply = x: os.mkProfileAttrs (toString x);
description = "path to profiles folder that can be collected into suites";
};
suites = mkOption {
type = pathTo (functionTo attrs);
default = _: { };
apply = suites: os.mkSuites {
inherit suites;
inherit (config) profiles;
};
description = ''
Function with the input of 'profiles' that returns an attribute set
with the suites for this config system.
These can be accessed through the 'suites' special argument.
'';
};
};
};
in
{
options = with types; {
self = mkOption {
type = addCheck attrs nixos.lib.isStorePath;
type = flakeType;
description = "The flake to create the devos outputs for";
};
hosts = mkOption {
type = path;
default = "${self}/hosts";
defaultText = "\${self}/hosts";
apply = toString;
supportedSystems = mkOption {
type = listOf str;
default = lib.defaultSystems;
description = ''
Path to directory containing host configurations that will be exported
to the 'nixosConfigurations' output.
The systems supported by this flake
'';
};
packages = mkOption {
# functionTo changes arg names which breaks flake check
type = types.anything // {
check = builtins.isFunction;
description = "Nixpkgs overlay";
};
default = (final: prev: { });
defaultText = "(final: prev: {})";
description = ''
Overlay for custom packages that will be included in treewide 'pkgs'.
This should follow the standard nixpkgs overlay format - two argument function
that returns an attrset.
These packages will be exported to the 'packages' and 'legacyPackages' outputs.
'';
};
modules = mkOption {
type = listOf moduleType;
default = [ ];
apply = dev.pathsToImportedAttrs;
description = ''
list of modules to include in confgurations and export in 'nixosModules' output
'';
};
userModules = mkOption {
type = listOf moduleType;
default = [ ];
apply = dev.pathsToImportedAttrs;
description = ''
list of modules to include in home-manager configurations and export in
'homeModules' output
'';
};
profiles = mkOption {
type = path;
default = "${self}/profiles";
defaultText = "\${self}/profiles";
apply = x: os.mkProfileAttrs (toString x);
description = "path to profiles folder that can be collected into suites";
};
userProfiles = mkOption {
type = path;
default = "${self}/users/profiles";
defaultText = "\${self}/users/profiles";
apply = x: os.mkProfileAttrs (toString x);
description = "path to user profiles folder that can be collected into userSuites";
};
suites =
channels =
let
defaults = { user = { }; system = { }; };
in
mkOption {
type = inputAttrs;
default = { ... }: defaults;
defaultText = "{ user = {}; system = {}; }";
apply = suites: defaults // os.mkSuites {
inherit suites;
inherit (config) profiles users userProfiles;
default = {
nixpkgs = {
input = userFlakeNixOS;
};
description = ''
Function with inputs 'users' and 'profiles' that returns attribute set
with user and system suites. The former for Home Manager and the latter
for nixos configurations.
These can be accessed through the 'suites' specialArg in each config system.
'';
};
users = mkOption {
type = path;
default = "${self}/users";
defaultText = "\${self}/users";
apply = x: os.mkProfileAttrs (toString x);
description = ''
path to folder containing profiles that define system users
'';
};
extern =
let
defaults = {
modules = [ ];
overlays = [ ];
specialArgs = { };
userModules = [ ];
userSpecialArgs = { };
};
in
mkOption {
type = inputAttrs;
default = { ... }: defaults;
defaultText = ''
{ modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; }
'';
# So unneeded extern attributes can safely be deleted
apply = x: defaults // (x { inputs = inputs // self.inputs; });
description = ''
Function with argument 'inputs' that contains all devos and ''${self}'s inputs.
The function should return an attribute set with modules, overlays, and
specialArgs to be included across nixos and home manager configurations.
Only attributes that are used should be returned.
'';
};
overlays = mkOption {
type = path;
default = "${self}/overlays";
defaultText = "\${self}/overlays";
apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x));
description = ''
path to folder containing overlays which will be applied to pkgs and exported in
the 'overlays' output
'';
};
overrides = mkOption rec {
type = attrs;
default = { modules = [ ]; disabledModules = [ ]; packages = _: _: _: { }; };
defaultText = "{ modules = []; disabledModules = []; packages = {}; }";
type = attrsOf (submodule channelsModule);
inherit default;
apply = x: default // x;
description = "attrset of packages and modules that will be pulled from nixpkgs master";
description = ''
nixpkgs channels to create
'';
};
nixos = mkOption {
type = submodule [ includeConfigsModule importsModule ];
default = { };
description = ''
hosts, modules, suites, and profiles for nixos
'';
};
home = mkOption {
type = submodule importsModule;
default = { };
description = ''
hosts, modules, suites, and profiles for home-manager
'';
};
};
};
in
nixos.lib.evalModules {
lib.evalModules {
modules = [ argOpts args ];
}

164
lib/mkFlake/evalOldArgs.nix Normal file
View file

@ -0,0 +1,164 @@
{ lib }:
{ userFlakeSelf, userFlakeInputs }:
{ args }:
let
argOpts = with lib; { config, options, ... }:
let
inherit (lib) os;
inherit (config) self;
inputAttrs = with types; functionTo attrs;
moduleType = with types; anything // {
inherit (submodule { }) check;
description = "valid module";
};
in
{
options = with types; {
self = mkOption {
type = addCheck attrs lib.isStorePath;
description = "The flake to create the devos outputs for";
};
nixos = mkOption {
type = addCheck attrs lib.isStorePath;
description = "The default nixpkgs channel of the devos";
};
inputs = mkOption {
type = addCheck attrs lib.isStorePath;
description = "All inptus of the devos";
};
hosts = mkOption {
type = path;
default = "${userFlakeSelf}/hosts";
defaultText = "\${userFlakeSelf}/hosts";
apply = toString;
description = ''
Path to directory containing host configurations that will be exported
to the 'nixosConfigurations' output.
'';
};
packages = mkOption {
# functionTo changes arg names which breaks flake check
type = types.anything // {
check = builtins.isFunction;
description = "Nixpkgs overlay";
};
default = (final: prev: { });
defaultText = "(final: prev: {})";
description = ''
Overlay for custom packages that will be included in treewide 'pkgs'.
This should follow the standard nixpkgs overlay format - two argument function
that returns an attrset.
These packages will be exported to the 'packages' and 'legacyPackages' outputs.
'';
};
modules = mkOption {
type = listOf moduleType;
default = [ ];
apply = lib.pathsToImportedAttrs;
description = ''
list of modules to include in confgurations and export in 'nixosModules' output
'';
};
userModules = mkOption {
type = listOf moduleType;
default = [ ];
apply = lib.pathsToImportedAttrs;
description = ''
list of modules to include in home-manager configurations and export in
'homeModules' output
'';
};
profiles = mkOption {
type = path;
default = "${userFlakeSelf}/profiles";
defaultText = "\${userFlakeSelf}/profiles";
apply = x: os.mkProfileAttrs (toString x);
description = "path to profiles folder that can be collected into suites";
};
userProfiles = mkOption {
type = path;
default = "${userFlakeSelf}/users/profiles";
defaultText = "\${userFlakeSelf}/users/profiles";
apply = x: os.mkProfileAttrs (toString x);
description = "path to user profiles folder that can be collected into userSuites";
};
suites =
let
defaults = { user = { }; system = { }; };
in
mkOption {
type = inputAttrs;
default = { ... }: defaults;
defaultText = "{ user = {}; system = {}; }";
apply = suites: defaults // os.mkSuites {
inherit suites;
inherit (config) profiles users userProfiles;
};
description = ''
Function with inputs 'users' and 'profiles' that returns attribute set
with user and system suites. The former for Home Manager and the latter
for nixos configurations.
These can be accessed through the 'suites' specialArg in each config system.
'';
};
users = mkOption {
type = path;
default = "${userFlakeSelf}/users";
defaultText = "\${userFlakeSelf}/users";
apply = x: os.mkProfileAttrs (toString x);
description = ''
path to folder containing profiles that define system users
'';
};
extern =
let
defaults = {
modules = [ ];
overlays = [ ];
specialArgs = { };
userModules = [ ];
userSpecialArgs = { };
};
in
mkOption {
type = inputAttrs;
default = { ... }: defaults;
defaultText = ''
{ modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; }
'';
# So unneeded extern attributes can safely be deleted
apply = x: defaults // (x { inputs = userFlakeInputs // userFlakeSelf.inputs; });
description = ''
Function with argument 'inputs' that contains all devos and ''${userFlakeSelf}'s inputs.
The function should return an attribute set with modules, overlays, and
specialArgs to be included across nixos and home manager configurations.
Only attributes that are used should be returned.
'';
};
overlays = mkOption {
type = path;
default = "${userFlakeSelf}/overlays";
defaultText = "\${userFlakeSelf}/overlays";
apply = x: lib.pathsToImportedAttrs (lib.pathsIn (toString x));
description = ''
path to folder containing overlays which will be applied to pkgs and exported in
the 'overlays' output
'';
};
overrides = mkOption rec {
type = attrs;
default = { modules = [ ]; disabledModules = [ ]; packages = _: _: _: { }; };
defaultText = "{ modules = []; disabledModules = []; packages = {}; }";
apply = x: default // x;
description = "attrset of packages and modules that will be pulled from nixpkgs master";
};
};
};
in
lib.evalModules {
modules = [ argOpts args ];
}

View file

@ -1,20 +1,9 @@
args@{ lib, dev, utils, nixos, ... }:
lib.genAttrs utils.lib.defaultSystems (system:
lib.makeExtensible (final:
let
pkgs = import nixos { inherit system; };
callLibs = file: import file
(args // {
inherit pkgs system;
pkgs-lib = final;
});
in
with final;
{
inherit callLibs;
{ lib, nixpkgs, deploy, devshell }:
tests = callLibs ./tests;
shell = callLibs ./shell;
lib.genAttrs
lib.defaultSystems (system:
{
tests = import ./tests { inherit lib deploy nixpkgs system; };
shell = import ./shell { inherit lib devshell deploy nixpkgs system; };
}
)
)

View file

@ -1,14 +1,17 @@
{ lib, dev, inputs, system, nixos, ... }:
{ lib, nixpkgs, devshell, deploy, system }:
let
overlays = [
inputs.devshell.overlay
devshell.overlay
(final: prev: {
deploy-rs =
inputs.deploy.packages.${prev.system}.deploy-rs;
deploy.packages.${prev.system}.deploy-rs;
})
];
pkgs = dev.os.pkgImport nixos overlays system;
pkgs = import nixpkgs { inherit system overlays; config = {}; };
flk = pkgs.callPackage ./flk.nix { };

View file

@ -1,14 +1,15 @@
{ pkgs-lib, pkgs, system, inputs, nixos, lib, ... }:
{ lib, nixpkgs, deploy, system }:
let
pkgs = import nixpkgs { inherit system; overlays = []; config = {}; };
mkChecks = { hosts, nodes, homes ? { } }:
let
deployHosts = lib.filterAttrs
(n: _: hosts.${n}.config.nixpkgs.system == system)
nodes;
deployChecks = inputs.deploy.lib.${system}.deployChecks { nodes = deployHosts; };
deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; };
tests =
{ libTests = libTests; }
// lib.optionalAttrs (deployHosts != { }) {
lib.optionalAttrs (deployHosts != { }) {
profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))});
} // lib.mapAttrs (n: v: v.activationPackage) homes;
@ -18,7 +19,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;
@ -51,33 +52,5 @@ let
machine.systemctl("is-system-running --wait")
'';
};
libTests = pkgs.runCommandNoCC "devos-lib-tests"
{
buildInputs = [
pkgs.nix
(
let tests = pkgs-lib.callLibs ./lib.nix;
in
if tests == [ ]
then null
else throw (builtins.toJSON tests)
)
];
} ''
datadir="${pkgs.nix}/share"
export TEST_ROOT=$(pwd)/test-tmp
export NIX_BUILD_HOOK=
export NIX_CONF_DIR=$TEST_ROOT/etc
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
export NIX_STATE_DIR=$TEST_ROOT/var/nix
export NIX_STORE_DIR=$TEST_ROOT/store
export PAGER=cat
cacheDir=$TEST_ROOT/binary-cache
nix-store --init
touch $out
'';
in
{ inherit mkTest libTests profilesTest mkChecks; }
{ inherit mkTest profilesTest mkChecks; }

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; }];

View file

@ -1,4 +1,4 @@
{ lib, ... }:
{ lib }:
{
# returns matching part of _regex_ _string_; null indicates failure.
rgxToString = regex: string:

27
lib/tests/default.nix Normal file
View file

@ -0,0 +1,27 @@
{ pkgs, lib }:
pkgs.runCommandNoCC "devos-lib-tests"
{
buildInputs = [
pkgs.nix
(
let tests = import ./lib.nix { inherit pkgs lib; }; in
if tests == [ ] then null
else throw (builtins.toJSON tests)
)
];
} ''
datadir="${pkgs.nix}/share"
export TEST_ROOT=$(pwd)/test-tmp
export NIX_BUILD_HOOK=
export NIX_CONF_DIR=$TEST_ROOT/etc
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
export NIX_STATE_DIR=$TEST_ROOT/var/nix
export NIX_STORE_DIR=$TEST_ROOT/store
export PAGER=cat
cacheDir=$TEST_ROOT/binary-cache
nix-store --init
touch $out
''

93
lib/tests/lib.nix Normal file
View file

@ -0,0 +1,93 @@
{ pkgs, lib }:
with lib;
lib.runTests {
testConcatAttrs = {
expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }];
expected = { foo = 1; bar = 2; baz = 3; };
};
testGenAttrs' = {
expr = genAttrs'
[ "/foo/bar" "/baz/buzz" ]
(path: {
name = baseNameOf path;
value = "${path}/fizz";
});
expected = { bar = "/foo/bar/fizz"; buzz = "/baz/buzz/fizz"; };
};
testMapFilterAttrs = {
expr = mapFilterAttrs
(n: v: n == "foobar" && v == 1)
(n: v: lib.nameValuePair ("${n}bar") (v + 1))
{ foo = 0; bar = 2; };
expected = { foobar = 1; };
};
testPathsIn = {
expr = pathsIn (toString ./testPathsIn);
expected = map toString [
./testPathsIn/bar
./testPathsIn/baz
./testPathsIn/foo
];
};
testPathsToImportedAttrs = {
expr =
pathsToImportedAttrs [
(toString ./testPathsToImportedAttrs/dir)
./testPathsToImportedAttrs/foo.nix
./testPathsToImportedAttrs/bar.nix
./testPathsToImportedAttrs/t.nix
./testPathsToImportedAttrs/f.nix
];
expected = {
dir = { a = 5; };
foo = { bar = 1; };
bar = { foo = 2; };
t = true;
f = false;
};
};
testRgxToString = lib.testAllTrue [
(rgxToString ".+x" "vxk" == "vx")
(rgxToString "^fo" "foo" == "fo")
(rgxToString "a?" "a" == "a")
(rgxToString "hat" "foohatbar" == "hat")
];
testSafeReadDir = {
expr = safeReadDir ./profiles // safeReadDir ./nonexistentdir;
expected = {
foo = "directory";
t = "directory";
};
};
testSuites =
let
profiles = os.mkProfileAttrs (toString ./profiles);
users = "";
userProfiles = "";
suites = { profiles, ... }: {
system.bar = [ profiles.foo ];
};
in
{
expr = os.mkSuites { inherit profiles users userProfiles suites; };
expected = {
system = {
bar = [ profiles.foo.default ];
allProfiles = [ profiles.foo.default profiles.t.default ];
allUsers = [ ];
};
};
};
}

View file

@ -12,7 +12,6 @@ in
binutils
coreutils
curl
deploy-rs
direnv
dnsutils
dosfstools