Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ jobs:
name: numtide
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix flake check
- run: nix develop -c echo OK
- name: Run devshell entry sanity checks
run: |
nix develop -c echo OK
for tmpl in ./templates/*; do
if ! [ -d "$tmpl" ]; then
continue
fi
nix develop --override-input devshell . "$tmpl" -c echo OK
done
- name: Run nix flake archive
run: nix flake archive
docs:
Expand Down
7 changes: 5 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ let
in
rec {
# Folder that contains all the extra modules
extraModulesDir = toString ./extra;
extraModulesPath = toString ./extra;

# Alias for backward compatibility.
extraModulesDir = extraModulesPath;

# 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;
imports = importTree extraModulesPath;
};
}).config.modules-docs;

Expand Down
4 changes: 3 additions & 1 deletion docs/src/extending.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ lang = "en_US.UTF-8"
From a nix flake you would import it like

```nix
imports = ["${devshell}/extra/locale.nix"];
devshell.mkShell ({ extraModulesPath, ... }: {
imports = ["${extraModulesPath}/locale.nix"];
})
```

## Building your own modules
Expand Down
2 changes: 1 addition & 1 deletion flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ in
'';

type = types.lazyAttrsOf (
types.submoduleWith { modules = import ./modules/modules.nix { inherit pkgs lib; }; }
types.submoduleWith (import ./modules/eval-args.nix { inherit pkgs lib; })
);
default = { };
};
Expand Down
19 changes: 7 additions & 12 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ nixpkgs:
extraSpecialArgs ? { },
}:
let
devenvModules = import ./modules.nix {
pkgs = nixpkgs;
inherit lib;
};

module = lib.evalModules {
modules = [ configuration ] ++ devenvModules;
specialArgs = {
modulesPath = builtins.toString ./.;
extraModulesPath = builtins.toString ../extra;
} // extraSpecialArgs;
};
module = lib.evalModules (
import ./eval-args.nix {
inherit lib extraSpecialArgs;
pkgs = nixpkgs;
modules = [ configuration ];
}
);
in
{
inherit (module) config options;
Expand Down
17 changes: 17 additions & 0 deletions modules/eval-args.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Arguments for `lib.evalModules` or `types.submoduleWith`.
{
pkgs,
lib,
modules ? [ ],
extraSpecialArgs ? { },
}:
let
devenvModules = import ./modules.nix { inherit lib pkgs; };
in
{
modules = (lib.toList modules) ++ devenvModules;
specialArgs = {
modulesPath = builtins.toString ./.;
extraModulesPath = builtins.toString ../extra;
} // extraSpecialArgs;
}
6 changes: 3 additions & 3 deletions nix/importTOML.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ let
dir = toString (builtins.dirOf file);
data = builtins.fromTOML (builtins.readFile file);

extraModulesDir = toString ../extra;
extraModules = builtins.readDir extraModulesDir;
extraModulesPath = toString ../extra;
extraModules = builtins.readDir extraModulesPath;

importModule =
str:
let
repoFile = "${dir}/${str}";
extraFile = "${extraModulesDir}/${builtins.replaceStrings [ "." ] [ "/" ] str}.nix";
extraFile = "${extraModulesPath}/${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
Expand Down
20 changes: 19 additions & 1 deletion templates/flake-parts/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,25 @@
perSystem =
{ pkgs, ... }:
{
devshells.default = { };
devshells.default = (
{ extraModulesPath, ... }@args:
{
# `extraModulesPath` provides access to additional modules that are
# not included in the standard devshell modules list.
#
# Please see https://numtide.github.io/devshell/extending.html for
# documentation on consuming extra modules, and see
# https://github.com/numtide/devshell/tree/main/extra for the
# extra modules that are currently available.
imports = [ "${extraModulesPath}/git/hooks.nix" ];

git.hooks.enable = false;
git.hooks.pre-commit.text = ''
echo 1>&2 'time to implement a pre-commit hook!'
exit 1
'';
}
);
};
};
}
Loading