From 140da4067f3fecdf1c01f199e8aeb288d6a5b20f Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 13 May 2022 10:10:42 +0200 Subject: [PATCH] Add local tooling and CI wiring without bloating flake.nix --- ci.nix | 11 +++++++++++ dev/README.md | 6 ++++++ dev/default.nix | 9 +++++++++ dev/flake-module.nix | 41 +++++++++++++++++++++++++++++++++++++++++ dev/flake.lock | 27 +++++++++++++++++++++++++++ dev/flake.nix | 13 +++++++++++++ dev/repl.nix | 3 +++ shell.nix | 2 ++ 8 files changed, 112 insertions(+) create mode 100644 ci.nix create mode 100644 dev/README.md create mode 100644 dev/default.nix create mode 100644 dev/flake-module.nix create mode 100644 dev/flake.lock create mode 100644 dev/flake.nix create mode 100644 dev/repl.nix create mode 100644 shell.nix diff --git a/ci.nix b/ci.nix new file mode 100644 index 0000000..650b9c0 --- /dev/null +++ b/ci.nix @@ -0,0 +1,11 @@ +# We're doing things a bit differently because Nix doesn't let us +# split out the dev dependencies and subflakes are broken, let alone "superflakes". +# See dev/README.md +let + flake = import ./dev; + inherit (flake.inputs.nixpkgs) lib; +in { + inherit (flake) herculesCI; +} // { + checks = lib.recurseIntoAttrs flake.checks.${builtins.currentSystem}; +} diff --git a/dev/README.md b/dev/README.md new file mode 100644 index 0000000..bd7f521 --- /dev/null +++ b/dev/README.md @@ -0,0 +1,6 @@ + +# Separate `tools` flake + +Wouldn't recommend this pattern normally, but I'm trying to keep +deps low for `flake-modules-core` until we have split dev inputs +that don't carry over to dependent lock files. diff --git a/dev/default.nix b/dev/default.nix new file mode 100644 index 0000000..c6846b7 --- /dev/null +++ b/dev/default.nix @@ -0,0 +1,9 @@ +let + flake = builtins.getFlake (toString ./.); + fmc-lib = import ../lib.nix { inherit (flake.inputs.nixpkgs) lib; }; + self = { inherit (flake) inputs; } // + fmc-lib.evalFlakeModule + { inherit self; } + ./flake-module.nix; +in + self.config.flake // { inherit (flake) inputs; } diff --git a/dev/flake-module.nix b/dev/flake-module.nix new file mode 100644 index 0000000..e80ad3e --- /dev/null +++ b/dev/flake-module.nix @@ -0,0 +1,41 @@ +flakeModuleArgs@{ config, lib, ... }: + +{ + imports = [ + ]; + systems = [ "x86_64-linux" "aarch64-darwin" ]; + perSystem = system: { config, self', inputs', pkgs, ... }: { + _module.args.pkgs = inputs'.nixpkgs.legacyPackages; + devShells.default = pkgs.mkShell { + nativeBuildInputs = [ pkgs.nixpkgs-fmt ]; + }; + packages = { + inherit (pkgs.nixosOptionsDoc { inherit (flakeModuleArgs) options; }) + optionsDocBook; + optionsMarkdown = pkgs.runCommand "options-markdown" + { + inherit (config.packages) optionsDocBook; + nativeBuildInputs = [ pkgs.pandoc ]; + } '' + mkdir $out + pandoc \ + --from docbook \ + --to markdown \ + --output $out/options.md \ + $optionsDocBook + ''; + }; + }; + flake = { + options.herculesCI = lib.mkOption { type = lib.types.raw; }; + config.herculesCI = { + onPush.default.outputs = { + inherit (config.flake) packages checks; + }; + }; + + # for repl exploration / debug + config.config = config; + options.mySystem = lib.mkOption { default = config.allSystems.${builtins.currentSystem}; }; + }; +} diff --git a/dev/flake.lock b/dev/flake.lock new file mode 100644 index 0000000..5ce9a29 --- /dev/null +++ b/dev/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1652425756, + "narHash": "sha256-3+5j3ZU43oC5PxRfGDQ6xs5sYnypS5GBhVP6uf7PVGM=", + "owner": "hercules-ci", + "repo": "nixpkgs", + "rev": "81a0a8be297a88f338ee0fd90c330cd94b4a55bd", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "ref": "functionTo-properly", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/dev/flake.nix b/dev/flake.nix new file mode 100644 index 0000000..45eef18 --- /dev/null +++ b/dev/flake.nix @@ -0,0 +1,13 @@ +{ + description = "Dependencies for development purposes"; + + inputs = { + # Flakes don't give us a good way to depend on .., so we don't. + # This has drastic consequences of course. + nixpkgs.url = "github:hercules-ci/nixpkgs/functionTo-properly"; + }; + + outputs = { self, ... }: + { + }; +} diff --git a/dev/repl.nix b/dev/repl.nix new file mode 100644 index 0000000..4c1b0d5 --- /dev/null +++ b/dev/repl.nix @@ -0,0 +1,3 @@ +# convenience for loading into nix repl +let self = builtins.getFlake (toString ./.); +in self // { inherit self; } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..62bdb7b --- /dev/null +++ b/shell.nix @@ -0,0 +1,2 @@ +# non-idiomatic, see tools/README.md +(import ./dev).devShells.${builtins.currentSystem}.default