Skip to content

Commit

Permalink
chore(flake): remove dependency on flake-utils
Browse files Browse the repository at this point in the history
Keep the dependency tree small.
  • Loading branch information
zimbatm committed Jul 27, 2024
1 parent cc87001 commit 2e64dd8
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 155 deletions.
107 changes: 54 additions & 53 deletions extra/language/hare.nix
Original file line number Diff line number Diff line change
@@ -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 ];
};
}
34 changes: 0 additions & 34 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

142 changes: 74 additions & 68 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.default.${system};
});

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;
};
}

0 comments on commit 2e64dd8

Please sign in to comment.