Skip to content

Commit

Permalink
mkDerivation/builtins-derivation: refactor: implementation.nix -> def…
Browse files Browse the repository at this point in the history
…ault.nix
  • Loading branch information
DavHau committed Mar 17, 2024
1 parent 6bbac51 commit f15cc37
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 118 deletions.
46 changes: 45 additions & 1 deletion modules/dream2nix/builtins-derivation/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
{
config,
lib,
...
}: let
l = lib // builtins;
t = l.types;

cfg = config.builtins-derivation;

outputs = l.unique cfg.outputs;

keepArg = key: val: val != null;

finalArgs = l.filterAttrs keepArg cfg;

# ensure that none of the env variables collide with the top-level options
envChecked =
l.mapAttrs
(key: val:
if config.builtins-derivation.${key} or false
then throw (envCollisionError key)
else val)
config.env;

# generates error message for env variable collision
envCollisionError = key: ''
Error while evaluating definitions for derivation ${config.name}
The environment variable defined via `env.${key}' collides with the option builtins-derivation.`${key}'.
Specify the top-level option instead, or rename the environment variable.
'';
in {
imports = [
./implementation.nix
./interface.nix
../core
../package-func
];

config.package-func.outputs = cfg.outputs;

config.package-func.func = lib.mkDefault builtins.derivation;

config.package-func.args =
envChecked
// finalArgs
// {
inherit outputs;
inherit (config.public) name;
};
}
49 changes: 0 additions & 49 deletions modules/dream2nix/builtins-derivation/implementation.nix

This file was deleted.

64 changes: 63 additions & 1 deletion modules/dream2nix/mkDerivation/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,68 @@
{
config,
lib,
...
}: let
l = lib // builtins;
t = l.types;

cfg = config.mkDerivation;

outputs = l.unique cfg.outputs;

keepArg = key: val: val != null;

finalArgs = l.filterAttrs keepArg cfg;

# ensure that none of the env variables collide with the top-level options
envChecked =
l.mapAttrs
(key: val:
if config.mkDerivation ? ${key}
then throw (envCollisionError key)
else val)
config.env;

# generates error message for env variable collision
envCollisionError = key: ''
Error while evaluating definitions for derivation ${config.name}
The environment variable defined via `env.${key}' collides with the option mkDerivation.`${key}'.
Specify the top-level option instead, or rename the environment variable.
'';

public =
# meta
(l.optionalAttrs (cfg.passthru ? meta) {
inherit (cfg.passthru) meta;
})
# tests
// (l.optionalAttrs (cfg.passthru ? tests) {
inherit (cfg.passthru) tests;
});
in {
imports = [
./implementation.nix
./interface.nix
../core
../package-func
];

config.package-func.outputs = cfg.outputs;

config.package-func.func = lib.mkDefault config.deps.stdenv.mkDerivation;

# add mkDerivation specific derivation attributes
config.public = public;

config.package-func.args =
envChecked
// finalArgs
// {
inherit outputs;
inherit (config.public) version;
pname = config.name;
};

config.deps = {nixpkgs, ...}: {
stdenv = lib.mkOverride 1050 nixpkgs.stdenv;
};
}
67 changes: 0 additions & 67 deletions modules/dream2nix/mkDerivation/implementation.nix

This file was deleted.

0 comments on commit f15cc37

Please sign in to comment.