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 = [ overlays = [
nur.overlay nur.overlay
devshell.overlay
(final: prev: {
deploy-rs = deploy.packages.${prev.system}.deploy-rs;
})
pkgs.overlay pkgs.overlay
]; ];

View file

@ -52,25 +52,17 @@
}, },
"deploy": { "deploy": {
"inputs": { "inputs": {
"flake-compat": [ "flake-compat": "flake-compat",
"flake-compat" "naersk": "naersk",
], "nixpkgs": "nixpkgs",
"naersk": [ "utils": "utils"
"naersk"
],
"nixpkgs": [
"override"
],
"utils": [
"utils"
]
}, },
"locked": { "locked": {
"lastModified": 1614654775, "lastModified": 1616406726,
"narHash": "sha256-3mLxoxIXSWUuKE8YgIuqM5AZzXFd1aWxkTlplEDeXIA=", "narHash": "sha256-n9zmgxR03QNrvs9/fHewqE0j3SjL7Y+cglBCFu3U3rg=",
"owner": "serokell", "owner": "serokell",
"repo": "deploy-rs", "repo": "deploy-rs",
"rev": "6278b9bef5ad624676a565980417cbbef42d5227", "rev": "9e405fbc5ab5bacbd271fd78c6b6b6877c4d9f8d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -79,13 +71,32 @@
"type": "github" "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": { "devshell": {
"locked": { "locked": {
"lastModified": 1613641255, "lastModified": 1618523768,
"narHash": "sha256-iSvjFK4WYAKhuXCCtkY7uy/cFQTzS3D3Ml5WZqjEfL0=", "narHash": "sha256-Gev9da35pHUey3kGz/zrJFc/9ICs++vPCho7qB1mqd8=",
"owner": "numtide", "owner": "numtide",
"repo": "devshell", "repo": "devshell",
"rev": "ff6cffba08600f5b7b43f398fcb58bef023bc4c4", "rev": "709fe4d04a9101c9d224ad83f73416dce71baf21",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -95,6 +106,22 @@
} }
}, },
"flake-compat": { "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, "flake": false,
"locked": { "locked": {
"lastModified": 1611461076, "lastModified": 1611461076,
@ -132,6 +159,27 @@
} }
}, },
"naersk": { "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": { "inputs": {
"nixpkgs": [ "nixpkgs": [
"override" "override"
@ -181,6 +229,22 @@
"type": "github" "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": { "nur": {
"locked": { "locked": {
"lastModified": 1615921934, "lastModified": 1615921934,
@ -245,26 +309,39 @@
"inputs": { "inputs": {
"ci-agent": "ci-agent", "ci-agent": "ci-agent",
"darwin": "darwin", "darwin": "darwin",
"deploy": "deploy", "devos": "devos",
"devshell": "devshell", "flake-compat": "flake-compat_2",
"flake-compat": "flake-compat",
"home": "home", "home": "home",
"naersk": "naersk", "naersk": "naersk_2",
"nixos": "nixos", "nixos": "nixos",
"nixos-hardware": "nixos-hardware", "nixos-hardware": "nixos-hardware",
"nur": "nur", "nur": "nur",
"override": "override", "override": "override",
"pkgs": "pkgs", "pkgs": "pkgs"
"utils": "utils"
} }
}, },
"utils": { "utils": {
"locked": { "locked": {
"lastModified": 1614513358, "lastModified": 1610051610,
"narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=", "narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "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" "type": "github"
}, },
"original": { "original": {

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 inputs nixos;
in hosts = ./hosts;
lib.mkFlake packages = import ./pkgs;
{ suites = import ./profiles/suites.nix;
inherit self; extern = import ./extern;
hosts = ./hosts; overrides = import ./extern/overrides.nix;
packages = import ./pkgs; overlays = ./overlays;
suites = import ./profiles/suites.nix; profiles = ./profiles;
extern = import ./extern; userProfiles = ./users/profiles;
overrides = import ./extern/overrides.nix; 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,4 +1,4 @@
{ lib, ... }: { lib }:
rec { rec {
# mapFilterAttrs :: # mapFilterAttrs ::
# (name -> value -> bool ) # (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 -> Pkgs
pkgImport = nixpkgs: overlays: system: pkgImport = nixpkgs: overlays: system:
@ -9,22 +9,22 @@
profileMap = list: map (profile: profile.default) (lib.flatten list); 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: { modules, ... } @ args:
lib.nixosSystem (args // { lib.nixosSystem (args // {
@ -13,7 +15,7 @@ lib.nixosSystem (args // {
(args // { (args // {
modules = moduleList ++ [ 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, ... }: { ({ config, suites, ... }: {
@ -23,15 +25,15 @@ lib.nixosSystem (args // {
disabledModules = map (x: [ x ]) disabledModules = map (x: [ x ])
(lib.remove modules.core suites.allProfiles); (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.isoBaseName = "nixos-" + config.networking.hostName;
isoImage.contents = [{ isoImage.contents = [{
source = self; source = userFlakeSelf;
target = "/devos/"; target = "/devos/";
}]; }];
isoImage.storeContents = [ isoImage.storeContents = [
self.devShell.${config.nixpkgs.system} userFlakeSelf.devShell.${config.nixpkgs.system}
# include also closures that are "switched off" by the # include also closures that are "switched off" by the
# above profile filter on the local config attribute # above profile filter on the local config attribute
fullHostConfig.system.build.toplevel fullHostConfig.system.build.toplevel

View file

@ -1,4 +1,6 @@
{ lib, self, ... }: { lib }:
{ userFlakeSelf }:
with lib; with lib;
let let
@ -6,7 +8,7 @@ let
mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home)
config.config.system.build.homes; config.config.system.build.homes;
hmConfigs = mapAttrs mkHomes self.nixosConfigurations; hmConfigs = mapAttrs mkHomes userFlakeSelf.nixosConfigurations;
in in
foldl recursiveUpdate { } (attrValues hmConfigs) 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 let
defaultSystem = "x86_64-linux"; defaultSystem = "x86_64-linux";
@ -29,24 +31,24 @@ let
useUserPackages = true; useUserPackages = true;
extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; 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; users.mutableUsers = lib.mkDefault false;
hardware.enableRedistributableFirmware = lib.mkDefault true; hardware.enableRedistributableFirmware = lib.mkDefault true;
nix.nixPath = [ nix.nixPath = [
"nixpkgs=${nixos}" "nixpkgs=${userFlakeNixOS}"
"nixos-config=${self}/lib/compat/nixos" "nixos-config=${userFlakeSelf}/lib/compat/nixos"
"home-manager=${inputs.home}" "home-manager=${userFlakeInputs.home}"
]; ];
nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system};
nix.registry = { nix.registry = {
devos.flake = self; devos.flake = userFlakeSelf;
nixos.flake = nixos; nixos.flake = userFlakeNixOS;
override.flake = inputs.override; override.flake = userFlakeInputs.override;
}; };
nix.package = pkgs.nixFlakes; 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`. # 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 if builtins.pathExists rootCachix
then rootCachix then rootCachix
else { } else { }
@ -82,25 +84,27 @@ let
networking = { inherit hostName; }; networking = { inherit hostName; };
_module.args = { _module.args = {
inherit self; self = userFlakeSelf;
hosts = builtins.mapAttrs (_: host: host.config) hosts = builtins.mapAttrs (_: host: host.config)
(removeAttrs hosts [ hostName ]); (removeAttrs hosts [ hostName ]);
}; };
};
lib = {
lib = { inherit specialArgs; }; lib = { inherit specialArgs; };
lib.testModule = { lib.testModule = {
imports = builtins.attrValues modules; imports = builtins.attrValues modules;
}; };
}; };
in in
dev.os.devosSystem { lib.os.devosSystem {
inherit userFlakeNixOS userFlakeInputs userFlakeSelf;
} {
inherit specialArgs; inherit specialArgs;
system = defaultSystem; system = defaultSystem;
modules = modules // { inherit local lib; }; modules = modules // { inherit local; };
}; };
hosts = dev.os.recImport hosts = lib.os.recImport
{ {
inherit dir; inherit dir;
_import = mkHostConfig; _import = mkHostConfig;

View file

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

View file

@ -1,10 +1,12 @@
{ lib, dev, self, ... }: { lib }:
{ userFlakeSelf }:
{ pkgs }: { pkgs }:
let let
inherit (self) overlay overlays; inherit (userFlakeSelf) overlay overlays;
packagesNames = lib.attrNames (overlay null null) packagesNames = lib.attrNames (overlay null null)
++ lib.attrNames (dev.concatAttrs ++ lib.attrNames (lib.concatAttrs
(lib.attrValues (lib.attrValues
(lib.mapAttrs (_: v: v null null) overlays) (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 }: { extern, overrides }:
(inputs.utils.lib.eachDefaultSystem (utils.lib.eachDefaultSystem
(system: (system:
let let
overridePkgs = dev.os.pkgImport inputs.override [ ] system; overridePkgs = lib.os.pkgImport userFlakeInputs.override [ ] system;
overridesOverlay = overrides.packages; overridesOverlay = overrides.packages;
overlays = [ overlays = [
(final: prev: { (final: prev: {
lib = prev.lib.extend (lfinal: lprev: { lib = prev.lib.extend (lfinal: lprev: {
inherit dev; inherit lib;
inherit (lib) nixosSystem; inherit (lib) nixosSystem;
utils = inputs.utils.lib;
}); });
}) })
(overridesOverlay overridePkgs) (overridesOverlay overridePkgs)
self.overlay userFlakeSelf.overlay
] ]
++ extern.overlays ++ extern.overlays
++ (lib.attrValues self.overlays); ++ (lib.attrValues userFlakeSelf.overlays);
in in
{ pkgs = dev.os.pkgImport nixos overlays system; } { pkgs = lib.os.pkgImport userFlakeNixOS overlays system; }
) )
).pkgs ).pkgs

View file

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

View file

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

View file

@ -1,7 +1,7 @@
{ lib, dev, ... }: { lib }:
{ dir, _import ? base: import "${dir}/${base}.nix" }: { dir, _import ? base: import "${dir}/${base}.nix" }:
dev.mapFilterAttrs lib.mapFilterAttrs
(_: v: v != null) (_: v: v != null)
(n: v: (n: v:
if n != "default.nix" && lib.hasSuffix ".nix" n && v == "regular" 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) let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name)
else else
lib.nameValuePair ("") (null)) 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: pathsIn = dir:
let let
fullPath = name: "${toString dir}/${name}"; fullPath = name: "${toString dir}/${name}";
in 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 let
inherit (dev) os; inherit (lib) os;
inherit (inputs) utils deploy;
evalFlakeArgs = dev.callLibs ./evalArgs.nix;
in in
{ self, ... } @ args: _: { self, inputs, nixos, ... } @ args:
let 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 = { outputs = {
nixosConfigurations = os.mkHosts { nixosConfigurations = os.mkHosts
inherit self multiPkgs; { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; }
inherit (cfg) extern suites overrides; {
dir = cfg.hosts; inherit multiPkgs;
}; inherit (cfg) extern suites overrides;
dir = cfg.hosts;
};
homeConfigurations = os.mkHomeConfigurations; homeConfigurations = os.mkHomeConfigurations
{ inherit userFlakeSelf; };
nixosModules = cfg.modules; nixosModules = cfg.modules;
@ -28,25 +39,27 @@ let
overlay = cfg.packages; overlay = cfg.packages;
inherit (cfg) overlays; 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 let
pkgs = multiPkgs.${system}; pkgs = multiPkgs.${system};
pkgs-lib = dev.pkgs-lib.${system}; pkgs-lib = lib.pkgs-lib.${system};
# all packages that are defined in ./pkgs # all packages that are defined in ./pkgs
legacyPackages = os.mkPackages { inherit pkgs; }; legacyPackages = os.mkPackages
{ inherit userFlakeSelf; }
{ inherit pkgs; };
in in
{ {
checks = pkgs-lib.tests.mkChecks { checks = pkgs-lib.tests.mkChecks {
inherit (self.deploy) nodes; inherit (userFlakeSelf.deploy) nodes;
hosts = self.nixosConfigurations; hosts = userFlakeSelf.nixosConfigurations;
homes = self.homeConfigurations; homes = userFlakeSelf.homeConfigurations;
}; };
inherit legacyPackages; inherit legacyPackages;
packages = dev.filterPackages system legacyPackages; packages = lib.filterPackages system legacyPackages;
devShell = pkgs-lib.shell; devShell = pkgs-lib.shell;
}); });

View file

@ -1,154 +1,235 @@
{ self, dev, nixos, inputs, ... }: { lib }:
{ userFlakeSelf, userFlakeNixOS }:
{ args }: { args }:
let let
argOpts = with nixos.lib; { config, options, ... }: argOpts = with lib; { config, ... }:
let let
inherit (dev) os; inherit (lib) os;
inherit (config) self; 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 // { moduleType = with types; anything // {
inherit (submodule { }) check; inherit (submodule { }) check;
description = "valid module"; 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 in
{ {
options = with types; { options = with types; {
self = mkOption { self = mkOption {
type = addCheck attrs nixos.lib.isStorePath; type = flakeType;
description = "The flake to create the devos outputs for"; description = "The flake to create the devos outputs for";
}; };
hosts = mkOption { supportedSystems = mkOption {
type = path; type = listOf str;
default = "${self}/hosts"; default = lib.defaultSystems;
defaultText = "\${self}/hosts";
apply = toString;
description = '' description = ''
Path to directory containing host configurations that will be exported The systems supported by this flake
to the 'nixosConfigurations' output.
''; '';
}; };
packages = mkOption { channels =
# 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 =
let let
defaults = { user = { }; system = { }; }; default = {
in nixpkgs = {
mkOption { input = userFlakeNixOS;
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 = "${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 in
mkOption { mkOption {
type = inputAttrs; type = attrsOf (submodule channelsModule);
default = { ... }: defaults; inherit default;
defaultText = '' apply = x: default // x;
{ modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; }
'';
# So unneeded extern attributes can safely be deleted
apply = x: defaults // (x { inputs = inputs // self.inputs; });
description = '' description = ''
Function with argument 'inputs' that contains all devos and ''${self}'s inputs. nixpkgs channels to create
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 { nixos = mkOption {
type = path; type = submodule [ includeConfigsModule importsModule ];
default = "${self}/overlays"; default = { };
defaultText = "\${self}/overlays";
apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x));
description = '' description = ''
path to folder containing overlays which will be applied to pkgs and exported in hosts, modules, suites, and profiles for nixos
the 'overlays' output
''; '';
}; };
overrides = mkOption rec { home = mkOption {
type = attrs; type = submodule importsModule;
default = { modules = [ ]; disabledModules = [ ]; packages = _: _: _: { }; }; default = { };
defaultText = "{ modules = []; disabledModules = []; packages = {}; }"; description = ''
apply = x: default // x; hosts, modules, suites, and profiles for home-manager
description = "attrset of packages and modules that will be pulled from nixpkgs master"; '';
}; };
}; };
}; };
in in
nixos.lib.evalModules { lib.evalModules {
modules = [ argOpts args ]; 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, nixpkgs, deploy, devshell }:
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;
tests = callLibs ./tests; lib.genAttrs
shell = callLibs ./shell; 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 let
overlays = [ overlays = [
inputs.devshell.overlay
devshell.overlay
(final: prev: { (final: prev: {
deploy-rs = 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 { }; flk = pkgs.callPackage ./flk.nix { };

View file

@ -1,14 +1,15 @@
{ pkgs-lib, pkgs, system, inputs, nixos, lib, ... }: { lib, nixpkgs, deploy, system }:
let let
pkgs = import nixpkgs { inherit system; overlays = []; config = {}; };
mkChecks = { hosts, nodes, homes ? { } }: mkChecks = { hosts, nodes, homes ? { } }:
let let
deployHosts = lib.filterAttrs deployHosts = lib.filterAttrs
(n: _: hosts.${n}.config.nixpkgs.system == system) (n: _: hosts.${n}.config.nixpkgs.system == system)
nodes; nodes;
deployChecks = inputs.deploy.lib.${system}.deployChecks { nodes = deployHosts; }; deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; };
tests = tests =
{ libTests = libTests; } lib.optionalAttrs (deployHosts != { }) {
// lib.optionalAttrs (deployHosts != { }) {
profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))});
} // lib.mapAttrs (n: v: v.activationPackage) homes; } // lib.mapAttrs (n: v: v.activationPackage) homes;
@ -18,7 +19,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;
@ -51,33 +52,5 @@ let
machine.systemctl("is-system-running --wait") 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 in
{ inherit mkTest libTests profilesTest mkChecks; } { inherit mkTest profilesTest mkChecks; }

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

View file

@ -1,4 +1,4 @@
{ lib, ... }: { lib }:
{ {
# returns matching part of _regex_ _string_; null indicates failure. # returns matching part of _regex_ _string_; null indicates failure.
rgxToString = regex: string: 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 binutils
coreutils coreutils
curl curl
deploy-rs
direnv direnv
dnsutils dnsutils
dosfstools dosfstools