Skip to content

Commit

Permalink
refactor: add requiredInputs check
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Oct 12, 2023
1 parent 6db0674 commit 0748723
Show file tree
Hide file tree
Showing 23 changed files with 562 additions and 15 deletions.
24 changes: 24 additions & 0 deletions lib/errors/inputsSource.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ lib }:
list:
lib.filter (pair: lib.elem pair.name list) [
{
name = "nixpkgs";
url = "github:nixpkgs/nixpkgs-unstable";
}
{
name = "makes";
url = "github:fluidattacks/makes";
}
{
name = "home-manager";
url = "github:github:nix-community/home-manager";
}
{
name = "microvm";
url = "github:astro/microvm.nix";
}
{
name = "topiary";
url = "github:github:tweag/topiary";
}
]
8 changes: 0 additions & 8 deletions lib/errors/msg.nix

This file was deleted.

59 changes: 59 additions & 0 deletions lib/errors/requiredInputs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
lib,
inputs,
super,
}:
inputs': listNames:
let
fondInputs =
if
(lib.length (
lib.filter (pair: pair == true) (map (v: lib.hasAttr v inputs) listNames)
)) > 0
then
true
else
false
;
msg =
(lib.concatMapStringsSep "\n "
(
{ name, url }:
''
# add `${name}.url = "${url}"` to your flake
${name} = inputs.${name};
''
)
(super.inputsSource listNames)
);

noSysNixpkgs =
if (lib.elem "nixpkgs" listNames) then
if (lib.hasAttr "path" inputs'.nixpkgs) then true else false
else
true
;
in
assert lib.assertMsg fondInputs ''
please, add the these inputs into
omnibus.lib.addLoadExtender {
load.inputs = {
${msg}
# you can also see the full inputs list at
# https://github.com/GTrunSec/omnibus/blob/main/local/lock/flake.nix#L1
};
};
}
'';
assert lib.assertMsg noSysNixpkgs ''
please, add the following inputs into
omnibus.lib.addLoadExtender {
load.inputs = {
nixpkgs = inputs.nixpkgs.legacyPackages.''${system} or (import inputs.nixpkgs.path);
};
};
}
'';
inputs'
5 changes: 5 additions & 0 deletions lib/exporter/flakeOutputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ let
in
{
inherit (outputs) srvos;

units = {
inherit (outputs) configs;
};

__inputs__ = super.pops.loadInputs.outputs;

dotfiles = inputs.self.outPath + "/dotfiles";
Expand Down
13 changes: 9 additions & 4 deletions lib/exporter/pops.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ in
load.src = inputs.self.outPath + "/nixos/darwinModules";
};

configs = flops.haumea.pops.default.setInit {
src = inputs.self.outPath + "/units/configs";
inputs = baseInputs;
};

srvos = flops.haumea.pops.default.setInit {
src = self.loadInputs.outputs.srvos + "/nixos";
type = "nixosProfiles";
Expand All @@ -62,24 +67,24 @@ in
};
flake-parts = {
loadModules = self.loadNixOSModules.addLoadExtender {
load.src = inputs.self.outPath + "/evalModules/flake-parts/modules";
load.src = inputs.self.outPath + "/units/flake-parts/modules";
};
loadProfiles = self.loadNixOSProfiles.addLoadExtender {
load = {
src = inputs.self.outPath + "/evalModules/flake-parts/profiles";
src = inputs.self.outPath + "/units/flake-parts/profiles";
};
};
};
devshell = rec {
loadModules = self.loadNixOSModules.addLoadExtender {
load = {
src = inputs.self.outPath + "/evalModules/devshell/modules";
src = inputs.self.outPath + "/units/devshell/modules";
type = "nixosModules";
};
};
loadProfiles = self.loadNixOSProfiles.addLoadExtender {
load = {
src = inputs.self.outPath + "/evalModules/devshell/profiles";
src = inputs.self.outPath + "/units/devshell/profiles";
type = "nixosProfiles";
};
};
Expand Down
27 changes: 27 additions & 0 deletions lib/makes.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
inputs,
lib,
root,
}:
let
l = nixpkgs.lib // builtins;
inherit
(root.errors.requiredInputs inputs [
"nixpkgs"
"makes"
])
nixpkgs
makes
;
in
l.fix (
l.extends
(_: _: {
inherit inputs;
inherit (nixpkgs) system;
__nixpkgs__ = nixpkgs;
__nixpkgsSrc__ = nixpkgs.path;
})
(import (makes + /src/args/agnostic.nix) { inherit (nixpkgs) system; })
.__unfix__
)
4 changes: 1 addition & 3 deletions lib/mkHome.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
root,
}:
userSet: shell: suites:
assert lib.assertMsg (inputs ? home-manager) (root.errors.msg "home-manager");
let

inherit (inputs) home-manager;
inherit (root.errors.requiredInputs inputs [ "home-manager" ]) home-manager;
user = lib.head (lib.attrNames userSet);
pathsToLinkShell = lib.elem shell [
"fish"
Expand Down
33 changes: 33 additions & 0 deletions lib/mkMicrovm.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# credit: https://github.com/divnix/std/blob/main/src/lib/ops/mkMicrovm.nix#
{
inputs,
lib,
root,
}:
let
inherit
(root.errors.requiredInputs inputs [
"nixpkgs"
"microvm"
])
nixpkgs
microvm
;
nixosSystem =
args:
import "${nixpkgs.path}/nixos/lib/eval-config.nix" (
args // { modules = args.modules; }
);
in
module:
nixosSystem {
inherit (nixpkgs) system;
modules = [
# for declarative MicroVM management
microvm.nixosModules.host
# this runs as a MicroVM that nests MicroVMs
microvm.nixosModules.microvm
# your custom module
module
];
}
17 changes: 17 additions & 0 deletions local/lock/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions local/lock/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";

makes.url = "github:fluidattacks/makes";
makes.flake = false;
};
outputs = _: { };
}
4 changes: 4 additions & 0 deletions tests/_snapshots/makes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pretty
{
makeScript = <function, args: {aliases?, entrypoint, globalState?, help?, name, persistState?, replace?, searchPaths?}>;
}
20 changes: 20 additions & 0 deletions tests/makes/expr.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ omnibus, lib }:
let
inherit (omnibus.__inputs__) nixpkgs makes;
makesLib =
(omnibus.pops.lib.addLoadExtender {
load = {
inputs = {
inputs = {
nixpkgs = nixpkgs.legacyPackages.x86_64-linux;
inherit makes;
};
};
};
}).layouts.default.makes;

inherit (makesLib) makeScript;
in
{
makeScript = makeScript;
}
1 change: 1 addition & 0 deletions tests/makes/format.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"pretty"
48 changes: 48 additions & 0 deletions units/configs/cog.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ inputs }:
{
default = {
output = "cog.toml";
commands = [ { package = inputs.nixpkgs.cocogitto; } ];
data = {
tag_prefix = "v";
branch_whitelist = [
"main"
"release/**"
];
ignore_merge_commits = true;
pre_bump_hooks = [
"echo {{version}} > ./VERSION"
''
branch="$(echo "release/{{version}}" | sed 's/\.[^.]*$//')"
if [ `git rev-parse --verify $branch 2>/dev/null` ]
then
git switch -m "$branch" || exit 1
git merge main
else
git switch -c "$branch" || exit 1
fi
''
];
post_bump_hooks = [
''
branch="$(echo "release/{{version}}" | sed 's/\.[^.]*$//')"
git push --set-upstream origin "$branch"
git push origin v{{version}}
git switch main
git merge "$branch" --no-commit --no-ff
echo {{version+minor-dev}} > ./VERSION
git add VERSION
git commit -m "chore: sync with release"
git push origin main
''
"cog -q changelog --at v{{version}}"
];
changelog = {
path = "CHANGELOG.md";
template = "remote";
remote = "github.com";
};
};
};
}
24 changes: 24 additions & 0 deletions units/configs/conform.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
default.data = {
commit = {
header = {
length = 89;
};
conventional = {
types = [
"build"
"chore"
"ci"
"docs"
"feat"
"fix"
"perf"
"refactor"
"style"
"test"
];
scopes = [ ];
};
};
};
}
33 changes: 33 additions & 0 deletions units/configs/editorconfig.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
default.data = {
root = true;
"*" = {
end_of_line = "lf";
insert_final_newline = true;
trim_trailing_whitespace = true;
charset = "utf-8";
indent_style = "space";
indent_size = 2;
};

"*.{diff,patch}" = {
end_of_line = "unset";
insert_final_newline = "unset";
trim_trailing_whitespace = "unset";
indent_size = "unset";
};

"*.md" = {
max_line_length = "off";
trim_trailing_whitespace = false;
};
"{LICENSES/**,LICENSE}" = {
end_of_line = "unset";
insert_final_newline = "unset";
trim_trailing_whitespace = "unset";
charset = "unset";
indent_style = "unset";
indent_size = "unset";
};
};
}
Loading

0 comments on commit 0748723

Please sign in to comment.