Skip to content

Commit

Permalink
chore: format with nixfmt-rfc-style
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbatm committed Jul 27, 2024
1 parent 78e2d09 commit 29ae436
Show file tree
Hide file tree
Showing 50 changed files with 853 additions and 609 deletions.
4 changes: 3 additions & 1 deletion benchmark/devshell-nix.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ system ? builtins.currentSystem }:
{
system ? builtins.currentSystem,
}:
let
devshell = import ../. { inherit system; };
in
Expand Down
4 changes: 3 additions & 1 deletion benchmark/devshell-toml.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ system ? builtins.currentSystem }:
{
system ? builtins.currentSystem,
}:
let
devshell = import ../. { inherit system; };
in
Expand Down
4 changes: 3 additions & 1 deletion benchmark/nixpkgs-mkshell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ system ? builtins.currentSystem }:
{
system ? builtins.currentSystem,
}:
let
pkgs = import (import ../nix/nixpkgs.nix) { inherit system; };
in
Expand Down
43 changes: 25 additions & 18 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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 <nixpkgs>/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
Expand All @@ -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; };
Expand Down Expand Up @@ -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;
}
13 changes: 8 additions & 5 deletions docs/default.nix
Original file line number Diff line number Diff line change
@@ -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 [
Expand Down
56 changes: 30 additions & 26 deletions extra/git/hooks.nix
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)}
'';

Expand Down
15 changes: 9 additions & 6 deletions extra/language/c.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ lib, config, pkgs, ... }:
{
lib,
config,
pkgs,
...
}:
let
cfg = config.language.c;
strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; };
Expand Down Expand Up @@ -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 [
Expand Down
23 changes: 17 additions & 6 deletions extra/language/go.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ lib, config, pkgs, ... }:
{
lib,
config,
pkgs,
...
}:
let
cfg = config.language.go;
strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; };
Expand All @@ -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";
};
Expand All @@ -21,10 +30,12 @@ with lib;
};

config = {
env = [{
name = "GO111MODULE";
value = cfg.GO111MODULE;
}];
env = [
{
name = "GO111MODULE";
value = cfg.GO111MODULE;
}
];

devshell.packages = [ cfg.package ];
};
Expand Down
19 changes: 10 additions & 9 deletions extra/language/hare.nix
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 6 additions & 1 deletion extra/language/perl.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ config, lib, pkgs, ... }:
{
config,
lib,
pkgs,
...
}:

let
cfg = config.language.perl;
Expand Down
33 changes: 26 additions & 7 deletions extra/language/ruby.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ lib, config, pkgs, ... }:
{
lib,
config,
pkgs,
...
}:
let
cfg = config.language.ruby;
strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; };
Expand Down Expand Up @@ -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";
}
];
};
}

Loading

0 comments on commit 29ae436

Please sign in to comment.