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

modules: pre-commit: make pkgs.buildEnv composable #498

Conversation

trueNAHO
Copy link
Contributor

@trueNAHO trueNAHO commented Oct 1, 2024

commit 9f73309ff19bda94d6bcbe77dcd72c1c65a9f37d
[...]

    modules: pre-commit: make pkgs.buildEnv composable

    Passing a git-hooks.lib.<SYSTEM>.run derivation as a path to
    pkgs.buildEnv results in the following error due to derivations with an
    empty file being treated differently from derivations with an empty
    directory:

        The store path <TARGET> is a file and can't be merged into an
        environment using pkgs.buildEnv!

    Since Nixpkgs rejected explicitly handling derivations with an empty
    file in pkgs.buildEnv [1], affected derivations should transition from
    'touch $out' to 'mkdir $out' to be pkgs.buildEnv composable.

    This change replaces 'touch $out' with 'mkdir $out' and makes the
    following command work:

        nix \
          build \
          --expr '
            let
              flake = builtins.getFlake (toString ./.);
              system = builtins.currentSystem;
            in
              flake.inputs.nixpkgs.legacyPackages.${system}.buildEnv {
                name = "";
                paths = [(flake.outputs.lib.${system}.run {src = ./.;})];
              }
          ' \
          --impure

    [1]: https://github.com/NixOS/nixpkgs/pull/325140

    Link: https://github.com/cachix/git-hooks.nix/pull/498

For example, this PR allows me to include the git-hooks check in pkgs.buildEnv: https://github.com/trueNAHO/dotfiles/blob/4fdeb9e4e6bf6cb2255b89f5d75aab167d3bdde7/flake.nix#L707-L751

Passing a git-hooks.lib.<SYSTEM>.run derivation as a path to
pkgs.buildEnv results in the following error due to derivations with an
empty file being treated differently from derivations with an empty
directory:

    The store path <TARGET> is a file and can't be merged into an
    environment using pkgs.buildEnv!

Since Nixpkgs rejected explicitly handling derivations with an empty
file in pkgs.buildEnv [1], affected derivations should transition from
'touch $out' to 'mkdir $out' to be pkgs.buildEnv composable.

This change replaces 'touch $out' with 'mkdir $out' and makes the
following command work:

    nix \
      build \
      --expr '
        let
          flake = builtins.getFlake (toString ./.);
          system = builtins.currentSystem;
        in
          flake.inputs.nixpkgs.legacyPackages.${system}.buildEnv {
            name = "";
            paths = [(flake.outputs.lib.${system}.run {src = ./.;})];
          }
      ' \
      --impure

[1]: NixOS/nixpkgs#325140

Link: cachix#498
@trueNAHO trueNAHO force-pushed the modules-pre-commit-run-make-pkgs-buildenv-composable branch from cfb75e0 to 9f73309 Compare October 1, 2024 17:04
@domenkozar domenkozar merged commit 2f5ae3f into cachix:master Oct 1, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants