replace flake-utils input with nix-systems

We're only using `eachDefaultSystem` from flake-utils so pulling it in is
a bit overkill; using the underlying nix-systems dependency directly brings
us closer to a "stock" flake format without adding unnecessary burden.
This commit is contained in:
Bryton Hall 2023-07-07 23:44:44 -04:00
parent f7f2df7119
commit b231710109
2 changed files with 134 additions and 156 deletions

31
flake.lock generated
View file

@ -16,24 +16,6 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1685518550,
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1686488075, "lastModified": 1686488075,
@ -52,11 +34,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1680945546, "lastModified": 1688590700,
"narHash": "sha256-8FuaH5t/aVi/pR1XxnF0qi4WwMYC+YxlfdsA0V+TEuQ=", "narHash": "sha256-ZF055rIUP89cVwiLpG5xkJzx00gEuuGFF60Bs/LM3wc=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d9f759f2ea8d265d974a6e1259bd510ac5844c5d", "rev": "f292b4964cb71f9dfbbd30dc9f511d6165cd109b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -69,8 +51,8 @@
"root": { "root": {
"inputs": { "inputs": {
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"systems": "systems",
"treefmt": "treefmt" "treefmt": "treefmt"
} }
}, },
@ -84,9 +66,8 @@
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-systems", "id": "systems",
"repo": "default", "type": "indirect"
"type": "github"
} }
}, },
"treefmt": { "treefmt": {

View file

@ -4,38 +4,26 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
treefmt.url = "github:numtide/treefmt-nix"; treefmt.url = "github:numtide/treefmt-nix";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = { flake-compat = {
url = "github:edolstra/flake-compat"; url = "github:edolstra/flake-compat";
flake = false; flake = false;
}; };
}; };
outputs = inputs @ { self, ... }: outputs = inputs@{ self, systems, ... }:
(inputs.flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = import inputs.nixpkgs { eachSystem = f: inputs.nixpkgs.lib.genAttrs (import systems)
inherit system; (system: f inputs.nixpkgs.legacyPackages.${system});
overlays = [ self.overlays.default ]; in
config.allowUnsupportedSystem = true; {
}; # evalModules with same interface as lib.evalModules and kubenix as special argument
evalModules = eachSystem (pkgs:
inherit (pkgs) lib; attrs @ { module ? null, modules ? [ module ], ... }:
kubenix = {
lib = import ./lib { inherit lib pkgs; };
evalModules = self.evalModules.${system};
modules = self.nixosModules.kubenix;
};
# evalModules with same interface as lib.evalModules and kubenix as
# special argument
evalModules = attrs @ { module ? null, modules ? [ module ], ... }:
let let
lib' = lib.extend (lib: _self: import ./lib/upstreamables.nix { inherit lib pkgs; }); lib' = pkgs.lib.extend (lib: _self: import ./lib/upstreamables.nix { inherit lib pkgs; });
attrs' = builtins.removeAttrs attrs [ "module" ]; attrs' = builtins.removeAttrs attrs [ "module" ];
in in
lib'.evalModules (lib.recursiveUpdate lib'.evalModules (pkgs.lib.recursiveUpdate
{ {
modules = modules ++ [{ modules = modules ++ [{
config._module.args = { config._module.args = {
@ -44,16 +32,24 @@
}; };
}]; }];
specialArgs = { specialArgs = {
inherit kubenix; pkgs = import inputs.nixpkgs {
inherit pkgs; inherit (pkgs) system;
overlays = [ self.overlays.default ];
config.allowUnsupportedSystem = true;
};
kubenix = {
lib = import ./lib { inherit pkgs; inherit (pkgs) lib; };
evalModules = self.evalModules.${pkgs.system};
modules = self.nixosModules.kubenix;
};
}; };
} }
attrs'); attrs')
in );
{
inherit evalModules pkgs;
devShells.default = pkgs.mkShell { devShells = eachSystem (pkgs: {
default = pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
dive dive
fd fd
@ -73,8 +69,9 @@
export NODE_PATH="${pkgs.nodePackages.prettier-plugin-toml}/lib/node_modules:$NODE_PATH" export NODE_PATH="${pkgs.nodePackages.prettier-plugin-toml}/lib/node_modules:$NODE_PATH"
''; '';
}; };
});
formatter = (inputs.treefmt.lib.evalModule pkgs { formatter = eachSystem (pkgs: (inputs.treefmt.lib.evalModule pkgs {
projectRootFile = "flake.nix"; projectRootFile = "flake.nix";
programs = { programs = {
nixpkgs-fmt.enable = true; nixpkgs-fmt.enable = true;
@ -87,9 +84,9 @@
"docs/layouts/*" "docs/layouts/*"
"modules/generated/*" "modules/generated/*"
]; ];
}).config.build.wrapper; }).config.build.wrapper);
apps = { apps = eachSystem (pkgs: {
docs = { docs = {
type = "app"; type = "app";
program = (pkgs.writeShellScript "gen-docs" '' program = (pkgs.writeShellScript "gen-docs" ''
@ -128,16 +125,16 @@
rm result rm result
'').outPath; '').outPath;
}; };
}; });
packages = { packages = eachSystem (pkgs: {
default = pkgs.callPackage ./pkgs/kubenix.nix { default = pkgs.callPackage ./pkgs/kubenix.nix {
inherit (self.packages.${system}); inherit (self.packages.${system});
evalModules = self.evalModules.${system}; evalModules = self.evalModules.${pkgs.system};
}; };
docs = import ./docs { docs = import ./docs {
inherit pkgs; inherit pkgs;
options = (self.evalModules.${system} { options = (self.evalModules.${pkgs.system} {
modules = builtins.attrValues (builtins.removeAttrs modules = builtins.attrValues (builtins.removeAttrs
# the submodules module currently doesn't evaluate: # the submodules module currently doesn't evaluate:
# error: No module found name/latest # error: No module found name/latest
@ -147,9 +144,10 @@
}; };
} }
// pkgs.lib.attrsets.mapAttrs' (name: value: pkgs.lib.attrsets.nameValuePair "generate-${name}" value) // pkgs.lib.attrsets.mapAttrs' (name: value: pkgs.lib.attrsets.nameValuePair "generate-${name}" value)
(builtins.removeAttrs (pkgs.callPackage ./pkgs/generators { }) [ "override" "overrideDerivation" ]); (builtins.removeAttrs (pkgs.callPackage ./pkgs/generators { }) [ "override" "overrideDerivation" ])
);
checks = checks = eachSystem (pkgs:
let let
wasSuccess = suite: wasSuccess = suite:
if suite.success if suite.success
@ -157,23 +155,22 @@
else pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-failed" { } "exit 1"; else pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-failed" { } "exit 1";
examples = import ./docs/content/examples; examples = import ./docs/content/examples;
mkK8STests = attrs: mkK8STests = attrs:
(import ./tests { inherit evalModules; }) (import ./tests { evalModules = self.evalModules.${pkgs.system}; })
({ registry = "docker.io/gatehub"; } // attrs); ({ registry = "docker.io/gatehub"; } // attrs);
in in
{ {
# TODO: access "success" derivation with nice testing utils for nice output # TODO: access "success" derivation with nice testing utils for nice output
testing = wasSuccess examples.testing.config.testing; testing = wasSuccess examples.testing.config.testing;
} } // builtins.listToAttrs (builtins.map
// builtins.listToAttrs (builtins.map
(v: { (v: {
name = "test-k8s-${builtins.replaceStrings ["."] ["_"] v}"; name = "test-k8s-${builtins.replaceStrings ["."] ["_"] v}";
value = wasSuccess (mkK8STests { k8sVersion = v; }); value = wasSuccess (mkK8STests { k8sVersion = v; });
}) })
(import ./versions.nix).versions); (import ./versions.nix).versions)
} );
))
// {
nixosModules.kubenix = import ./modules; nixosModules.kubenix = import ./modules;
overlays.default = _final: prev: { overlays.default = _final: prev: {
kubenix.evalModules = self.evalModules.${prev.system}; kubenix.evalModules = self.evalModules.${prev.system};
}; };