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
1 change: 0 additions & 1 deletion docs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
stdenv,
lib,
}:
with lib;
stdenv.mkDerivation {
name = "devshell-docs";
buildInputs = [ mdbook ];
Expand Down
19 changes: 9 additions & 10 deletions extra/git/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@
pkgs,
...
}:
with lib;
let
cfg = config.git.hooks;

# These are all the options available for a git hook.
hookOptions = desc: {
text = mkOption {
text = lib.mkOption {
description = "Text of the script to install";
default = "";
type = types.str;
type = lib.types.str;
};
};

# All of the hook types supported by this module.
allHooks = filterAttrs (k: v: k != "enable") cfg;
allHooks = lib.filterAttrs (k: v: k != "enable") cfg;

# Only keep all the hooks that have a value set.
hooksWithData = filterAttrs (k: v: v.text != "") allHooks;
hooksWithData = lib.filterAttrs (k: v: v.text != "") allHooks;

# Shims for all the hooks that this module supports. The shims cause git
# hooks to be ignored:
Expand Down Expand Up @@ -70,7 +69,7 @@ let
in
pkgs.buildEnv {
name = "git.hooks";
paths = mapAttrsToList mkHookScript hooksWithData;
paths = lib.mapAttrsToList mkHookScript hooksWithData;
};

# Execute this script to update the project's git hooks
Expand Down Expand Up @@ -116,7 +115,7 @@ let
mkdir -pv "$target_hook_dir"

# Iterate over all the hooks enabled for this environment
for name in ${toString (attrNames hooksWithData)}; do
for name in ${toString (lib.attrNames hooksWithData)}; do
# Resolve all the symlinks
src_hook=$(readlink -f "$source_hook_dir/$name" || true)
dst_hook=$(readlink -f "$target_hook_dir/$name" || true)
Expand All @@ -137,7 +136,7 @@ let
in
{
options.git.hooks = {
enable = mkEnableOption "install .git/hooks on shell entry";
enable = lib.mkEnableOption "install .git/hooks on shell entry";

# TODO: add proper description for each hook.
applypatch-msg = hookOptions "";
Expand All @@ -157,15 +156,15 @@ in
# update = hookOptions "";
};

config.devshell = optionalAttrs cfg.enable {
config.devshell = lib.optionalAttrs cfg.enable {
packages = [ install-git-hooks ];

startup.install-git-hooks.text = "
$DEVSHELL_DIR/bin/install-git-hooks
";
};

config.env = optional cfg.enable {
config.env = lib.optional cfg.enable {
name = "DEVSHELL_GIT_HOOKS_DIR";
value = hooksDir;
};
Expand Down
3 changes: 1 addition & 2 deletions extra/language/c.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ let
hasLibraries = lib.length cfg.libraries > 0;
hasIncludes = lib.length cfg.includes > 0;
in
with lib;
{
options.language.c = {
options.language.c = with lib; {
libraries = mkOption {
type = types.listOf strOrPackage;
default = [ ];
Expand Down
3 changes: 1 addition & 2 deletions extra/language/go.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ let
cfg = config.language.go;
strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; };
in
with lib;
{
options.language.go = {
options.language.go = with lib; {
GO111MODULE = mkOption {
type = types.enum [
"on"
Expand Down
9 changes: 4 additions & 5 deletions extra/language/hare.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ let
in
lib.makeSearchPath "src/hare/third-party" (userHareLibs ++ propagatedLibs);
in
with lib;
{
options.language.hare = {
options.language.hare = with lib; {
thirdPartyLibs = mkOption {
type = types.listOf strOrPackage;
default = [ ];
Expand All @@ -48,13 +47,13 @@ with lib;
name = "HAREPATH";
value = lib.makeSearchPath "src/hare/stdlib" [ cfg.package ];
}
(mkIf (cfg.thirdPartyLibs != [ ]) {
(lib.mkIf (cfg.thirdPartyLibs != [ ]) {
name = "HAREPATH";
prefix = makeHareFullPath cfg.thirdPartyLibs;
})
(mkIf (cfg.vendoredLibs != [ ]) {
(lib.mkIf (cfg.vendoredLibs != [ ]) {
name = "HAREPATH";
prefix = concatStringsSep ":" cfg.vendoredLibs;
prefix = lib.concatStringsSep ":" cfg.vendoredLibs;
})
];
devshell.packages = [ cfg.package ];
Expand Down
10 changes: 4 additions & 6 deletions extra/language/perl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
let
cfg = config.language.perl;
strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; };

in
with lib;
{
options.language.perl = {
options.language.perl = with lib; {
extraPackages = mkOption {
type = types.listOf strOrPackage;
default = [ ];
Expand All @@ -35,13 +33,13 @@ with lib;

config = {
env = [
(mkIf (cfg.extraPackages != [ ]) {
(lib.mkIf (cfg.extraPackages != [ ]) {
name = "PERL5LIB";
prefix = pkgs.perlPackages.makeFullPerlPath cfg.extraPackages;
})
(mkIf (cfg.libraryPaths != [ ]) {
(lib.mkIf (cfg.libraryPaths != [ ]) {
name = "PERL5LIB";
prefix = concatStringsSep ":" cfg.libraryPaths;
prefix = lib.concatStringsSep ":" cfg.libraryPaths;
})
];
devshell.packages = [ cfg.package ] ++ cfg.extraPackages;
Expand Down
3 changes: 1 addition & 2 deletions extra/language/ruby.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ let
cfg = config.language.ruby;
strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; };
in
with lib;
{
imports = [ ./c.nix ];
options.language.ruby = {
options.language.ruby = with lib; {
nativeDeps = mkOption {
type = types.listOf strOrPackage;
default = [ ];
Expand Down
3 changes: 1 addition & 2 deletions extra/language/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
let
cfg = config.language.rust;
in
with lib;
{
options.language.rust = {
options.language.rust = with lib; {
packageSet = mkOption {
# FIXME: how to make the selection possible in TOML?
type = types.attrs;
Expand Down
3 changes: 1 addition & 2 deletions extra/locale.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
config,
...
}:
with lib;
let
cfg = config.extra.locale;
in
{
options.extra.locale = {
options.extra.locale = with lib; {
lang = mkOption {
type = types.nullOr types.str;
default = null;
Expand Down
11 changes: 8 additions & 3 deletions extra/services/postgres.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
config,
...
}:
with lib;
let
inherit (lib)
mkOption
types
mkEnableOption
;

# Because we want to be able to push pure JSON-like data into the
# environment.
strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; };

cfg = config.services.postgres;
createDB = optionalString cfg.createUserDB ''
createDB = lib.optionalString cfg.createUserDB ''
echo "CREATE DATABASE ''${USER:-$(id -nu)};" | postgres --single -E postgres
'';

Expand All @@ -27,7 +32,7 @@ let
# Abort if the data dir already exists
[[ ! -d "$PGDATA" ]] || exit 0

initdb ${concatStringsSep " " cfg.initdbArgs}
initdb ${lib.concatStringsSep " " cfg.initdbArgs}

cat >> "$PGDATA/postgresql.conf" <<EOF
listen_addresses = '''
Expand Down
7 changes: 6 additions & 1 deletion modules/back-compat.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ let
# Because we want to be able to push pure JSON-like data into the
# environment.
strOrPackage = import ../nix/strOrPackage.nix { inherit lib pkgs; };

inherit (lib)
types
mkOption
noDepEntry
;
in
with lib;
{
options = {
bash.extra = mkOption {
Expand Down
9 changes: 7 additions & 2 deletions modules/commands.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
pkgs,
...
}:
with lib;
let
ansi = import ../nix/ansi.nix;

Expand Down Expand Up @@ -65,7 +64,7 @@ let
maxCommandLength = builtins.foldl' (max: v: if v > max then v else max) 0 commandLengths;

commandCategories = lib.unique (
(zipAttrsWithNames [ "category" ] (name: vs: vs) commands).category
(lib.zipAttrsWithNames [ "category" ] (name: vs: vs) commands).category
);

commandByCategoriesSorted = builtins.attrValues (
Expand Down Expand Up @@ -93,6 +92,12 @@ let
in
builtins.concatStringsSep "\n" (map opCat commandByCategoriesSorted) + "\n";

inherit (lib)
types
mkOption
literalExpression
;

# These are all the options available for the commands.
commandOptions = {
name = mkOption {
Expand Down
28 changes: 19 additions & 9 deletions modules/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
options,
...
}:
with lib;
let
cfg = config.devshell;
sanitizedName = strings.sanitizeDerivationName cfg.name;
sanitizedName = lib.strings.sanitizeDerivationName cfg.name;

ansi = import ../nix/ansi.nix;

Expand Down Expand Up @@ -41,7 +40,7 @@ let

addAttributeName =
prefix:
mapAttrs (
lib.mapAttrs (
k: v:
v
// {
Expand All @@ -52,6 +51,17 @@ let
}
);

inherit (lib)
mkOption
mkEnableOption
attrNames
attrValues
textClosureMap
replaceStrings
types
id
;

entryOptions = {
text = mkOption {
type = types.str;
Expand Down Expand Up @@ -228,7 +238,7 @@ let
# Returns a list of all the input derivation ... for a derivation.
inputsOf =
drv:
filter lib.isDerivation (
lib.filter lib.isDerivation (
(drv.buildInputs or [ ])
++ (drv.nativeBuildInputs or [ ])
++ (drv.propagatedBuildInputs or [ ])
Expand Down Expand Up @@ -381,11 +391,11 @@ in
config.devshell = {
package = devshell_dir;

packages = foldl' (sum: drv: sum ++ (inputsOf drv)) [ ] cfg.packagesFrom;
packages = lib.foldl' (sum: drv: sum ++ (inputsOf drv)) [ ] cfg.packagesFrom;

startup =
{
motd = noDepEntry ''
motd = lib.noDepEntry ''
__devshell-motd() {
cat <<DEVSHELL_PROMPT
${cfg.motd}
Expand All @@ -411,7 +421,7 @@ in
fi
'';
}
// (optionalAttrs cfg.load_profiles {
// (lib.optionalAttrs cfg.load_profiles {
load_profiles = lib.noDepEntry ''
# Load installed profiles
for file in "$DEVSHELL_DIR/etc/profile.d/"*.sh; do
Expand All @@ -422,7 +432,7 @@ in
});

interactive = {
PS1_util = noDepEntry ''
PS1_util = lib.noDepEntry ''
if [[ -n "''${PRJ_ROOT:-}" ]]; then
# Print the path relative to $PRJ_ROOT
rel_root() {
Expand All @@ -441,7 +451,7 @@ in
'';

# Set a cool PS1
PS1 = stringAfter [ "PS1_util" ] (
PS1 = lib.stringAfter [ "PS1_util" ] (
lib.mkDefault ''
__set_prompt() {
PS1='\[\033[38;5;202m\][${cfg.name}]$(rel_root)\$\[\033[0m\] '
Expand Down
Loading
Loading