From 78e2d0993257530d7aa43f15810493623f1ba77d Mon Sep 17 00:00:00 2001 From: zimbatm Date: Sat, 27 Jul 2024 22:39:08 +0200 Subject: [PATCH 1/2] chore(flake): remove dependency on flake-utils Keep the dependency tree small. --- extra/language/hare.nix | 107 +++++++++++++++--------------- flake.lock | 34 ---------- flake.nix | 142 +++++++++++++++++++++------------------- 3 files changed, 128 insertions(+), 155 deletions(-) diff --git a/extra/language/hare.nix b/extra/language/hare.nix index 3a6cff3b..9244927a 100644 --- a/extra/language/hare.nix +++ b/extra/language/hare.nix @@ -1,58 +1,59 @@ -{ - config, - lib, - pkgs, - ... -}: let +{ config +, lib +, pkgs +, ... +}: +let cfg = config.language.hare; - strOrPackage = import ../../nix/strOrPackage.nix {inherit lib pkgs;}; - makeHareFullPath = thirdParty: let - allHareThirdPartyPkgs = builtins.attrValues (pkgs.hareThirdParty.packages pkgs); - isPropagatedLib = drv: builtins.any (x: drv == x) allHareThirdPartyPkgs; - pkgsPropagatedBuildInputs = builtins.foldl' (acc: e: acc ++ e.propagatedBuildInputs) [] thirdParty; - propagatedLibs = builtins.filter isPropagatedLib pkgsPropagatedBuildInputs; - in + strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; + makeHareFullPath = thirdParty: + let + allHareThirdPartyPkgs = builtins.attrValues (pkgs.hareThirdParty.packages pkgs); + isPropagatedLib = drv: builtins.any (x: drv == x) allHareThirdPartyPkgs; + pkgsPropagatedBuildInputs = builtins.foldl' (acc: e: acc ++ e.propagatedBuildInputs) [ ] thirdParty; + propagatedLibs = builtins.filter isPropagatedLib pkgsPropagatedBuildInputs; + in lib.makeSearchPath - "src/hare/third-party" - (thirdParty ++ propagatedLibs); + "src/hare/third-party" + (thirdParty ++ propagatedLibs); in - with lib; { - options.language.hare = { - thirdPartyLibs = mkOption { - type = types.listOf strOrPackage; - default = []; - example = literalExpression "[ hareThirdParty.hare-compress ]"; - description = "List of extra packages (coming from hareThirdParty) to add"; - }; - vendoredLibs = mkOption { - type = types.listOf types.str; - default = []; - example = literalExpression "[ ./vendor/lib ]"; - description = "List of paths to add to HAREPATH"; - }; - package = mkOption { - type = strOrPackage; - default = pkgs.hare; - example = literalExpression "pkgs.hare"; - description = "Which Hare package to use"; - }; +with lib; { + options.language.hare = { + thirdPartyLibs = mkOption { + type = types.listOf strOrPackage; + default = [ ]; + example = literalExpression "[ hareThirdParty.hare-compress ]"; + description = "List of extra packages (coming from hareThirdParty) to add"; }; - - config = { - env = [ - (mkIf (cfg.thirdPartyLibs != [] || cfg.vendoredLibs != []) { - name = "HAREPATH"; - value = lib.makeSearchPath "src/hare/stdlib" [cfg.package]; - }) - (mkIf (cfg.thirdPartyLibs != []) { - name = "HAREPATH"; - prefix = makeHareFullPath cfg.thirdPartyLibs; - }) - (mkIf (cfg.vendoredLibs != []) { - name = "HAREPATH"; - prefix = concatStringsSep ":" cfg.vendoredLibs; - }) - ]; - devshell.packages = [cfg.package]; + vendoredLibs = mkOption { + type = types.listOf types.str; + default = [ ]; + example = literalExpression "[ ./vendor/lib ]"; + description = "List of paths to add to HAREPATH"; + }; + package = mkOption { + type = strOrPackage; + default = pkgs.hare; + example = literalExpression "pkgs.hare"; + description = "Which Hare package to use"; }; - } + }; + + config = { + env = [ + (mkIf (cfg.thirdPartyLibs != [ ] || cfg.vendoredLibs != [ ]) { + name = "HAREPATH"; + value = lib.makeSearchPath "src/hare/stdlib" [ cfg.package ]; + }) + (mkIf (cfg.thirdPartyLibs != [ ]) { + name = "HAREPATH"; + prefix = makeHareFullPath cfg.thirdPartyLibs; + }) + (mkIf (cfg.vendoredLibs != [ ]) { + name = "HAREPATH"; + prefix = concatStringsSep ":" cfg.vendoredLibs; + }) + ]; + devshell.packages = [ cfg.package ]; + }; +} diff --git a/flake.lock b/flake.lock index f5feddac..0e3d3ae2 100644 --- a/flake.lock +++ b/flake.lock @@ -1,23 +1,5 @@ { "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1704161960, @@ -36,24 +18,8 @@ }, "root": { "inputs": { - "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 14959a0e..f9f92c06 100644 --- a/flake.nix +++ b/flake.nix @@ -3,86 +3,92 @@ # To update all inputs: # nix flake update inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - inputs.flake-utils.url = "github:numtide/flake-utils"; - outputs = inputs: inputs.flake-utils.lib.eachSystem [ - "x86_64-linux" - "aarch64-linux" - "riscv64-linux" - "x86_64-darwin" - "aarch64-darwin" - ] - (system: - let - pkgs = inputs.nixpkgs.legacyPackages.${system}; + outputs = { self, nixpkgs }: + let + systems = [ + "aarch64-darwin" + "aarch64-linux" + "riscv64-linux" + "x86_64-darwin" + "x86_64-linux" + ]; + + eachSystem = f: nixpkgs.lib.genAttrs systems (system: f rec { + inherit system; + pkgs = nixpkgs.legacyPackages.${system}; devshell = import ./. { nixpkgs = pkgs; }; - in - rec { - packages = { - docs = pkgs.writeShellApplication { - name = "docs"; - meta.description = ''Run mdBook server at http://localhost:3000''; - runtimeInputs = [ pkgs.mdbook ]; - text = '' - cd docs - cp ${devshell.modules-docs.markdown} src/modules_schema.md - mdbook serve - ''; - }; - bench = pkgs.writeShellApplication { - name = "benchmark"; - meta.description = ''Run benchmark''; - runtimeInputs = [ pkgs.hyperfine ]; - text = '' - cd benchmark - hyperfine -w 3 \ - 'nix-instantiate ../shell.nix' \ - 'nix-instantiate ./devshell-nix.nix' \ - 'nix-instantiate ./devshell-toml.nix' \ - 'nix-instantiate ./nixpkgs-mkshell.nix' - ''; - }; - # expose devshell as an executable package - default = devShells.default; + }); + in + { + packages = eachSystem ({ pkgs, system, devshell }: { + docs = pkgs.writeShellApplication { + name = "docs"; + meta.description = ''Run mdBook server at http://localhost:3000''; + runtimeInputs = [ pkgs.mdbook ]; + text = '' + cd docs + cp ${devshell.modules-docs.markdown} src/modules_schema.md + mdbook serve + ''; + }; + bench = pkgs.writeShellApplication { + name = "benchmark"; + meta.description = ''Run benchmark''; + runtimeInputs = [ pkgs.hyperfine ]; + text = '' + cd benchmark + hyperfine -w 3 \ + 'nix-instantiate ../shell.nix' \ + 'nix-instantiate ./devshell-nix.nix' \ + 'nix-instantiate ./devshell-toml.nix' \ + 'nix-instantiate ./nixpkgs-mkshell.nix' + ''; }; + # expose devshell as an executable package + default = self.devShells.${system}.default; + }); - devShells.default = devshell.fromTOML ./devshell.toml; + devShells = eachSystem ({ devshell, ... }: { + default = devshell.fromTOML ./devshell.toml; + }); - legacyPackages = import inputs.self { + legacyPackages = eachSystem ({ system, pkgs, ... }: + import self { inherit system; inputs = null; nixpkgs = pkgs; - }; + } + ); - checks = - with pkgs.lib; - pipe (import ./tests { inherit pkgs; }) [ - (collect isDerivation) - (map (x: { name = x.name or x.pname; value = x; })) - listToAttrs - ]; + checks = eachSystem ({ pkgs, ... }: + with pkgs.lib; + pipe (import ./tests { inherit pkgs; }) [ + (collect isDerivation) + (map (x: { name = x.name or x.pname; value = x; })) + listToAttrs + ] + ); - formatter = pkgs.nixpkgs-fmt; - } - ) // { - # Import this overlay into your instance of nixpkgs - overlays.default = import ./overlay.nix; + formatter = eachSystem ({ pkgs, ... }: pkgs.nixpkgs-fmt); - templates = rec { - toml = { - path = ./templates/toml; - description = "nix flake new my-project -t github:numtide/devshell"; - }; - flake-parts = { - path = ./templates/flake-parts; - description = "nix flake new my-project -t github:numtide/devshell#flake-parts"; + # Import this overlay into your instance of nixpkgs + overlays.default = import ./overlay.nix; + + templates = rec { + toml = { + path = ./templates/toml; + description = "nix flake new my-project -t github:numtide/devshell"; + }; + flake-parts = { + path = ./templates/flake-parts; + description = "nix flake new my-project -t github:numtide/devshell#flake-parts"; + }; + default = toml; }; - default = toml; - }; - lib.importTOML = import ./nix/importTOML.nix; + lib.importTOML = import ./nix/importTOML.nix; - flakeModule = ./flake-module.nix; - } - ; + flakeModule = ./flake-module.nix; + }; } From 29ae43652fd2f029e494e757406d71c9dbd97d41 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Sat, 27 Jul 2024 22:41:56 +0200 Subject: [PATCH 2/2] chore: format with nixfmt-rfc-style --- benchmark/devshell-nix.nix | 4 +- benchmark/devshell-toml.nix | 4 +- benchmark/nixpkgs-mkshell.nix | 4 +- default.nix | 43 ++++--- docs/default.nix | 13 +- extra/git/hooks.nix | 56 ++++---- extra/language/c.nix | 15 ++- extra/language/go.nix | 23 +++- extra/language/hare.nix | 19 +-- extra/language/perl.nix | 7 +- extra/language/ruby.nix | 33 ++++- extra/language/rust.nix | 104 ++++++++------- extra/locale.nix | 16 ++- extra/services/postgres.nix | 12 +- flake-module.nix | 35 ++--- flake.lock | 6 +- flake.lock.nix | 112 ++++++++-------- flake.nix | 101 +++++++++------ modules/back-compat.nix | 10 +- modules/commands.nix | 94 +++++++------- modules/default.nix | 7 +- modules/devshell.nix | 149 ++++++++++++---------- modules/env.nix | 37 +++++- modules/modules-docs.nix | 102 +++++++-------- modules/modules.nix | 30 +++-- modules/services.nix | 76 ++++++----- nix/ansi.nix | 5 +- nix/importTOML.nix | 21 ++- nix/mkNakedShell.nix | 31 +++-- nix/source.nix | 29 +++-- nix/strOrPackage.nix | 3 +- nix/writeDefaultShellScript.nix | 23 ++-- overlay.nix | 5 +- shell.nix | 4 +- templates/flake-parts/flake.nix | 20 ++- templates/gettingStartedExample/flake.nix | 12 +- templates/toml/flake.nix | 13 +- templates/toml/shell.nix | 27 ++-- tests/core/commands.nix | 10 +- tests/core/devshell.nix | 15 ++- tests/core/env.nix | 6 +- tests/core/modules-docs.nix | 10 +- tests/default.nix | 40 +++--- tests/extra/git.hooks.nix | 10 +- tests/extra/language.c.nix | 6 +- tests/extra/language.hare.nix | 36 +++--- tests/extra/language.perl.nix | 6 +- tests/extra/language.rust.nix | 6 +- tests/extra/locale.nix | 6 +- tests/extra/services.postgres.nix | 6 +- 50 files changed, 853 insertions(+), 609 deletions(-) diff --git a/benchmark/devshell-nix.nix b/benchmark/devshell-nix.nix index a1f9a01e..e95e8229 100644 --- a/benchmark/devshell-nix.nix +++ b/benchmark/devshell-nix.nix @@ -1,4 +1,6 @@ -{ system ? builtins.currentSystem }: +{ + system ? builtins.currentSystem, +}: let devshell = import ../. { inherit system; }; in diff --git a/benchmark/devshell-toml.nix b/benchmark/devshell-toml.nix index 13c3efcc..9ecd9df4 100644 --- a/benchmark/devshell-toml.nix +++ b/benchmark/devshell-toml.nix @@ -1,4 +1,6 @@ -{ system ? builtins.currentSystem }: +{ + system ? builtins.currentSystem, +}: let devshell = import ../. { inherit system; }; in diff --git a/benchmark/nixpkgs-mkshell.nix b/benchmark/nixpkgs-mkshell.nix index e89be55b..b51286fb 100644 --- a/benchmark/nixpkgs-mkshell.nix +++ b/benchmark/nixpkgs-mkshell.nix @@ -1,4 +1,6 @@ -{ system ? builtins.currentSystem }: +{ + system ? builtins.currentSystem, +}: let pkgs = import (import ../nix/nixpkgs.nix) { inherit system; }; in diff --git a/default.nix b/default.nix index 462c977c..00cceb82 100644 --- a/default.nix +++ b/default.nix @@ -1,26 +1,33 @@ -{ system ? builtins.currentSystem -, inputs ? import ./flake.lock.nix { } -, nixpkgs ? import inputs.nixpkgs { +{ + system ? builtins.currentSystem, + inputs ? import ./flake.lock.nix { }, + nixpkgs ? import inputs.nixpkgs { inherit system; # Makes the config pure as well. See /top-level/impure.nix: config = { }; overlays = [ ]; - } + }, }: let # Build a list of all the files, imported as Nix code, from a directory. - importTree = dir: + importTree = + dir: let data = builtins.readDir dir; - op = sum: name: + op = + sum: name: let path = "${dir}/${name}"; type = data.${name}; in - sum ++ - (if type == "regular" then [ path ] - # assume it's a directory - else importTree path); + sum + ++ ( + if type == "regular" then + [ path ] + # assume it's a directory + else + importTree path + ); in builtins.foldl' op [ ] (builtins.attrNames data); in @@ -29,12 +36,13 @@ rec { extraModulesDir = toString ./extra; # Get the modules documentation from an empty evaluation - modules-docs = (eval { - configuration = { - # Load all of the extra modules so they appear in the docs - imports = importTree extraModulesDir; - }; - }).config.modules-docs; + modules-docs = + (eval { + configuration = { + # Load all of the extra modules so they appear in the docs + imports = importTree extraModulesDir; + }; + }).config.modules-docs; # Docs docs = nixpkgs.callPackage ./docs { inherit modules-docs; }; @@ -65,6 +73,5 @@ rec { # * flake app # * direnv integration # * setup hook for derivation or hercules ci effect - mkShell = configuration: - (eval { inherit configuration; }).shell; + mkShell = configuration: (eval { inherit configuration; }).shell; } diff --git a/docs/default.nix b/docs/default.nix index a432ed00..67f410f6 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -1,14 +1,17 @@ -{ mdbook -, modules-docs -, stdenv -, lib +{ + mdbook, + modules-docs, + stdenv, + lib, }: with lib; stdenv.mkDerivation { name = "devshell-docs"; buildInputs = [ mdbook ]; src = - let fs = lib.fileset; in + let + fs = lib.fileset; + in fs.toSource { root = ./.; fileset = fs.unions [ diff --git a/extra/git/hooks.nix b/extra/git/hooks.nix index f9f1d936..aff8ed4d 100644 --- a/extra/git/hooks.nix +++ b/extra/git/hooks.nix @@ -1,17 +1,21 @@ -{ lib, config, pkgs, ... }: +{ + lib, + config, + pkgs, + ... +}: with lib; let cfg = config.git.hooks; # These are all the options available for a git hook. - hookOptions = desc: - { - text = mkOption { - description = "Text of the script to install"; - default = ""; - type = types.str; - }; + hookOptions = desc: { + text = mkOption { + description = "Text of the script to install"; + default = ""; + type = types.str; }; + }; # All of the hook types supported by this module. allHooks = filterAttrs (k: v: k != "enable") cfg; @@ -36,26 +40,26 @@ let mkdir -p $out/bin ${lib.concatMapStringsSep "\n" (k: '' - cat <<'WRAPPER' > $out/bin/${k} - #!${pkgs.bash}/bin/bash - set -euo pipefail - - if [[ -z "''${DEVSHELL_DIR:-}" ]]; then - echo "${k}: ignoring git hook outside of devshell"; >&2 - exit; - elif [[ -z "''${DEVSHELL_GIT_HOOKS_DIR:-}" ]]; then - echo "${k}: git hooks are not activated in this environment"; >&2 - exit; - elif ! [[ -x "''${DEVSHELL_GIT_HOOKS_DIR}/bin/${k}" ]]; then - echo "${k}: the ${k} git hook is not activated in this environment"; >&2 - exit; - fi + cat <<'WRAPPER' > $out/bin/${k} + #!${pkgs.bash}/bin/bash + set -euo pipefail + + if [[ -z "''${DEVSHELL_DIR:-}" ]]; then + echo "${k}: ignoring git hook outside of devshell"; >&2 + exit; + elif [[ -z "''${DEVSHELL_GIT_HOOKS_DIR:-}" ]]; then + echo "${k}: git hooks are not activated in this environment"; >&2 + exit; + elif ! [[ -x "''${DEVSHELL_GIT_HOOKS_DIR}/bin/${k}" ]]; then + echo "${k}: the ${k} git hook is not activated in this environment"; >&2 + exit; + fi - exec "''${DEVSHELL_GIT_HOOKS_DIR}/bin/${k}" "$@" - WRAPPER + exec "''${DEVSHELL_GIT_HOOKS_DIR}/bin/${k}" "$@" + WRAPPER - # Mark as executable - chmod +x "$out/bin/${k}" + # Mark as executable + chmod +x "$out/bin/${k}" '') (builtins.attrNames allHooks)} ''; diff --git a/extra/language/c.nix b/extra/language/c.nix index 795f7449..929e70bb 100644 --- a/extra/language/c.nix +++ b/extra/language/c.nix @@ -1,4 +1,9 @@ -{ lib, config, pkgs, ... }: +{ + lib, + config, + pkgs, + ... +}: let cfg = config.language.c; strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; @@ -32,12 +37,10 @@ with lib; config = { devshell.packages = [ cfg.compiler ] + ++ (lib.optionals hasLibraries (map lib.getLib cfg.libraries)) ++ - (lib.optionals hasLibraries (map lib.getLib cfg.libraries)) - ++ - # Assume we want pkg-config, because it's good - (lib.optionals hasIncludes ([ pkgs.pkg-config ] ++ (map lib.getDev cfg.includes))) - ; + # Assume we want pkg-config, because it's good + (lib.optionals hasIncludes ([ pkgs.pkg-config ] ++ (map lib.getDev cfg.includes))); env = (lib.optionals hasLibraries [ diff --git a/extra/language/go.nix b/extra/language/go.nix index e3d7d098..d04fa7eb 100644 --- a/extra/language/go.nix +++ b/extra/language/go.nix @@ -1,4 +1,9 @@ -{ lib, config, pkgs, ... }: +{ + lib, + config, + pkgs, + ... +}: let cfg = config.language.go; strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; @@ -7,7 +12,11 @@ with lib; { options.language.go = { GO111MODULE = mkOption { - type = types.enum [ "on" "off" "auto" ]; + type = types.enum [ + "on" + "off" + "auto" + ]; default = "on"; description = "Enable Go modules"; }; @@ -21,10 +30,12 @@ with lib; }; config = { - env = [{ - name = "GO111MODULE"; - value = cfg.GO111MODULE; - }]; + env = [ + { + name = "GO111MODULE"; + value = cfg.GO111MODULE; + } + ]; devshell.packages = [ cfg.package ]; }; diff --git a/extra/language/hare.nix b/extra/language/hare.nix index 9244927a..b548aeb9 100644 --- a/extra/language/hare.nix +++ b/extra/language/hare.nix @@ -1,23 +1,24 @@ -{ config -, lib -, pkgs -, ... +{ + config, + lib, + pkgs, + ... }: let cfg = config.language.hare; strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; - makeHareFullPath = thirdParty: + makeHareFullPath = + thirdParty: let allHareThirdPartyPkgs = builtins.attrValues (pkgs.hareThirdParty.packages pkgs); isPropagatedLib = drv: builtins.any (x: drv == x) allHareThirdPartyPkgs; pkgsPropagatedBuildInputs = builtins.foldl' (acc: e: acc ++ e.propagatedBuildInputs) [ ] thirdParty; propagatedLibs = builtins.filter isPropagatedLib pkgsPropagatedBuildInputs; in - lib.makeSearchPath - "src/hare/third-party" - (thirdParty ++ propagatedLibs); + lib.makeSearchPath "src/hare/third-party" (thirdParty ++ propagatedLibs); in -with lib; { +with lib; +{ options.language.hare = { thirdPartyLibs = mkOption { type = types.listOf strOrPackage; diff --git a/extra/language/perl.nix b/extra/language/perl.nix index 91a509ab..8a9f6126 100644 --- a/extra/language/perl.nix +++ b/extra/language/perl.nix @@ -1,4 +1,9 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let cfg = config.language.perl; diff --git a/extra/language/ruby.nix b/extra/language/ruby.nix index df345cef..55d3ebb5 100644 --- a/extra/language/ruby.nix +++ b/extra/language/ruby.nix @@ -1,4 +1,9 @@ -{ lib, config, pkgs, ... }: +{ + lib, + config, + pkgs, + ... +}: let cfg = config.language.ruby; strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; @@ -35,12 +40,26 @@ with lib; gnumake ]; env = [ - { name = "CC"; value = "cc"; } - { name = "CPP"; value = "cpp"; } - { name = "CXX"; value = "c++"; } - { name = "GEM_HOME"; eval = "$PRJ_DATA_DIR/ruby/bundle/$(ruby -e 'puts RUBY_VERSION')"; } - { name = "PATH"; prefix = "$GEM_HOME/bin"; } + { + name = "CC"; + value = "cc"; + } + { + name = "CPP"; + value = "cpp"; + } + { + name = "CXX"; + value = "c++"; + } + { + name = "GEM_HOME"; + eval = "$PRJ_DATA_DIR/ruby/bundle/$(ruby -e 'puts RUBY_VERSION')"; + } + { + name = "PATH"; + prefix = "$GEM_HOME/bin"; + } ]; }; } - diff --git a/extra/language/rust.nix b/extra/language/rust.nix index f607d92c..ab86dc69 100644 --- a/extra/language/rust.nix +++ b/extra/language/rust.nix @@ -1,4 +1,9 @@ -{ lib, config, pkgs, ... }: +{ + lib, + config, + pkgs, + ... +}: let cfg = config.language.rust; in @@ -31,52 +36,55 @@ with lib; }; config = { - devshell.packages = if cfg.enableDefaultToolchain then (map (tool: cfg.packageSet.${tool}) cfg.tools) else [ ]; - env = [ - { - # On darwin for example enables finding of libiconv - name = "LIBRARY_PATH"; - # append in case it needs to be modified - eval = "$DEVSHELL_DIR/lib"; - } - { - # some *-sys crates require additional includes - name = "CFLAGS"; - # append in case it needs to be modified - eval = "\"-I $DEVSHELL_DIR/include ${lib.optionalString pkgs.stdenv.isDarwin "-iframework $DEVSHELL_DIR/Library/Frameworks"}\""; - } - ] ++ lib.optionals pkgs.stdenv.isDarwin [ - { - # On darwin for example required for some *-sys crate compilation - name = "RUSTFLAGS"; - # append in case it needs to be modified - eval = "\"-L framework=$DEVSHELL_DIR/Library/Frameworks\""; - } - { - # rustdoc uses a different set of flags - name = "RUSTDOCFLAGS"; - # append in case it needs to be modified - eval = "\"-L framework=$DEVSHELL_DIR/Library/Frameworks\""; - } - { - name = "PATH"; - prefix = - let - inherit (pkgs) xcbuild; - in - lib.makeBinPath [ - xcbuild - "${xcbuild}/Toolchains/XcodeDefault.xctoolchain" - ]; - } - ] - # fenix provides '.rust-src' in the 'complete' toolchain configuration - ++ lib.optionals (cfg.enableDefaultToolchain && cfg.packageSet ? rust-src) [ - { - # rust-analyzer may use this to quicker find the rust source - name = "RUST_SRC_PATH"; - value = "${cfg.packageSet.rust-src}/lib/rustlib/src/rust/library"; - } - ]; + devshell.packages = + if cfg.enableDefaultToolchain then (map (tool: cfg.packageSet.${tool}) cfg.tools) else [ ]; + env = + [ + { + # On darwin for example enables finding of libiconv + name = "LIBRARY_PATH"; + # append in case it needs to be modified + eval = "$DEVSHELL_DIR/lib"; + } + { + # some *-sys crates require additional includes + name = "CFLAGS"; + # append in case it needs to be modified + eval = "\"-I $DEVSHELL_DIR/include ${lib.optionalString pkgs.stdenv.isDarwin "-iframework $DEVSHELL_DIR/Library/Frameworks"}\""; + } + ] + ++ lib.optionals pkgs.stdenv.isDarwin [ + { + # On darwin for example required for some *-sys crate compilation + name = "RUSTFLAGS"; + # append in case it needs to be modified + eval = "\"-L framework=$DEVSHELL_DIR/Library/Frameworks\""; + } + { + # rustdoc uses a different set of flags + name = "RUSTDOCFLAGS"; + # append in case it needs to be modified + eval = "\"-L framework=$DEVSHELL_DIR/Library/Frameworks\""; + } + { + name = "PATH"; + prefix = + let + inherit (pkgs) xcbuild; + in + lib.makeBinPath [ + xcbuild + "${xcbuild}/Toolchains/XcodeDefault.xctoolchain" + ]; + } + ] + # fenix provides '.rust-src' in the 'complete' toolchain configuration + ++ lib.optionals (cfg.enableDefaultToolchain && cfg.packageSet ? rust-src) [ + { + # rust-analyzer may use this to quicker find the rust source + name = "RUST_SRC_PATH"; + value = "${cfg.packageSet.rust-src}/lib/rustlib/src/rust/library"; + } + ]; }; } diff --git a/extra/locale.nix b/extra/locale.nix index eafc56da..e8bc8efa 100644 --- a/extra/locale.nix +++ b/extra/locale.nix @@ -1,4 +1,9 @@ -{ lib, pkgs, config, ... }: +{ + lib, + pkgs, + config, + ... +}: with lib; let cfg = config.extra.locale; @@ -20,11 +25,10 @@ in }; }; config.env = - lib.optional pkgs.stdenv.isLinux - { - name = "LOCALE_ARCHIVE"; - value = "${cfg.package}/lib/locale/locale-archive"; - } + lib.optional pkgs.stdenv.isLinux { + name = "LOCALE_ARCHIVE"; + value = "${cfg.package}/lib/locale/locale-archive"; + } ++ lib.optionals (cfg.lang != null) [ { name = "LANG"; diff --git a/extra/services/postgres.nix b/extra/services/postgres.nix index 1fb7800a..6228b38a 100644 --- a/extra/services/postgres.nix +++ b/extra/services/postgres.nix @@ -3,7 +3,12 @@ # # To start the server, invoke `postgres` in one devshell. Then start a second # devshell to run the clients. -{ lib, pkgs, config, ... }: +{ + lib, + pkgs, + config, + ... +}: with lib; let # Because we want to be able to push pure JSON-like data into the @@ -61,7 +66,10 @@ in initdbArgs = mkOption { type = with types; listOf str; default = [ "--no-locale" ]; - example = [ "--data-checksums" "--allow-group-access" ]; + example = [ + "--data-checksums" + "--allow-group-access" + ]; description = '' Additional arguments passed to `initdb` during data dir initialisation. diff --git a/flake-module.nix b/flake-module.nix index c6997be9..7a5d52fb 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -5,25 +5,28 @@ let in { options = { - perSystem = mkPerSystemOption ({ config, pkgs, ... }: { - options.devshells = mkOption { - description = '' - Configure devshells with flake-parts. + perSystem = mkPerSystemOption ( + { config, pkgs, ... }: + { + options.devshells = mkOption { + description = '' + Configure devshells with flake-parts. - Not to be confused with `devShells`, with a capital S. Yes, this - is unfortunate. + Not to be confused with `devShells`, with a capital S. Yes, this + is unfortunate. - Each devshell will also configure an equivalent `devShells`. + Each devshell will also configure an equivalent `devShells`. - Used to define devshells. not to be confused with `devShells` - ''; + Used to define devshells. not to be confused with `devShells` + ''; - type = types.lazyAttrsOf (types.submoduleWith { - modules = import ./modules/modules.nix { inherit pkgs lib; }; - }); - default = { }; - }; - config.devShells = lib.mapAttrs (_name: devshell: devshell.devshell.shell) config.devshells; - }); + type = types.lazyAttrsOf ( + types.submoduleWith { modules = import ./modules/modules.nix { inherit pkgs lib; }; } + ); + default = { }; + }; + config.devShells = lib.mapAttrs (_name: devshell: devshell.devshell.shell) config.devshells; + } + ); }; } diff --git a/flake.lock b/flake.lock index 0e3d3ae2..60f0822e 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1704161960, - "narHash": "sha256-QGua89Pmq+FBAro8NriTuoO/wNaUtugt29/qqA8zeeM=", + "lastModified": 1722073938, + "narHash": "sha256-OpX0StkL8vpXyWOGUD6G+MA26wAXK6SpT94kLJXo6B4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "63143ac2c9186be6d9da6035fa22620018c85932", + "rev": "e36e9f57337d0ff0cf77aceb58af4c805472bfae", "type": "github" }, "original": { diff --git a/flake.lock.nix b/flake.lock.nix index 9a67535a..ffa93f9a 100644 --- a/flake.lock.nix +++ b/flake.lock.nix @@ -2,7 +2,9 @@ # # This version only gives back the inputs. In that mode, flake becomes little # more than a niv replacement. -{ src ? ./. }: +{ + src ? ./., +}: let lockFilePath = src + "/flake.lock"; @@ -26,18 +28,26 @@ let } else if info.type == "git" then { - outPath = - builtins.fetchGit - ({ url = info.url; sha256 = info.narHash; } - // (if info ? rev then { inherit (info) rev; } else { }) - // (if info ? ref then { inherit (info) ref; } else { }) - ); + outPath = builtins.fetchGit ( + { + url = info.url; + sha256 = info.narHash; + } + // (if info ? rev then { inherit (info) rev; } else { }) + // (if info ? ref then { inherit (info) ref; } else { }) + ); lastModified = info.lastModified; narHash = info.narHash; - } // (if info ? rev then { - rev = info.rev; - shortRev = builtins.substring 0 7 info.rev; - } else { }) + } + // ( + if info ? rev then + { + rev = info.rev; + shortRev = builtins.substring 0 7 info.rev; + } + else + { } + ) else if info.type == "path" then { outPath = builtins.path { path = info.path; }; @@ -61,55 +71,53 @@ let shortRev = builtins.substring 0 7 info.rev; } else - # FIXME: add Mercurial, tarball inputs. + # FIXME: add Mercurial, tarball inputs. throw "flake input has unsupported input type '${info.type}'"; - allNodes = - builtins.mapAttrs - (key: node: - let - sourceInfo = - if key == lockFile.root - then { } - else fetchTree (node.info or { } // removeAttrs node.locked [ "dir" ]); - - inputs = builtins.mapAttrs - (inputName: inputSpec: allNodes.${resolveInput inputSpec}) - (node.inputs or { }); + allNodes = builtins.mapAttrs ( + key: node: + let + sourceInfo = + if key == lockFile.root then + { } + else + fetchTree (node.info or { } // removeAttrs node.locked [ "dir" ]); - # Resolve a input spec into a node name. An input spec is - # either a node name, or a 'follows' path from the root - # node. - resolveInput = inputSpec: - if builtins.isList inputSpec - then getInputByPath lockFile.root inputSpec - else inputSpec; + inputs = builtins.mapAttrs (inputName: inputSpec: allNodes.${resolveInput inputSpec}) ( + node.inputs or { } + ); - # Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the - # root node, returning the final node. - getInputByPath = nodeName: path: - if path == [ ] - then nodeName - else - getInputByPath - # Since this could be a 'follows' input, call resolveInput. - (resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path}) - (builtins.tail path); + # Resolve a input spec into a node name. An input spec is + # either a node name, or a 'follows' path from the root + # node. + resolveInput = + inputSpec: if builtins.isList inputSpec then getInputByPath lockFile.root inputSpec else inputSpec; - result = sourceInfo // { inherit inputs; inherit sourceInfo; }; - in - if node.flake or true then - result + # Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the + # root node, returning the final node. + getInputByPath = + nodeName: path: + if path == [ ] then + nodeName else - sourceInfo - ) - lockFile.nodes; + getInputByPath + # Since this could be a 'follows' input, call resolveInput. + (resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path}) + (builtins.tail path); + + result = sourceInfo // { + inherit inputs; + inherit sourceInfo; + }; + in + if node.flake or true then result else sourceInfo + ) lockFile.nodes; result = - if lockFile.version >= 5 && lockFile.version <= 7 - then allNodes.${lockFile.root}.inputs - else throw "lock file '${lockFilePath}' has unsupported version ${toString lockFile.version}"; + if lockFile.version >= 5 && lockFile.version <= 7 then + allNodes.${lockFile.root}.inputs + else + throw "lock file '${lockFilePath}' has unsupported version ${toString lockFile.version}"; in result - diff --git a/flake.nix b/flake.nix index f9f92c06..7baec94f 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,8 @@ # nix flake update inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - outputs = { self, nixpkgs }: + outputs = + { self, nixpkgs }: let systems = [ "aarch64-darwin" @@ -14,46 +15,62 @@ "x86_64-linux" ]; - eachSystem = f: nixpkgs.lib.genAttrs systems (system: f rec { - inherit system; - pkgs = nixpkgs.legacyPackages.${system}; - devshell = import ./. { nixpkgs = pkgs; }; - }); + eachSystem = + f: + nixpkgs.lib.genAttrs systems ( + system: + f rec { + inherit system; + pkgs = nixpkgs.legacyPackages.${system}; + devshell = import ./. { nixpkgs = pkgs; }; + } + ); in { - packages = eachSystem ({ pkgs, system, devshell }: { - docs = pkgs.writeShellApplication { - name = "docs"; - meta.description = ''Run mdBook server at http://localhost:3000''; - runtimeInputs = [ pkgs.mdbook ]; - text = '' - cd docs - cp ${devshell.modules-docs.markdown} src/modules_schema.md - mdbook serve - ''; - }; - bench = pkgs.writeShellApplication { - name = "benchmark"; - meta.description = ''Run benchmark''; - runtimeInputs = [ pkgs.hyperfine ]; - text = '' - cd benchmark - hyperfine -w 3 \ - 'nix-instantiate ../shell.nix' \ - 'nix-instantiate ./devshell-nix.nix' \ - 'nix-instantiate ./devshell-toml.nix' \ - 'nix-instantiate ./nixpkgs-mkshell.nix' - ''; - }; - # expose devshell as an executable package - default = self.devShells.${system}.default; - }); + packages = eachSystem ( + { + pkgs, + system, + devshell, + }: + { + docs = pkgs.writeShellApplication { + name = "docs"; + meta.description = ''Run mdBook server at http://localhost:3000''; + runtimeInputs = [ pkgs.mdbook ]; + text = '' + cd docs + cp ${devshell.modules-docs.markdown} src/modules_schema.md + mdbook serve + ''; + }; + bench = pkgs.writeShellApplication { + name = "benchmark"; + meta.description = ''Run benchmark''; + runtimeInputs = [ pkgs.hyperfine ]; + text = '' + cd benchmark + hyperfine -w 3 \ + 'nix-instantiate ../shell.nix' \ + 'nix-instantiate ./devshell-nix.nix' \ + 'nix-instantiate ./devshell-toml.nix' \ + 'nix-instantiate ./nixpkgs-mkshell.nix' + ''; + }; + # expose devshell as an executable package + default = self.devShells.${system}.default; + } + ); - devShells = eachSystem ({ devshell, ... }: { - default = devshell.fromTOML ./devshell.toml; - }); + devShells = eachSystem ( + { devshell, ... }: + { + default = devshell.fromTOML ./devshell.toml; + } + ); - legacyPackages = eachSystem ({ system, pkgs, ... }: + legacyPackages = eachSystem ( + { system, pkgs, ... }: import self { inherit system; inputs = null; @@ -61,16 +78,20 @@ } ); - checks = eachSystem ({ pkgs, ... }: + checks = eachSystem ( + { pkgs, ... }: with pkgs.lib; pipe (import ./tests { inherit pkgs; }) [ (collect isDerivation) - (map (x: { name = x.name or x.pname; value = x; })) + (map (x: { + name = x.name or x.pname; + value = x; + })) listToAttrs ] ); - formatter = eachSystem ({ pkgs, ... }: pkgs.nixpkgs-fmt); + formatter = eachSystem ({ pkgs, ... }: pkgs.nixfmt-rfc-style); # Import this overlay into your instance of nixpkgs overlays.default = import ./overlay.nix; diff --git a/modules/back-compat.nix b/modules/back-compat.nix index 6413aef6..3d94cda0 100644 --- a/modules/back-compat.nix +++ b/modules/back-compat.nix @@ -1,4 +1,9 @@ -{ lib, pkgs, config, ... }: +{ + lib, + pkgs, + config, + ... +}: # Avoid breaking back-compat for now. let # Because we want to be able to push pure JSON-like data into the @@ -54,6 +59,5 @@ with lib; interactive.bash_interactive = noDepEntry config.bash.interactive; } // (lib.optionalAttrs (config.motd != null) { motd = config.motd; }) - // (lib.optionalAttrs (config.name != null) { name = config.name; }) - ; + // (lib.optionalAttrs (config.name != null) { name = config.name; }); } diff --git a/modules/commands.nix b/modules/commands.nix index d4e74e89..3e1e109f 100644 --- a/modules/commands.nix +++ b/modules/commands.nix @@ -1,4 +1,9 @@ -{ lib, config, pkgs, ... }: +{ + lib, + config, + pkgs, + ... +}: with lib; let ansi = import ../nix/ansi.nix; @@ -11,87 +16,78 @@ let inherit (pkgs) lib writeTextFile bash; }; - pad = str: num: - if num > 0 then - pad "${str} " (num - 1) - else - str; + pad = str: num: if num > 0 then pad "${str} " (num - 1) else str; # Fallback to the package pname if the name is unset - resolveName = cmd: + resolveName = + cmd: if cmd.name == null then cmd.package.pname or (builtins.parseDrvName cmd.package.name).name else cmd.name; # Fill in default options for a command. - commandToPackage = cmd: - assert lib.assertMsg (cmd.command == null || cmd.name != cmd.command) "[[commands]]: ${toString cmd.name} cannot be set to both the `name` and the `command` attributes. Did you mean to use the `package` attribute?"; - assert lib.assertMsg (cmd.package != null || (cmd.command != null && cmd.command != "")) "[[commands]]: ${resolveName cmd} expected either a command or package attribute."; + commandToPackage = + cmd: + assert lib.assertMsg (cmd.command == null || cmd.name != cmd.command) + "[[commands]]: ${toString cmd.name} cannot be set to both the `name` and the `command` attributes. Did you mean to use the `package` attribute?"; + assert lib.assertMsg ( + cmd.package != null || (cmd.command != null && cmd.command != "") + ) "[[commands]]: ${resolveName cmd} expected either a command or package attribute."; if cmd.package == null then - writeDefaultShellScript - { - name = cmd.name; - text = cmd.command; - binPrefix = true; - } + writeDefaultShellScript { + name = cmd.name; + text = cmd.command; + binPrefix = true; + } else cmd.package; - commandsToMenu = cmds: + commandsToMenu = + cmds: let - cleanName = { name, package, ... }@cmd: - assert lib.assertMsg (cmd.name != null || cmd.package != null) "[[commands]]: some command is missing both a `name` or `package` attribute."; + cleanName = + { name, package, ... }@cmd: + assert lib.assertMsg ( + cmd.name != null || cmd.package != null + ) "[[commands]]: some command is missing both a `name` or `package` attribute."; let name = resolveName cmd; - help = - if cmd.help == null then - cmd.package.meta.description or "" - else - cmd.help; + help = if cmd.help == null then cmd.package.meta.description or "" else cmd.help; in - cmd // { - inherit name help; - }; + cmd // { inherit name help; }; commands = map cleanName cmds; - commandLengths = - map ({ name, ... }: builtins.stringLength name) commands; + commandLengths = map ({ name, ... }: builtins.stringLength name) commands; - maxCommandLength = - builtins.foldl' - (max: v: if v > max then v else max) - 0 - commandLengths - ; + maxCommandLength = builtins.foldl' (max: v: if v > max then v else max) 0 commandLengths; commandCategories = lib.unique ( (zipAttrsWithNames [ "category" ] (name: vs: vs) commands).category ); - commandByCategoriesSorted = - builtins.attrValues (lib.genAttrs - commandCategories - (category: lib.nameValuePair category (builtins.sort - (a: b: a.name < b.name) - (builtins.filter (x: x.category == category) commands) - )) - ); + commandByCategoriesSorted = builtins.attrValues ( + lib.genAttrs commandCategories ( + category: + lib.nameValuePair category ( + builtins.sort (a: b: a.name < b.name) (builtins.filter (x: x.category == category) commands) + ) + ) + ); - opCat = kv: + opCat = + kv: let category = kv.name; cmd = kv.value; - opCmd = { name, help, ... }: + opCmd = + { name, help, ... }: let len = maxCommandLength - (builtins.stringLength name); in - if help == null || help == "" then - " ${name}" - else - " ${pad name len} - ${help}"; + if help == null || help == "" then " ${name}" else " ${pad name len} - ${help}"; in "\n${ansi.bold}[${category}]${ansi.reset}\n\n" + builtins.concatStringsSep "\n" (map opCmd cmd); in diff --git a/modules/default.nix b/modules/default.nix index ab5057d1..4af22296 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,8 +1,9 @@ # Evaluate the devshell environment nixpkgs: -{ configuration -, lib ? nixpkgs.lib -, extraSpecialArgs ? { } +{ + configuration, + lib ? nixpkgs.lib, + extraSpecialArgs ? { }, }: let devenvModules = import ./modules.nix { diff --git a/modules/devshell.nix b/modules/devshell.nix index d70f3798..083efc3f 100644 --- a/modules/devshell.nix +++ b/modules/devshell.nix @@ -1,4 +1,10 @@ -{ config, lib, pkgs, options, ... }: +{ + config, + lib, + pkgs, + options, + ... +}: with lib; let cfg = config.devshell; @@ -19,7 +25,8 @@ let program = "${bin}"; }; - mkSetupHook = rc: + mkSetupHook = + rc: pkgs.stdenvNoCC.mkDerivation { name = "devshell-setup-hook"; setupHook = pkgs.writeText "devshell-setup-hook.sh" '' @@ -32,13 +39,18 @@ let mkNakedShell = pkgs.callPackage ../nix/mkNakedShell.nix { }; - addAttributeName = prefix: - mapAttrs (k: v: v // { - text = '' - #### ${prefix}.${k} - ${v.text} - ''; - }); + addAttributeName = + prefix: + mapAttrs ( + k: v: + v + // { + text = '' + #### ${prefix}.${k} + ${v.text} + ''; + } + ); entryOptions = { text = mkOption { @@ -93,7 +105,6 @@ let fi # Interactive session ''; - # This is our entrypoint script. entrypoint = pkgs.writeScript "${cfg.name}-entrypoint" '' #!${bashPath} @@ -215,13 +226,14 @@ let }; # Returns a list of all the input derivation ... for a derivation. - inputsOf = drv: - filter lib.isDerivation - ((drv.buildInputs or [ ]) ++ - (drv.nativeBuildInputs or [ ]) ++ - (drv.propagatedBuildInputs or [ ]) ++ - (drv.propagatedNativeBuildInputs or [ ])) - ; + inputsOf = + drv: + filter lib.isDerivation ( + (drv.buildInputs or [ ]) + ++ (drv.nativeBuildInputs or [ ]) + ++ (drv.propagatedBuildInputs or [ ]) + ++ (drv.propagatedNativeBuildInputs or [ ]) + ); in { @@ -276,9 +288,7 @@ in {202}🔨 Welcome to ${cfg.name}{reset} $(type -p menu &>/dev/null && menu) ''; - apply = replaceStrings - (map (key: "{${key}}") (attrNames ansi)) - (attrValues ansi); + apply = replaceStrings (map (key: "{${key}}") (attrNames ansi)) (attrValues ansi); description = '' Message Of The Day. @@ -341,7 +351,9 @@ in in types.nullOr (types.coercedTo types.nonEmptyStr coerceFunc envType); apply = x: if x == null then x else x // { name = "PRJ_ROOT"; }; - default = { eval = "$PWD"; }; + default = { + eval = "$PWD"; + }; example = lib.literalExpression '' { # Use the top-level directory of the working tree @@ -371,41 +383,43 @@ in packages = foldl' (sum: drv: sum ++ (inputsOf drv)) [ ] cfg.packagesFrom; - startup = { - motd = noDepEntry '' - __devshell-motd() { - cat < 0) "[[environ]]: ${name} expected one of (value|eval|prefix|unset) to be set."; - assert assertMsg ((length vals) < 2) "[[environ]]: ${name} expected only one of (value|eval|prefix|unset) to be set. Not ${toString vals}"; - assert assertMsg (!(name == "PATH" && valType == "value")) "[[environ]]: ${name} should not override the value. Use 'prefix' instead."; + assert assertMsg ( + (length vals) > 0 + ) "[[environ]]: ${name} expected one of (value|eval|prefix|unset) to be set."; + assert assertMsg ((length vals) < 2) + "[[environ]]: ${name} expected only one of (value|eval|prefix|unset) to be set. Not ${toString vals}"; + assert assertMsg ( + !(name == "PATH" && valType == "value") + ) "[[environ]]: ${name} should not override the value. Use 'prefix' instead."; if valType == "value" then "export ${name}=${escapeShellArg (toString value)}" else if valType == "eval" then diff --git a/modules/modules-docs.nix b/modules/modules-docs.nix index 547b9f77..56700d2f 100644 --- a/modules/modules-docs.nix +++ b/modules/modules-docs.nix @@ -1,7 +1,14 @@ # MIT - Copyright (c) 2017-2019 Robert Helgesson and Home Manager contributors. # # This is an adapted version of the original https://gitlab.com/rycee/nmd/ -{ lib, pkgs, options, config, modulesPath, ... }: +{ + lib, + pkgs, + options, + config, + modulesPath, + ... +}: with lib; let cfg = config.modules-docs; @@ -16,7 +23,8 @@ let # (either of `name`, `path` is required, the rest are optional). mkRelatedPackages = let - unpack = p: + unpack = + p: if isString p then { name = p; } else if isList p then @@ -24,26 +32,27 @@ let else p; - repack = args: + repack = + args: let name = args.name or (concatStringsSep "." args.path); path = args.path or [ args.name ]; - pkg = args.package or ( - let - bail = throw "Invalid package attribute path '${toString path}'"; - in - attrByPath path bail pkgs - ); + pkg = + args.package or ( + let + bail = throw "Invalid package attribute path '${toString path}'"; + in + attrByPath path bail pkgs + ); in { attrName = name; packageName = pkg.meta.name; available = pkg.meta.available; - } // optionalAttrs (pkg.meta ? description) { - inherit (pkg.meta) description; - } // optionalAttrs (pkg.meta ? longDescription) { - inherit (pkg.meta) longDescription; - } // optionalAttrs (args ? comment) { inherit (args) comment; }; + } + // optionalAttrs (pkg.meta ? description) { inherit (pkg.meta) description; } + // optionalAttrs (pkg.meta ? longDescription) { inherit (pkg.meta) longDescription; } + // optionalAttrs (args ? comment) { inherit (args) comment; }; in map (p: repack (unpack p)); @@ -51,21 +60,19 @@ let # to the repo root, and URL points to an online view of the module. mkDeclaration = let - rootsWithPrefixes = map - (p: p // { prefix = "${toString p.path}/"; }) - cfg.roots; + rootsWithPrefixes = map (p: p // { prefix = "${toString p.path}/"; }) cfg.roots; in decl: let - root = lib.findFirst - (x: lib.hasPrefix x.prefix decl) - null - rootsWithPrefixes; + root = lib.findFirst (x: lib.hasPrefix x.prefix decl) null rootsWithPrefixes; in if root == null then - # We need to strip references to /nix/store/* from the options or - # else the build will fail. - { path = removePrefix "${builtins.storeDir}/" decl; url = ""; } + # We need to strip references to /nix/store/* from the options or + # else the build will fail. + { + path = removePrefix "${builtins.storeDir}/" decl; + url = ""; + } else rec { path = removePrefix root.prefix decl; @@ -73,7 +80,8 @@ let }; # Sort modules and put "enable" and "package" declarations first. - moduleDocCompare = a: b: + moduleDocCompare = + a: b: let isEnable = lib.hasPrefix "enable"; isPackage = lib.hasPrefix "package"; @@ -83,7 +91,8 @@ let compareLists moduleCmp a.loc b.loc < 0; # Replace functions by the string - substFunction = x: + substFunction = + x: if builtins.isAttrs x then mapAttrs (name: substFunction) x else if builtins.isList x then @@ -93,7 +102,8 @@ let else x; - cleanUpOption = opt: + cleanUpOption = + opt: let applyOnAttr = n: f: optionalAttrs (hasAttr n opt) { ${n} = f opt.${n}; }; in @@ -105,23 +115,21 @@ let // applyOnAttr "relatedPackages" mkRelatedPackages; optionsDocs = map cleanUpOption ( - sort - moduleDocCompare - ( - filter - (opt: opt.visible && !opt.internal) - (optionAttrSetToDocList options) - ) + sort moduleDocCompare (filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options)) ); # TODO: display values like TOML instead. - toMarkdown = optionsDocs: + toMarkdown = + optionsDocs: let optionsDocsPartitioned = partition (opt: head opt.loc != "_module") optionsDocs; # TODO: handle opt.relatedPackages. What is it for? - optToMd = opt: - let heading = lib.showOption opt.loc; in + optToMd = + opt: + let + heading = lib.showOption opt.loc; + in '' ### `${heading}` @@ -131,15 +139,15 @@ let + '' **Type**: - + ```console ${opt.type} ``` '' + (lib.optionalString (opt ? default && opt.default != null) '' - + **Default value**: - + ```nix ${removeSuffix "\n" opt.default.text} ``` @@ -147,7 +155,7 @@ let + (lib.optionalString (opt ? example) '' **Example value**: - + ```nix ${removeSuffix "\n" opt.example.text} ``` @@ -157,16 +165,8 @@ let **Declared in**: '' - + ( - lib.concatStringsSep - "\n" - (map - (decl: "- [${decl.path}](${decl.url})") - opt.declarations - ) - ) - + "\n" - ; + + (lib.concatStringsSep "\n" (map (decl: "- [${decl.path}](${decl.url})") opt.declarations)) + + "\n"; doc = [ "## Options\n" (concatStringsSep "\n" (map optToMd optionsDocsPartitioned.right)) diff --git a/modules/modules.nix b/modules/modules.nix index f4a8e507..6cebe3c4 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -1,6 +1,4 @@ -{ pkgs -, lib -}: +{ pkgs, lib }: let modules = [ ./back-compat.nix @@ -10,21 +8,25 @@ let ./modules-docs.nix { # Configure modules-docs - config.modules-docs.roots = [{ - url = "https://github.com/numtide/devshell"; - path = toString ../.; - branch = "main"; - }]; + config.modules-docs.roots = [ + { + url = "https://github.com/numtide/devshell"; + path = toString ../.; + branch = "main"; + } + ]; } ./services.nix ]; - pkgsModule = { config, ... }: { - config = { - _module.args.baseModules = modules; - _module.args.pkgsPath = lib.mkDefault pkgs.path; - _module.args.pkgs = lib.mkDefault pkgs; + pkgsModule = + { config, ... }: + { + config = { + _module.args.baseModules = modules; + _module.args.pkgsPath = lib.mkDefault pkgs.path; + _module.args.pkgs = lib.mkDefault pkgs; + }; }; - }; in [ pkgsModule ] ++ modules diff --git a/modules/services.nix b/modules/services.nix index 94546bc7..fb4e264d 100644 --- a/modules/services.nix +++ b/modules/services.nix @@ -1,4 +1,9 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: with lib; let serviceOptions = { @@ -39,10 +44,15 @@ let ''; }; }; - groupToProcfile = name: g: pkgs.writeText "Procfile.${name}" (concatLines - (mapAttrsToList (sName: s: "${if s.name == null then sName else s.name}: ${s.command}") g.services) - ); - groupToCommands = gName: g: + groupToProcfile = + name: g: + pkgs.writeText "Procfile.${name}" ( + concatLines ( + mapAttrsToList (sName: s: "${if s.name == null then sName else s.name}: ${s.command}") g.services + ) + ); + groupToCommands = + gName: g: let procfile = groupToProcfile gName g; description = if g.description == null then gName else g.description; @@ -52,35 +62,37 @@ let name = "${gName}:start"; category = "service groups"; help = "Start ${description} services"; - command = (pkgs.writeShellScript "${gName}-services-start" '' - if [ -e "$PRJ_DATA_DIR/pids/${gName}.pid" ]; then - echo "Already running, refusing to start" - exit 1 - fi - mkdir -p "$PRJ_DATA_DIR/pids/" - ${pkgs.honcho}/bin/honcho start -f ${procfile} -d "$PRJ_ROOT" & - pid=$! - echo $pid > "$PRJ_DATA_DIR/pids/${gName}.pid" - on_stop() { - kill -TERM $pid - rm "$PRJ_DATA_DIR/pids/${gName}.pid" - wait $pid - } - trap "on_stop" SIGINT SIGTERM SIGHUP - wait $pid - '').outPath; + command = + (pkgs.writeShellScript "${gName}-services-start" '' + if [ -e "$PRJ_DATA_DIR/pids/${gName}.pid" ]; then + echo "Already running, refusing to start" + exit 1 + fi + mkdir -p "$PRJ_DATA_DIR/pids/" + ${pkgs.honcho}/bin/honcho start -f ${procfile} -d "$PRJ_ROOT" & + pid=$! + echo $pid > "$PRJ_DATA_DIR/pids/${gName}.pid" + on_stop() { + kill -TERM $pid + rm "$PRJ_DATA_DIR/pids/${gName}.pid" + wait $pid + } + trap "on_stop" SIGINT SIGTERM SIGHUP + wait $pid + '').outPath; } { name = "${gName}:stop"; category = "service groups"; help = "Stop ${description} services"; - command = (pkgs.writeShellScript "${gName}-services-stop" '' - if [ -e "$PRJ_DATA_DIR/pids/${gName}.pid" ]; then - pid=$(cat "$PRJ_DATA_DIR/pids/${gName}.pid") - kill -TERM $pid - rm "$PRJ_DATA_DIR/pids/${gName}.pid" - fi - '').outPath; + command = + (pkgs.writeShellScript "${gName}-services-stop" '' + if [ -e "$PRJ_DATA_DIR/pids/${gName}.pid" ]; then + pid=$(cat "$PRJ_DATA_DIR/pids/${gName}.pid") + kill -TERM $pid + rm "$PRJ_DATA_DIR/pids/${gName}.pid" + fi + '').outPath; } ]; in @@ -93,5 +105,9 @@ in ''; }; - config.commands = foldl (l: r: l ++ r) [ ] (mapAttrsToList (gName: g: groupToCommands (if g.name == null then gName else g.name) g) config.serviceGroups); + config.commands = foldl (l: r: l ++ r) [ ] ( + mapAttrsToList ( + gName: g: groupToCommands (if g.name == null then gName else g.name) g + ) config.serviceGroups + ); } diff --git a/nix/ansi.nix b/nix/ansi.nix index f2155def..941a52cc 100644 --- a/nix/ansi.nix +++ b/nix/ansi.nix @@ -10,4 +10,7 @@ in bold = "${esc}[1m"; italic = "${esc}[3m"; underline = "${esc}[4m"; -} // (foldl' (x: y: x // { "${toString y}" = "${esc}[38;5;${toString y}m"; }) { } (genList (x: x) 256)) +} +// (foldl' (x: y: x // { "${toString y}" = "${esc}[38;5;${toString y}m"; }) { } ( + genList (x: x) 256 +)) diff --git a/nix/importTOML.nix b/nix/importTOML.nix index 40106b33..1c6f58f9 100644 --- a/nix/importTOML.nix +++ b/nix/importTOML.nix @@ -1,5 +1,6 @@ let - importTOML = file: + importTOML = + file: # Return a module that gets lib as an argument { lib, ... }: let @@ -9,22 +10,18 @@ let extraModulesDir = toString ../extra; extraModules = builtins.readDir extraModulesDir; - importModule = str: + importModule = + str: let repoFile = "${dir}/${str}"; - extraFile = - "${extraModulesDir}/${builtins.replaceStrings [ "." ] [ "/" ] str}.nix"; + extraFile = "${extraModulesDir}/${builtins.replaceStrings [ "." ] [ "/" ] str}.nix"; in # First try to import from the user's repository - if lib.hasPrefix "./" str || lib.hasSuffix ".nix" str || lib.hasSuffix ".toml" str - then - ( - if lib.hasSuffix ".toml" str - then importTOML repoFile - else import repoFile - ) + if lib.hasPrefix "./" str || lib.hasSuffix ".nix" str || lib.hasSuffix ".toml" str then + (if lib.hasSuffix ".toml" str then importTOML repoFile else import repoFile) # Then fallback on the extra modules - else import extraFile; + else + import extraFile; in { _file = file; diff --git a/nix/mkNakedShell.nix b/nix/mkNakedShell.nix index 2154be45..437efc45 100644 --- a/nix/mkNakedShell.nix +++ b/nix/mkNakedShell.nix @@ -1,7 +1,8 @@ -{ bashInteractive -, coreutils -, stdenv -, writeTextFile +{ + bashInteractive, + coreutils, + stdenv, + writeTextFile, }: let bashPath = "${bashInteractive}/bin/bash"; @@ -19,12 +20,13 @@ let ''; }; in -{ name -, # A path to a buildEnv that will be loaded by the shell. +{ + name, + # A path to a buildEnv that will be loaded by the shell. # We assume that the buildEnv contains an ./env.bash script. - profile -, meta ? { } -, passthru ? { } + profile, + meta ? { }, + passthru ? { }, }: (derivation { inherit name; @@ -35,7 +37,10 @@ in builder = bashPath; # Bring in the dependencies on `nix-build` - args = [ "-ec" "${coreutils}/bin/ln -s ${profile} $out; exit 0" ]; + args = [ + "-ec" + "${coreutils}/bin/ln -s ${profile} $out; exit 0" + ]; # $stdenv/setup is loaded by nix-shell during startup. # https://github.com/nixos/nix/blob/377345e26f1ac4bbc87bb21debcc52a1d03230aa/src/nix-build/nix-build.cc#L429-L432 @@ -60,4 +65,8 @@ in # Load the environment source "${profile}/env.bash" ''; -}) // { inherit meta passthru; } // passthru +}) +// { + inherit meta passthru; +} +// passthru diff --git a/nix/source.nix b/nix/source.nix index c8485ee9..95a6d557 100644 --- a/nix/source.nix +++ b/nix/source.nix @@ -20,36 +20,39 @@ let lenContent = stringLength content; lenSuffix = stringLength suffix; in - lenContent >= lenSuffix && - substring (lenContent - lenSuffix) lenContent content == suffix; + lenContent >= lenSuffix && substring (lenContent - lenSuffix) lenContent content == suffix; # If an argument to allow or deny is a path, transform it to a matcher. # # This probably needs more work, I don't think that it works on sub-folders. - toMatcher = f: + toMatcher = + f: let path_ = toString f; in - if isFunction f then f - else - (path: type: path_ == toString path); + if isFunction f then f else (path: type: path_ == toString path); in { # Match paths with the given extension - matchExt = ext: - path: type: - (hasSuffix ".${ext}" path); + matchExt = + ext: path: type: + (hasSuffix ".${ext}" path); # A proper filter - filter = { path, name ? "source", allow ? [ ], deny ? [ ] }: + filter = + { + path, + name ? "source", + allow ? [ ], + deny ? [ ], + }: let allow_ = builtins.map toMatcher allow; deny_ = builtins.map toMatcher deny; in builtins.path { inherit name path; - filter = path: type: - (builtins.any (f: f path type) allow_) && - (!builtins.any (f: f path type) deny_); + filter = + path: type: (builtins.any (f: f path type) allow_) && (!builtins.any (f: f path type) deny_); }; } diff --git a/nix/strOrPackage.nix b/nix/strOrPackage.nix index 7d49d7d6..f0794021 100644 --- a/nix/strOrPackage.nix +++ b/nix/strOrPackage.nix @@ -1,7 +1,8 @@ { lib, pkgs }: with lib; let - resolveKey = key: + resolveKey = + key: let attrs = builtins.filter builtins.isString (builtins.split "\\." key); op = sum: attr: sum.${attr} or (throw "package \"${key}\" not found"); diff --git a/nix/writeDefaultShellScript.nix b/nix/writeDefaultShellScript.nix index 83a4d489..4c0215a2 100644 --- a/nix/writeDefaultShellScript.nix +++ b/nix/writeDefaultShellScript.nix @@ -1,20 +1,23 @@ -{ lib, writeTextFile, bash }: +{ + lib, + writeTextFile, + bash, +}: /* Similar to writeShellScript, except that a default shebang can be provided Either the script already has a shebang, or one will be provided for it. */ -{ name -, text -, defaultShebang ? "#!${bash}/bin/bash\nset -euo pipefail\n" -, checkPhase ? null -, binPrefix ? false +{ + name, + text, + defaultShebang ? "#!${bash}/bin/bash\nset -euo pipefail\n", + checkPhase ? null, + binPrefix ? false, }: let - script = - if lib.hasPrefix "#!" text then text - else "${defaultShebang}\n${text}"; + script = if lib.hasPrefix "#!" text then text else "${defaultShebang}\n${text}"; in writeTextFile ( { @@ -23,5 +26,5 @@ writeTextFile ( executable = true; } // (lib.optionalAttrs (checkPhase != null) { inherit checkPhase; }) - // (lib.optionalAttrs binPrefix { destination = "/bin/${name}"; }) + // (lib.optionalAttrs binPrefix { destination = "/bin/${name}"; }) ) diff --git a/overlay.nix b/overlay.nix index 2d195552..d67260c1 100644 --- a/overlay.nix +++ b/overlay.nix @@ -1,5 +1,2 @@ # Import this overlay in your project to add devshell -final: prev: -{ - devshell = import ./. { nixpkgs = final; }; -} +final: prev: { devshell = import ./. { nixpkgs = final; }; } diff --git a/shell.nix b/shell.nix index 1315be62..5a0a3c84 100755 --- a/shell.nix +++ b/shell.nix @@ -1,6 +1,8 @@ #!/usr/bin/env nix-build # Used to test the shell -{ system ? builtins.currentSystem }: +{ + system ? builtins.currentSystem, +}: let devshell = import ./. { inherit system; }; in diff --git a/templates/flake-parts/flake.nix b/templates/flake-parts/flake.nix index 1236c804..556562ec 100644 --- a/templates/flake-parts/flake.nix +++ b/templates/flake-parts/flake.nix @@ -4,11 +4,15 @@ inputs.devshell.url = "github:numtide/devshell"; inputs.flake-parts.url = "github:hercules-ci/flake-parts"; - outputs = inputs@{ self, flake-parts, devshell, nixpkgs }: + outputs = + inputs@{ + self, + flake-parts, + devshell, + nixpkgs, + }: flake-parts.lib.mkFlake { inherit inputs; } { - imports = [ - devshell.flakeModule - ]; + imports = [ devshell.flakeModule ]; systems = [ "aarch64-darwin" @@ -18,8 +22,10 @@ "x86_64-linux" ]; - perSystem = { pkgs, ... }: { - devshells.default = { }; - }; + perSystem = + { pkgs, ... }: + { + devshells.default = { }; + }; }; } diff --git a/templates/gettingStartedExample/flake.nix b/templates/gettingStartedExample/flake.nix index 421d1412..e7dd1124 100644 --- a/templates/gettingStartedExample/flake.nix +++ b/templates/gettingStartedExample/flake.nix @@ -4,7 +4,13 @@ inputs.devshell.url = "github:numtide/devshell"; inputs.flake-utils.url = "github:numtide/flake-utils"; - outputs = { self, flake-utils, devshell, nixpkgs }: + outputs = + { + self, + flake-utils, + devshell, + nixpkgs, + }: flake-utils.lib.eachDefaultSystem (system: { devShell = let @@ -14,8 +20,6 @@ overlays = [ devshell.overlays.default ]; }; in - pkgs.devshell.mkShell { - imports = [ (pkgs.devshell.importTOML ./devshell.toml) ]; - }; + pkgs.devshell.mkShell { imports = [ (pkgs.devshell.importTOML ./devshell.toml) ]; }; }); } diff --git a/templates/toml/flake.nix b/templates/toml/flake.nix index 31bc13f0..5289b771 100644 --- a/templates/toml/flake.nix +++ b/templates/toml/flake.nix @@ -9,7 +9,14 @@ flake = false; }; - outputs = { self, flake-utils, devshell, nixpkgs, ... }: + outputs = + { + self, + flake-utils, + devshell, + nixpkgs, + ... + }: flake-utils.lib.eachDefaultSystem (system: { devShells.default = let @@ -19,8 +26,6 @@ overlays = [ devshell.overlays.default ]; }; in - pkgs.devshell.mkShell { - imports = [ (pkgs.devshell.importTOML ./devshell.toml) ]; - }; + pkgs.devshell.mkShell { imports = [ (pkgs.devshell.importTOML ./devshell.toml) ]; }; }); } diff --git a/templates/toml/shell.nix b/templates/toml/shell.nix index 597b64b2..d7bad492 100644 --- a/templates/toml/shell.nix +++ b/templates/toml/shell.nix @@ -1,23 +1,18 @@ # Use `builtins.getFlake` if available -if builtins ? getFlake -then +if builtins ? getFlake then let - scheme = - if builtins.pathExists ./.git - then "git+file" - else "path"; + scheme = if builtins.pathExists ./.git then "git+file" else "path"; in (builtins.getFlake "${scheme}://${toString ./.}").devShells.${builtins.currentSystem}.default # Otherwise we'll use the flake-compat shim else - (import - ( - let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } - ) - { src = ./.; } - ).shellNix + (import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) { src = ./.; }).shellNix diff --git a/tests/core/commands.nix b/tests/core/commands.nix index 2376b2f4..43b5eb6f 100644 --- a/tests/core/commands.nix +++ b/tests/core/commands.nix @@ -1,4 +1,8 @@ -{ pkgs, devshell, runTest }: +{ + pkgs, + devshell, + runTest, +}: { # Basic devshell usage commands-1 = @@ -23,9 +27,7 @@ print("hello-python") ''; } - { - package = "git"; - } + { package = "git"; } ]; }; in diff --git a/tests/core/devshell.nix b/tests/core/devshell.nix index 67e352c5..d4605e0d 100644 --- a/tests/core/devshell.nix +++ b/tests/core/devshell.nix @@ -1,4 +1,8 @@ -{ pkgs, devshell, runTest }: +{ + pkgs, + devshell, + runTest, +}: { # Basic devshell package usage devshell-packages-1 = @@ -7,7 +11,12 @@ devshell.name = "devshell-1"; devshell.packages = [ pkgs.git ]; devshell.packagesFrom = [ - (pkgs.hello.overrideAttrs { buildInputs = [ null pkgs.cowsay ]; }) + (pkgs.hello.overrideAttrs { + buildInputs = [ + null + pkgs.cowsay + ]; + }) ]; }; in @@ -23,7 +32,7 @@ # Adds packages to the PATH type -p git - + # Adds packages from packagesFrom to the PATH type -p cowsay ''; diff --git a/tests/core/env.nix b/tests/core/env.nix index 29d2b511..b0a096c4 100644 --- a/tests/core/env.nix +++ b/tests/core/env.nix @@ -1,4 +1,8 @@ -{ pkgs, devshell, runTest }: +{ + pkgs, + devshell, + runTest, +}: { # Test the environment variables env-1 = diff --git a/tests/core/modules-docs.nix b/tests/core/modules-docs.nix index 7ce01fe5..f88d9bfd 100644 --- a/tests/core/modules-docs.nix +++ b/tests/core/modules-docs.nix @@ -1,10 +1,12 @@ -{ pkgs, devshell, runTest }: +{ + pkgs, + devshell, + runTest, +}: { modules-docs-1 = let - shell = devshell.mkShell { - devshell.name = "modules-docs"; - }; + shell = devshell.mkShell { devshell.name = "modules-docs"; }; in runTest "modules-docs-1" { } '' # The Markdown gets generated and is a derivation diff --git a/tests/default.nix b/tests/default.nix index 7c86aaef..af6b94c5 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,15 +1,20 @@ -{ system ? builtins.currentSystem -, inputs ? import ../flake.lock.nix { } -, pkgs ? import inputs.nixpkgs { +{ + system ? builtins.currentSystem, + inputs ? import ../flake.lock.nix { }, + pkgs ? import inputs.nixpkgs { inherit system; # Makes the config pure as well. See /top-level/impure.nix: config = { }; overlays = [ ]; - } + }, }: let - devshell = import ../. { inputs = null; nixpkgs = pkgs; }; - runTest = name: attrs: script: + devshell = import ../. { + inputs = null; + nixpkgs = pkgs; + }; + runTest = + name: attrs: script: pkgs.runCommand name attrs '' source ${./assert.sh} @@ -22,21 +27,26 @@ let ''; # Arguments to pass to each test file - attrs = { inherit pkgs devshell runTest; }; + attrs = { + inherit pkgs devshell runTest; + }; # Attrs marked with this attribute are recursed into by nix-build - recursive = { recurseForDerivations = true; }; + recursive = { + recurseForDerivations = true; + }; - loadDir = testPrefix: dir: + loadDir = + testPrefix: dir: let data = builtins.readDir dir; - op = sum: name: + op = + sum: name: let path = "${dir}/${name}"; type = data.${name}; # Nix doesn't recurse into attrs that have dots in them... - attr = builtins.replaceStrings [ "." ] [ "-" ] - (pkgs.lib.removeSuffix ".nix" name); + attr = builtins.replaceStrings [ "." ] [ "-" ] (pkgs.lib.removeSuffix ".nix" name); args = attrs // { # Customize runTest @@ -44,11 +54,7 @@ let }; in assert type == "regular"; - sum // - { - "${attr}" = recursive // (import path args); - } - ; + sum // { "${attr}" = recursive // (import path args); }; in builtins.foldl' op recursive (builtins.attrNames data); in diff --git a/tests/extra/git.hooks.nix b/tests/extra/git.hooks.nix index 367ea358..ba331de3 100644 --- a/tests/extra/git.hooks.nix +++ b/tests/extra/git.hooks.nix @@ -1,4 +1,8 @@ -{ pkgs, devshell, runTest }: +{ + pkgs, + devshell, + runTest, +}: { # Basic git.hooks module tests git-hooks-1 = @@ -19,9 +23,7 @@ git.hooks.enable = true; }; - shell3 = devshell.mkShell { - devshell.name = "git-hooks-1c"; - }; + shell3 = devshell.mkShell { devshell.name = "git-hooks-1c"; }; shell4 = devshell.mkShell { imports = [ ../../extra/git/hooks.nix ]; diff --git a/tests/extra/language.c.nix b/tests/extra/language.c.nix index 3ee397db..3d994ac4 100644 --- a/tests/extra/language.c.nix +++ b/tests/extra/language.c.nix @@ -1,4 +1,8 @@ -{ pkgs, devshell, runTest }: +{ + pkgs, + devshell, + runTest, +}: { # Basic test language-c-1 = diff --git a/tests/extra/language.hare.nix b/tests/extra/language.hare.nix index d67c8a88..4699212a 100644 --- a/tests/extra/language.hare.nix +++ b/tests/extra/language.hare.nix @@ -5,13 +5,14 @@ }: pkgs.lib.optionalAttrs (!pkgs.hostPlatform.isDarwin) { # Basic test - language-hare-1 = let - shell = devshell.mkShell { - imports = [../../extra/language/hare.nix]; - devshell.name = "devshell-1"; - }; - in - runTest "language-hare-1" {} '' + language-hare-1 = + let + shell = devshell.mkShell { + imports = [ ../../extra/language/hare.nix ]; + devshell.name = "devshell-1"; + }; + in + runTest "language-hare-1" { } '' # Load the devshell source ${shell}/env.bash @@ -21,17 +22,18 @@ pkgs.lib.optionalAttrs (!pkgs.hostPlatform.isDarwin) { # Test good HAREPATH value # TODO: When the nixpkgs input is updated, change hare-ev to hare-png, so # that the inclusion of propagatedBuildInputs third-party libraries is also tested. - language-hare-2 = let - shell = devshell.mkShell { - imports = [../../extra/language/hare.nix]; - devshell.name = "devshell-2"; - language.hare = { - thirdPartyLibs = [pkgs.hareThirdParty.hare-compress]; - vendoredLibs = ["./vendor/lib"]; + language-hare-2 = + let + shell = devshell.mkShell { + imports = [ ../../extra/language/hare.nix ]; + devshell.name = "devshell-2"; + language.hare = { + thirdPartyLibs = [ pkgs.hareThirdParty.hare-compress ]; + vendoredLibs = [ "./vendor/lib" ]; + }; }; - }; - in - runTest "language-hare-2" {} '' + in + runTest "language-hare-2" { } '' # Load the devshell source ${shell}/env.bash diff --git a/tests/extra/language.perl.nix b/tests/extra/language.perl.nix index af3a3dfa..5d5bc2d6 100644 --- a/tests/extra/language.perl.nix +++ b/tests/extra/language.perl.nix @@ -1,4 +1,8 @@ -{ pkgs, devshell, runTest }: +{ + pkgs, + devshell, + runTest, +}: { # Basic test simple = diff --git a/tests/extra/language.rust.nix b/tests/extra/language.rust.nix index c9c3f8c1..da87ba78 100644 --- a/tests/extra/language.rust.nix +++ b/tests/extra/language.rust.nix @@ -1,4 +1,8 @@ -{ pkgs, devshell, runTest }: +{ + pkgs, + devshell, + runTest, +}: { # Basic test simple = diff --git a/tests/extra/locale.nix b/tests/extra/locale.nix index 9e313dcb..e1c51c09 100644 --- a/tests/extra/locale.nix +++ b/tests/extra/locale.nix @@ -1,4 +1,8 @@ -{ pkgs, devshell, runTest }: +{ + pkgs, + devshell, + runTest, +}: { # Basic test simple = diff --git a/tests/extra/services.postgres.nix b/tests/extra/services.postgres.nix index 96fc7f39..a1c8e43c 100644 --- a/tests/extra/services.postgres.nix +++ b/tests/extra/services.postgres.nix @@ -1,4 +1,8 @@ -{ pkgs, devshell, runTest }: +{ + pkgs, + devshell, + runTest, +}: { # Basic test simple =