diff --git a/.gitignore b/.gitignore index c6aefa6..bb8fa3d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,3 @@ result-* # pre-commit-hooks.nix .pre-commit-config.yaml - -# dev/README.md -flake.lock diff --git a/README.md b/README.md index b2dcc1e..ca0eab5 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ baseline level of compatibility: the core attributes that constitute a flake. - Reuse project logic written by others + # Getting Started @@ -76,6 +77,10 @@ See [the template](./template/default/flake.nix). See [flake.parts](https://flake.parts/options.html) +# Documentation + +See [flake.parts](https://flake.parts) + # Top-level module parameters - `config`, `options`, `lib`, ...: standard module system parameters. diff --git a/dev/README.md b/dev/README.md index b5001c5..270517d 100644 --- a/dev/README.md +++ b/dev/README.md @@ -1,5 +1,5 @@ -# Separate `tools` flake +# Separate `dev` flake Wouldn't recommend this pattern normally, but I'm trying to keep deps low for `flake-parts` until we have split dev inputs diff --git a/dev/flake-module.nix b/dev/flake-module.nix index 95fdb63..ae227e5 100644 --- a/dev/flake-module.nix +++ b/dev/flake-module.nix @@ -3,8 +3,7 @@ { imports = [ inputs.pre-commit-hooks-nix.flakeModule - inputs.hercules-ci-effects.flakeModule - ../site/flake-module.nix + inputs.hercules-ci-effects.flakeModule # herculesCI attr ]; systems = [ "x86_64-linux" "aarch64-darwin" ]; perSystem = { config, self', inputs', pkgs, ... }: { @@ -13,10 +12,6 @@ nativeBuildInputs = [ pkgs.nixpkgs-fmt pkgs.pre-commit - pkgs.hci - pkgs.netlify-cli - pkgs.pandoc - pkgs.mdbook ]; shellHook = '' ${config.pre-commit.installationScript} @@ -31,19 +26,6 @@ }; }; - herculesCI = herculesCI@{ config, ... }: { - onPush.default.outputs = { - effects = - withSystem "x86_64-linux" ({ config, pkgs, hci-effects, ... }: { - netlifyDeploy = hci-effects.netlifyDeploy { - content = config.packages.siteContent; - secretName = "default-netlify"; - siteId = "29a153b1-3698-433c-bc73-62415efb8117"; - productionDeployment = herculesCI.config.repo.branch == "main"; - }; - }); - }; - }; flake = { # for repl exploration / debug config.config = config; diff --git a/dev/flake.lock b/dev/flake.lock index 3e6c2b9..60bc8b0 100644 --- a/dev/flake.lock +++ b/dev/flake.lock @@ -1,132 +1,5 @@ { "nodes": { - "alejandra": { - "inputs": { - "fenix": "fenix", - "flakeCompat": "flakeCompat", - "nixpkgs": [ - "dream2nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1658427149, - "narHash": "sha256-ToD/1z/q5VHsLMrS2h96vjJoLho59eNRtknOUd19ey8=", - "owner": "kamadorueda", - "repo": "alejandra", - "rev": "f5a22afd2adfb249b4e68e0b33aa1f0fb73fb1be", - "type": "github" - }, - "original": { - "owner": "kamadorueda", - "repo": "alejandra", - "type": "github" - } - }, - "all-cabal-json": { - "flake": false, - "locked": { - "lastModified": 1665552503, - "narHash": "sha256-r14RmRSwzv5c+bWKUDaze6pXM7nOsiz1H8nvFHJvufc=", - "owner": "nix-community", - "repo": "all-cabal-json", - "rev": "d7c0434eebffb305071404edcf9d5cd99703878e", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "hackage", - "repo": "all-cabal-json", - "type": "github" - } - }, - "crane": { - "flake": false, - "locked": { - "lastModified": 1661875961, - "narHash": "sha256-f1h/2c6Teeu1ofAHWzrS8TwBPcnN+EEu+z1sRVmMQTk=", - "owner": "ipetkov", - "repo": "crane", - "rev": "d9f394e4e20e97c2a60c3ad82c2b6ef99be19e24", - "type": "github" - }, - "original": { - "owner": "ipetkov", - "repo": "crane", - "type": "github" - } - }, - "devshell": { - "flake": false, - "locked": { - "lastModified": 1663445644, - "narHash": "sha256-+xVlcK60x7VY1vRJbNUEAHi17ZuoQxAIH4S4iUFUGBA=", - "owner": "numtide", - "repo": "devshell", - "rev": "e3dc3e21594fe07bdb24bdf1c8657acaa4cb8f66", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "dream2nix": { - "inputs": { - "alejandra": "alejandra", - "all-cabal-json": "all-cabal-json", - "crane": "crane", - "devshell": "devshell", - "flake-utils-pre-commit": "flake-utils-pre-commit", - "ghc-utils": "ghc-utils", - "gomod2nix": "gomod2nix", - "mach-nix": "mach-nix", - "nixpkgs": [ - "nixpkgs" - ], - "poetry2nix": "poetry2nix", - "pre-commit-hooks": [ - "pre-commit-hooks-nix" - ] - }, - "locked": { - "lastModified": 1668037398, - "narHash": "sha256-2N/KCus0Stm9qa7rotuvA6QW35KwXERphE5xxgudses=", - "owner": "nix-community", - "repo": "dream2nix", - "rev": "e98ca58528f9b4d1fa8cc3135c02c4306ec81364", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "dream2nix", - "type": "github" - } - }, - "fenix": { - "inputs": { - "nixpkgs": [ - "dream2nix", - "alejandra", - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1657607339, - "narHash": "sha256-HaqoAwlbVVZH2n4P3jN2FFPMpVuhxDy1poNOR7kzODc=", - "owner": "nix-community", - "repo": "fenix", - "rev": "b814c83d9e6aa5a28d0cf356ecfdafb2505ad37d", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" @@ -181,21 +54,6 @@ "type": "github" } }, - "flake-utils-pre-commit": { - "locked": { - "lastModified": 1644229661, - "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "flake-utils_2": { "locked": { "lastModified": 1667077288, @@ -211,69 +69,6 @@ "type": "github" } }, - "flakeCompat": { - "flake": false, - "locked": { - "lastModified": 1650374568, - "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "b4a34015c698c7793d592d66adbab377907a2be8", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "ghc-utils": { - "flake": false, - "locked": { - "lastModified": 1662774800, - "narHash": "sha256-1Rd2eohGUw/s1tfvkepeYpg8kCEXiIot0RijapUjAkE=", - "ref": "refs/heads/master", - "rev": "bb3a2d3dc52ff0253fb9c2812bd7aa2da03e0fea", - "revCount": 1072, - "type": "git", - "url": "https://gitlab.haskell.org/bgamari/ghc-utils" - }, - "original": { - "type": "git", - "url": "https://gitlab.haskell.org/bgamari/ghc-utils" - } - }, - "gomod2nix": { - "flake": false, - "locked": { - "lastModified": 1627572165, - "narHash": "sha256-MFpwnkvQpauj799b4QTBJQFEddbD02+Ln5k92QyHOSk=", - "owner": "tweag", - "repo": "gomod2nix", - "rev": "67f22dd738d092c6ba88e420350ada0ed4992ae8", - "type": "github" - }, - "original": { - "owner": "tweag", - "repo": "gomod2nix", - "type": "github" - } - }, - "haskell-flake": { - "locked": { - "lastModified": 1668167720, - "narHash": "sha256-5wDTR6xt9BB3BjgKR+YOjOkZgMyDXKaX79g42sStzDU=", - "owner": "srid", - "repo": "haskell-flake", - "rev": "4fc511d93a55fedf815c1647ad146c26d7a2054e", - "type": "github" - }, - "original": { - "owner": "srid", - "repo": "haskell-flake", - "type": "github" - } - }, "hercules-ci-agent": { "inputs": { "flake-parts": "flake-parts_2", @@ -315,21 +110,6 @@ "type": "github" } }, - "mach-nix": { - "flake": false, - "locked": { - "lastModified": 1634711045, - "narHash": "sha256-m5A2Ty88NChLyFhXucECj6+AuiMZPHXNbw+9Kcs7F6Y=", - "owner": "DavHau", - "repo": "mach-nix", - "rev": "4433f74a97b94b596fa6cd9b9c0402104aceef5d", - "type": "github" - }, - "original": { - "id": "mach-nix", - "type": "indirect" - } - }, "nix-darwin": { "inputs": { "nixpkgs": [ @@ -417,23 +197,6 @@ "type": "github" } }, - "poetry2nix": { - "flake": false, - "locked": { - "lastModified": 1632969109, - "narHash": "sha256-jPDclkkiAy5m2gGLBlKgH+lQtbF7tL4XxBrbSzw+Ioc=", - "owner": "nix-community", - "repo": "poetry2nix", - "rev": "aee8f04296c39d88155e05d25cfc59dfdd41cc77", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "1.21.0", - "repo": "poetry2nix", - "type": "github" - } - }, "pre-commit-hooks-nix": { "inputs": { "flake-utils": "flake-utils", @@ -481,29 +244,10 @@ }, "root": { "inputs": { - "dream2nix": "dream2nix", - "haskell-flake": "haskell-flake", "hercules-ci-effects": "hercules-ci-effects", "nixpkgs": "nixpkgs_3", "pre-commit-hooks-nix": "pre-commit-hooks-nix_2" } - }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1657557289, - "narHash": "sha256-PRW+nUwuqNTRAEa83SfX+7g+g8nQ+2MMbasQ9nt6+UM=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "caf23f29144b371035b864a1017dbc32573ad56d", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } } }, "root": "root", diff --git a/dev/flake.nix b/dev/flake.nix index ae07d5d..61815c8 100644 --- a/dev/flake.nix +++ b/dev/flake.nix @@ -7,17 +7,9 @@ # we can't use the `nix` CLI as expected. nixpkgs.url = "github:hercules-ci/nixpkgs/options-markdown-and-errors"; - pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix"; pre-commit-hooks-nix.inputs.nixpkgs.follows = "nixpkgs"; - hercules-ci-effects.url = "github:hercules-ci/hercules-ci-effects"; - - haskell-flake.url = "github:srid/haskell-flake"; - haskell-flake.inputs.nixpkgs.follows = "nixpkgs"; - dream2nix.url = "github:nix-community/dream2nix"; - dream2nix.inputs.pre-commit-hooks.follows = "pre-commit-hooks-nix"; - dream2nix.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, ... }: diff --git a/site/.gitignore b/site/.gitignore deleted file mode 100644 index 7585238..0000000 --- a/site/.gitignore +++ /dev/null @@ -1 +0,0 @@ -book diff --git a/site/book.toml b/site/book.toml deleted file mode 100644 index fbede22..0000000 --- a/site/book.toml +++ /dev/null @@ -1,6 +0,0 @@ -[book] -authors = ["Robert Hensing", "Various module authors"] -language = "en" -multilingual = false -src = "src" -title = "flake-parts" diff --git a/site/flake-module.nix b/site/flake-module.nix deleted file mode 100644 index b5c43d9..0000000 --- a/site/flake-module.nix +++ /dev/null @@ -1,137 +0,0 @@ -{ inputs, ... }: { - perSystem = { config, self', inputs', pkgs, lib, ... }: - let - inherit (lib) filter any hasPrefix concatMap removePrefix; - - libNix = import ../lib.nix { inherit lib; }; - eval = libNix.evalFlakeModule { self = { inputs = { inherit (inputs) nixpkgs; }; }; } { - imports = [ - inputs.pre-commit-hooks-nix.flakeModule - inputs.hercules-ci-effects.flakeModule - inputs.haskell-flake.flakeModule - inputs.dream2nix.flakeModuleBeta - ]; - }; - opts = eval.options; - - filterTransformOptions = { sourceName, sourcePath, baseUrl }: - let sourcePathStr = toString sourcePath; - in - opt: - let - declarations = concatMap - (decl: - if hasPrefix sourcePathStr (toString decl) - then - let subpath = removePrefix sourcePathStr (toString decl); - in [{ url = baseUrl + subpath; name = sourceName + subpath; }] - else [ ] - ) - opt.declarations; - in - if declarations == [ ] - then opt // { visible = false; } - else opt // { inherit declarations; }; - - optionsDoc = { sourceName, baseUrl, sourcePath, title }: pkgs.runCommand "option-doc-${sourceName}" - { - nativeBuildInputs = [ pkgs.libxslt.bin pkgs.pandoc ]; - inputDoc = (pkgs.nixosOptionsDoc { - options = opts; - documentType = "none"; - transformOptions = filterTransformOptions { - inherit sourceName baseUrl sourcePath; - }; - warningsAreErrors = true; # not sure if feasible long term - markdownByDefault = true; - }).optionsDocBook; - inherit title; - } '' - xsltproc --stringparam title "$title" \ - -o options.db.xml ${./options.xsl} \ - "$inputDoc" - mkdir $out - pandoc --verbose --from docbook --to html options.db.xml >$out/options.md; - ''; - - repos = { - flake-parts = { - title = "Core Options"; - sourceName = "flake-parts"; - baseUrl = "https://github.com/hercules-ci/flake-parts/blob/main"; - sourcePath = ../.; - }; - pre-commit-hooks-nix = { - title = "pre-commit-hooks.nix"; - sourceName = "pre-commit-hooks.nix"; - baseUrl = "https://github.com/hercules-ci/pre-commit-hooks.nix/blob/flakeModule"; - sourcePath = inputs.pre-commit-hooks-nix; - }; - hercules-ci-effects = { - title = "hercules-ci-effects"; - sourceName = "hercules-ci-effects"; - baseUrl = "https://github.com/hercules-ci/hercules-ci-effects/blob/master"; - sourcePath = inputs.hercules-ci-effects; - }; - haskell-flake = { - title = "haskell-flake"; - sourceName = "haskell-flake"; - baseUrl = "https://github.com/srid/haskell-flake/blob/master"; - sourcePath = inputs.haskell-flake; - }; - dream2nix = { - title = "dream2nix beta"; - sourceName = "dream2nix"; - baseUrl = "https://github.com/nix-community/dream2nix/blob/master"; - sourcePath = inputs.dream2nix; - }; - }; - - generatedDocs = lib.mapAttrs (k: optionsDoc) repos; - generatedDocs' = lib.mapAttrs' (name: value: { name = "generated-docs-${name}"; inherit value; }) generatedDocs; - - in - { - packages = { - siteContent = pkgs.stdenvNoCC.mkDerivation { - name = "site"; - nativeBuildInputs = [ pkgs.mdbook ]; - src = ./.; - buildPhase = '' - runHook preBuild - - { - while read ln; do - case "$ln" in - *end_of_intro*) - break - ;; - *) - echo "$ln" - ;; - esac - done - cat src/intro-continued.md - } <${../README.md} >src/README.md - - mkdir -p src/options - ${lib.concatStringsSep "\n" - (lib.mapAttrsToList - (name: generated: '' - cp '${generated}/options.md' 'src/options/${name}.md' - '') - generatedDocs) - } - - mdbook build --dest-dir $out - - echo 'to the options' \ - >$out/options.html - - runHook postBuild - ''; - dontInstall = true; - }; - } // generatedDocs'; - }; -} diff --git a/site/options.xsl b/site/options.xsl deleted file mode 100644 index 830825d..0000000 --- a/site/options.xsl +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - <xsl:value-of select="$title"/> - - Overview: - - - - - - - -
- - <link xlink:href="#{db:term/@xml:id}" xml:id="{db:term/@xml:id}"><xsl:copy-of select="db:term/db:option"/></link> - - -
-
- - - - - - - - - - - - - - - - - - - - - - -
\ No newline at end of file diff --git a/site/src/SUMMARY.md b/site/src/SUMMARY.md deleted file mode 100644 index 712764d..0000000 --- a/site/src/SUMMARY.md +++ /dev/null @@ -1,13 +0,0 @@ -# Summary - -- [Introduction](./README.md) -- [Getting Started](./getting-started.md) -- [Working with `system`](./system.md) -- [Reference Documentation](./module-arguments.md) - - [Module Arguments](./module-arguments.md) - - [Options](./options/flake-parts.md) - - [Core `flake-parts`](./options/flake-parts.md) - - [`dream2nix beta`](./options/dream2nix.md) - - [`haskell-flake`](./options/haskell-flake.md) - - [`hercules-ci-effects`](./options/hercules-ci-effects.md) - - [`pre-commit-hooks.nix`](./options/pre-commit-hooks-nix.md) diff --git a/site/src/getting-started.md b/site/src/getting-started.md deleted file mode 100644 index 1cd713d..0000000 --- a/site/src/getting-started.md +++ /dev/null @@ -1,38 +0,0 @@ - -# Getting Started - -## New flake - -If your project does not have a flake yet: - -```console -nix flake init -t github:hercules-ci/flake-parts -``` - -## Existing flake - -Otherwise, add the input, - -``` - flake-parts.url = "github:hercules-ci/flake-parts"; -``` - -then slide `mkFlake` between your outputs function head and body, - -``` - outputs = { self, flake-parts, ... }: - flake-parts.lib.mkFlake { inherit self; } { - flake = { - # Put your original flake attributes here. - }; - systems = [ - # systems for which you want to build the `perSystem` attributes - "x86_64-linux" - # ... - ]; - perSystem = { config, ... }: { - }; - }; -``` - -Now you can start using the flake-parts options. diff --git a/site/src/intro-continued.md b/site/src/intro-continued.md deleted file mode 100644 index e398c97..0000000 --- a/site/src/intro-continued.md +++ /dev/null @@ -1,7 +0,0 @@ - - -# This documentation - -You can find guides and the options reference in the menu (top left). - -A site wide search is available by typing `s`. diff --git a/site/src/module-arguments.md b/site/src/module-arguments.md deleted file mode 100644 index 438305a..0000000 --- a/site/src/module-arguments.md +++ /dev/null @@ -1,58 +0,0 @@ - -# Module Arguments - -The module system allows modules and submodules to be defined using plain -attribute sets, or functions that return attribute sets. When a module is a -function, various attributes may be passed to it. - -# Top-level Module Arguments - -Top-level refers to the module passed to `mkFlake`, or any of the modules -imported into it using `imports`. - -The standard module system arguments are available in all modules and submodules. These are chiefly `config`, `options`, `lib`. - -## `getSystem` - -A function from [system](./system.md) string to the `config` of the appropriate `perSystem`. - -## `moduleWithSystem` - -A function that brings the `perSystem` module arguments. -This allows a module to reference the defining flake without introducing -global variables. - -```nix -{ moduleWithSystem, ... }: -{ - nixosModules.default = moduleWithSystem ( - perSystem@{ config }: # NOTE: only explicit params will be in perSystem - nixos@{ ... }: - { - services.foo.package = perSystem.config.packages.foo; - imports = [ ./nixos-foo.nix ]; - } - ); -} -``` - -## `withSystem` - -Enter the scope of a system. Worked example: - -```nix -{ withSystem, ... }: -{ - # perSystem = ...; - - nixosConfigurations.foo = withSystem "x86_64-linux" (ctx@{ pkgs, ... }: - pkgs.nixos ({ config, lib, packages, pkgs, ... }: { - _module.args.packages = ctx.config.packages; - imports = [ ./nixos-configuration.nix ]; - services.nginx.enable = true; - environment.systemPackages = [ - packages.hello - ]; - })); -} -``` diff --git a/site/src/system.md b/site/src/system.md deleted file mode 100644 index 64ed635..0000000 --- a/site/src/system.md +++ /dev/null @@ -1,20 +0,0 @@ - -# `system` - -In Nix, "system" generally refers to the cpu-os string, such as `"x86_64-linux"`. - -In Flakes specifically, these strings are used as attribute names, so that the -Nix CLI can find a derivation for the right platform. - -Many things, such as packages, can exist on multiple systems. For these, use -the [`perSystem`](options/flake-parts.html#opt-perSystem) submodule. - -Other things do not exist on multiple systems. Examples are the configuration -of a specific machine, or a the execution of a deployment. These are not -written in `perSystem`, but in other top-level options, or directly into the -flake outputs' top level (e.g. [`flake.nixosConfigurations`](options/flake-parts.html#opt-flake.nixosConfigurations)). - -Such top-level entities typically do need to read packages, etc that are defined -in `perSystem`. Instead of reading them from `config.flake.packages..`, -it may be more convenient to bring all `perSystem` definitions for a system into -scope, using [`withSystem`](module-arguments.html#withsystem).