Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(flake): remove dependency on flake-utils #324

Merged
merged 2 commits into from
Jul 27, 2024
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
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
100 changes: 51 additions & 49 deletions extra/language/hare.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,58 @@
lib,
pkgs,
...
}: let
}:
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
lib.makeSearchPath
"src/hare/third-party"
(thirdParty ++ propagatedLibs);
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);
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 ];
};
}
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
Loading
Loading