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

Git sources in flakes #368

Open
Lykos153 opened this issue Dec 16, 2021 · 3 comments
Open

Git sources in flakes #368

Lykos153 opened this issue Dec 16, 2021 · 3 comments

Comments

@Lykos153
Copy link

I've been trying to get this to work for days, but I'm kind of stuck. I'm fairly new to Nix, so the solution might be obvious.

So I'm starting with the following flake that I use in conjunction with direnv to set up a k8s workspace:

Working flake using mach-nix
# Inspired by https://www.reddit.com/r/Python/comments/npu66t/reproducible_python_environment_with_nix_flake/
{
  description = "Flake to manage k8s workspace";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/master";
    flake-utils.url = "github:numtide/flake-utils";
    mach-nix.url = "github:DavHau/mach-nix?ref=3.3.0";
  };

  outputs = { self, nixpkgs, flake-utils, mach-nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        python = "python39";
        pkgs = nixpkgs.legacyPackages.${system};
        # https://github.com/DavHau/mach-nix/issues/153#issuecomment-717690154
        mach-nix-wrapper = import mach-nix { inherit pkgs python; };
        pythonBuild = mach-nix-wrapper.mkPython {
          requirements = ''
            ansible
          '';
        };
      in {
        devShell = pkgs.mkShell {
          buildInputs = [
            pkgs.kubectl
            pkgs.pass
            pkgs.k9s
            pkgs.terraform
            pkgs.envsubst
            pkgs.pwgen

            pythonBuild
          ];
        };
      });
} 

However, I need a feature from ansible's master branch which hasn't been released yet. I know I can't just list the github url in the requirements due to #36.
But when, instead, I try to add it to packagesExtra using buildPythonPackage like this...

[...]
        pythonBuild = mach-nix-wrapper.mkPython {
          packagesExtra = [
            mach-nix-wrapper.buildPythonPackage {
              src = builtins.fetchGit{
                url = "https://github.com/ansible/ansible";
                ref = "master";
                rev = "cd2d8b77fe699f7cc8529dfa296b0d2894630599";
              };
            }
          ];
        };
[...]
Full flake with packagesExtra
{
  description = "Flake to manage k8s workspace";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/master";
    flake-utils.url = "github:numtide/flake-utils";
    mach-nix.url = "github:DavHau/mach-nix?ref=3.3.0";
  };

  outputs = { self, nixpkgs, flake-utils, mach-nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        python = "python39"; # <--- change here
        pkgs = nixpkgs.legacyPackages.${system};
        # https://github.com/DavHau/mach-nix/issues/153#issuecomment-717690154
        mach-nix-wrapper = import mach-nix { inherit pkgs python; };
        pythonBuild = mach-nix-wrapper.mkPython {
          packagesExtra = [
            mach-nix-wrapper.buildPythonPackage {
              src = builtins.fetchGit{
                url = "https://github.com/ansible/ansible";
                ref = "master";
                rev = "cd2d8b77fe699f7cc8529dfa296b0d2894630599";
              };
            }
          ];
        };
      in {
        devShell = pkgs.mkShell {
          buildInputs = [
            pkgs.kubectl
            pkgs.pass
            pkgs.k9s
            pkgs.terraform
            pkgs.envsubst
            pkgs.pwgen

            pythonBuild
          ];
        };
      });
} 

...I get the following error:

error: cannot coerce a function to a string

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/lib/extractor/default.nix:157:14:

          156|     stdenv.mkDerivation ( (base_derivation []) // {
          157|       inherit src;
             |              ^
          158|       name = "package-requirements";
(use '--show-trace' to show detailed location information)
Output of invocation with --show-trace
$ nix develop . --show-trace
error: cannot coerce a function to a string

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/lib/extractor/default.nix:157:14:

          156|     stdenv.mkDerivation ( (base_derivation []) // {
          157|       inherit src;
             |              ^
          158|       name = "package-requirements";while evaluating the attribute 'src' of the derivation 'package-requirements'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/stdenv/generic/make-derivation.nix:205:7:

          204|     // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
          205|       name =
             |       ^
          206|         letwhile evaluating 'extract'

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/lib.nix:41:28:

           40|
           41|     extract = python: src: fail_msg:
             |                            ^
           42|     let

       … from call site

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/lib.nix:72:14:

           71|         Please manually specify '${for_attr}' '';
           72|       data = extract python src error_msg;
             |              ^
           73|       result = if hasAttr attr data then data."${attr}" else throw error_msg;while evaluating 'extract_meta'

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/lib.nix:67:37:

           66|
           67|   extract_meta = python: src: attr: for_attr:
             |                                     ^
           68|     let

       … from call site

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/buildPythonPackage.nix:36:14:

           35|         if hasAttr "pname" args then args.pname
           36|         else l.extract_meta python_pkg src "name" "pname";
             |              ^
           37|       version =

       … while evaluating 'extract_requirements'

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/lib.nix:50:45:

           49|
           50|   extract_requirements = python: src: name: extras:
             |                                             ^
           51|     let

       … from call site

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/buildPythonPackage.nix:40:19:

           39|         else l.extract_meta python_pkg src "version" "version";
           40|       meta_reqs = l.extract_requirements python_pkg src "${pname}:${version}" extras;
             |                   ^
           41|       reqs =

       … while evaluating the attribute 'requirements' of the derivation 'mach_nix_file'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/stdenv/generic/make-derivation.nix:205:7:

          204|     // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
          205|       name =
             |       ^
          206|         letwhile evaluating the attribute 'overrides'

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/lib.nix:30:7:

           29|     in {
           30|       overrides = result.overrides manylinux autoPatchelfHook;
             |       ^
           31|       select_pkgs = result.select_pkgs;while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;

       … while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;

       … while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;

       … while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;

       … while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;

       … while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;

       … while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:76:22:

           75|     f: g: final: prev:
           76|       let fApplied = f final prev;
             |                      ^
           77|           prev' = prev // fApplied;

       … while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:78:22:

           77|           prev' = prev // fApplied;
           78|       in fApplied // g final prev';
             |                      ^
           79|

       … while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:69:67:

           68|   #
           69|   extends = f: rattrs: self: let super = rattrs self; in super // f self super;
             |                                                                   ^
           70|

       … while evaluating 'extends'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:69:24:

           68|   #
           69|   extends = f: rattrs: self: let super = rattrs self; in super // f self super;
             |                        ^
           70|

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:233:14:

          232|       spliced = extra spliced0 // spliced0 // keep self;
          233|       self = f self // {
             |              ^
          234|         newScope = scope: newScope (spliced // scope);

       … while evaluating 'makeScopeWithSplicing'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:222:80:

          221|      hopefully it helps a little bit. */
          222|   makeScopeWithSplicing = splicePackages: newScope: otherSplices: keep: extra: f:
             |                                                                                ^
          223|     let

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/development/interpreters/python/default.nix:79:12:

           78|           aliases = self: super: lib.optionalAttrs (config.allowAliases or true) (import ../../../top-level/python-aliases.nix lib self super);
           79|         in lib.makeScopeWithSplicing
             |            ^
           80|           pkgs.splicePackages

       … while evaluating anonymous lambda

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/development/interpreters/python/default.nix:25:10:

           24|       pythonPackages = callPackage
           25|         ({ pkgs, stdenv, python, overrides }: let
             |          ^
           26|           pythonPackagesFun = import ../../../top-level/python-packages.nix {

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:69:16:

           68|     let
           69|       result = f origArgs;
             |                ^
           70|

       … while evaluating 'makeOverridable'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:67:24:

           66|   */
           67|   makeOverridable = f: origArgs:
             |                        ^
           68|     let

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:121:8:

          120|       auto = builtins.intersectAttrs (lib.functionArgs f) autoArgs;
          121|     in makeOverridable f (auto // args);
             |        ^
          122|

       … while evaluating 'callPackageWith'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:117:35:

          116|   */
          117|   callPackageWith = autoArgs: fn: args:
             |                                   ^
          118|     let

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/development/interpreters/python/default.nix:24:24:

           23|     }: let
           24|       pythonPackages = callPackage
             |                        ^
           25|         ({ pkgs, stdenv, python, overrides }: let

       … while evaluating the attribute 'pkgs.buildPythonPackage'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/development/interpreters/python/default.nix:105:9:

          104|         withPackages = import ./with-packages.nix { inherit buildEnv pythonPackages;};
          105|         pkgs = pythonPackages;
             |         ^
          106|         interpreter = "${self}/bin/${executable}";

       … while evaluating 'buildPythonPackageBase'

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/buildPythonPackage.nix:8:5:

            7|   buildPythonPackageBase = pythonGlobal: func:
            8|     args@{
             |     ^
            9|       ignoreDataOutdated ? false,  # don't fail if pypi data is older than nixpkgs

       … from call site

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/buildPythonPackage.nix:79:21:

           78|
           79| python: func: args: buildPythonPackageBase python func (l.translateDeprecatedArgs args)
             |                     ^

       … while evaluating anonymous lambda

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/buildPythonPackage.nix:79:15:

           78|
           79| python: func: args: buildPythonPackageBase python func (l.translateDeprecatedArgs args)
             |               ^

       … from call site

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/mkPython.nix:53:11:

           52|         else
           53|           buildPythonPackageBase python_arg "buildPythonPackage" {
             |           ^
           54|             inherit pkgs providers pypiData tests _providerDefaults;while evaluating anonymous lambda

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/mkPython.nix:32:32:

           31|       # and separate pkgs into groups
           32|       extra_pkgs_python = map (p:
             |                                ^
           33|         # check if element is a package built via mach-nix

       … from call site

       … while evaluating anonymous lambda

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/mkPython.nix:91:43:

           90|       );
           91|       overrides_pre_extra = flatten (map (p: p.passthru.overridesPre) extra_pkgs_python);
             |                                           ^
           92|       overrides_post_extra = flatten (map (p: p.passthru.overridesPost) extra_pkgs_python);

       … from call site

       … while evaluating 'flatten'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/lists.nix:137:13:

          136|   */
          137|   flatten = x:
             |             ^
          138|     if isList x

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/lists.nix:139:24:

          138|     if isList x
          139|     then concatMap (y: flatten y) x
             |                        ^
          140|     else [x];while evaluating anonymous lambda

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/lists.nix:139:21:

          138|     if isList x
          139|     then concatMap (y: flatten y) x
             |                     ^
          140|     else [x];

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/lists.nix:139:10:

          138|     if isList x
          139|     then concatMap (y: flatten y) x
             |          ^
          140|     else [x];while evaluating 'flatten'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/lists.nix:137:13:

          136|   */
          137|   flatten = x:
             |             ^
          138|     if isList x

       … from call site

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/mkPython.nix:91:29:

           90|       );
           91|       overrides_pre_extra = flatten (map (p: p.passthru.overridesPre) extra_pkgs_python);
             |                             ^
           92|       overrides_post_extra = flatten (map (p: p.passthru.overridesPost) extra_pkgs_python);while evaluating 'foldl''

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/lists.nix:82:16:

           81|     let
           82|       foldl' = n:
             |                ^
           83|         if n == -1

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/lists.nix:86:8:

           85|         else op (foldl' (n - 1)) (elemAt list n);
           86|     in foldl' (length list - 1);
             |        ^
           87|while evaluating 'foldl'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/lists.nix:80:20:

           79|   */
           80|   foldl = op: nul: list:
             |                    ^
           81|     let

       … from call site

       at /nix/store/dljl5bzw3cvzg0c5vfrmn8z9cnz5rnla-source/mach_nix/nix/mkPython.nix:109:23:

          108|
          109|       all_overrides = l.mergeOverrides (
             |                       ^
          110|         overridesPre ++ overrides_pre_extra

       … while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:78:22:

           77|           prev' = prev // fApplied;
           78|       in fApplied // g final prev';
             |                      ^
           79|while evaluating 'composeExtensions'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:75:18:

           74|   composeExtensions =
           75|     f: g: final: prev:
             |                  ^
           76|       let fApplied = f final prev;

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:69:67:

           68|   #
           69|   extends = f: rattrs: self: let super = rattrs self; in super // f self super;
             |                                                                   ^
           70|while evaluating 'extends'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/fixed-points.nix:69:24:

           68|   #
           69|   extends = f: rattrs: self: let super = rattrs self; in super // f self super;
             |                        ^
           70|

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:233:14:

          232|       spliced = extra spliced0 // spliced0 // keep self;
          233|       self = f self // {
             |              ^
          234|         newScope = scope: newScope (spliced // scope);while evaluating 'makeScopeWithSplicing'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:222:80:

          221|      hopefully it helps a little bit. */
          222|   makeScopeWithSplicing = splicePackages: newScope: otherSplices: keep: extra: f:
             |                                                                                ^
          223|     let

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/development/interpreters/python/default.nix:79:12:

           78|           aliases = self: super: lib.optionalAttrs (config.allowAliases or true) (import ../../../top-level/python-aliases.nix lib self super);
           79|         in lib.makeScopeWithSplicing
             |            ^
           80|           pkgs.splicePackages

       … while evaluating anonymous lambda

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/development/interpreters/python/default.nix:25:10:

           24|       pythonPackages = callPackage
           25|         ({ pkgs, stdenv, python, overrides }: let
             |          ^
           26|           pythonPackagesFun = import ../../../top-level/python-packages.nix {

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:69:16:

           68|     let
           69|       result = f origArgs;
             |                ^
           70|while evaluating 'makeOverridable'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:67:24:

           66|   */
           67|   makeOverridable = f: origArgs:
             |                        ^
           68|     let

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:121:8:

          120|       auto = builtins.intersectAttrs (lib.functionArgs f) autoArgs;
          121|     in makeOverridable f (auto // args);
             |        ^
          122|while evaluating 'callPackageWith'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/lib/customisation.nix:117:35:

          116|   */
          117|   callPackageWith = autoArgs: fn: args:
             |                                   ^
          118|     let

       … from call site

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/development/interpreters/python/default.nix:24:24:

           23|     }: let
           24|       pythonPackages = callPackage
             |                        ^
           25|         ({ pkgs, stdenv, python, overrides }: letwhile evaluating the attribute 'passAsFile'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/build-support/buildenv/default.nix:77:5:

           76|     # XXX: The size is somewhat arbitrary
           77|     passAsFile = if builtins.stringLength pkgs >= 128*1024 then [ "pkgs" ] else [ ];
             |     ^
           78|   }

       … while evaluating the attribute 'passAsFile' of the derivation 'python3-3.9.6-env'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/stdenv/generic/make-derivation.nix:205:7:

          204|     // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
          205|       name =
             |       ^
          206|         letwhile evaluating the attribute 'buildInputs' of the derivation 'nix-shell'

       at /nix/store/mdbgxa6h5zsdahgsm6kbapagjiwjbns2-source/pkgs/stdenv/generic/make-derivation.nix:205:7:

          204|     // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
          205|       name =
             |       ^
          206|         let

In #153 (comment), @nat543207 said that buildPythonPackage won't work with flakes because the extractor uses import <nixpkgs>, so I tried specifying requirements, pname and version, but that results in the same error.

Flake with packagesExtra and requirements, pname and version
{
  description = "Flake to manage k8s workspace";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/master";
    flake-utils.url = "github:numtide/flake-utils";
    mach-nix.url = "github:DavHau/mach-nix?ref=3.3.0";
  };

  outputs = { self, nixpkgs, flake-utils, mach-nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        python = "python39"; # <--- change here
        pkgs = nixpkgs.legacyPackages.${system};
        # https://github.com/DavHau/mach-nix/issues/153#issuecomment-717690154
        mach-nix-wrapper = import mach-nix { inherit pkgs python; };
        pythonBuild = mach-nix-wrapper.mkPython {
          packagesExtra = [
            mach-nix-wrapper.buildPythonPackage {
              src = builtins.fetchGit{
                url = "https://github.com/ansible/ansible";
                ref = "master";
                rev = "cd2d8b77fe699f7cc8529dfa296b0d2894630599";
              };
              requirements = ''
                jinja2 >= 3.0.0
                PyYAML
                cryptography
                packaging
                resolvelib >= 0.5.3, < 0.6.0
              '';
              pname = "ansible";
              version = "2.13.0.dev0";
            }
          ];
        };
      in {
        devShell = pkgs.mkShell {
          buildInputs = [
            pkgs.kubectl
            pkgs.pass
            pkgs.k9s
            pkgs.terraform
            pkgs.envsubst
            pkgs.pwgen

            pythonBuild
          ];
        };
      });
} 

Please tell me if I'm doing something stupidly wrong or if this use case is simply not yet supported by mach-nix. In case of the latter, what would need to be done to make it possible or are there any alternatives to achieve something similar?

@nat543207
Copy link
Contributor

nat543207 commented Dec 16, 2021

The problem here is that ansible doesn't have a master branch - if you search their branch listing, nothing shows up. The most similar name I can find is devel, so starting with your "Full flake with packagesExtra" code I built a flake that successfully launches a shell when I run nix develop:

Working flake using devel ref
{
  description = "Flake to manage k8s workspace";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/master";
    flake-utils.url = "github:numtide/flake-utils";
    mach-nix.url = "github:DavHau/mach-nix?ref=3.3.0";
  };

  outputs = { self, nixpkgs, flake-utils, mach-nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        python = "python39"; # <--- change here
        pkgs = nixpkgs.legacyPackages.${system};
        # https://github.com/DavHau/mach-nix/issues/153#issuecomment-717690154
        mach-nix-wrapper = import mach-nix { inherit pkgs python; };
        ansible-upstream = mach-nix-wrapper.buildPythonPackage {
          src = builtins.fetchGit{
            url = "https://github.com/ansible/ansible";
            ref = "devel";
            rev = "cd2d8b77fe699f7cc8529dfa296b0d2894630599";
          };
        };
        pythonBuild = mach-nix-wrapper.mkPython {
          packagesExtra = [
            ansible-upstream
          ];
        };
      in {
        devShell = pkgs.mkShell {
          buildInputs = [
            pkgs.kubectl
            pkgs.pass
            pkgs.k9s
            pkgs.terraform
            pkgs.envsubst
            pkgs.pwgen

            pythonBuild
          ];
        };
        packages = {
          inherit ansible-upstream;
        };
      });
}

The error message that nix gives is unfortunately misleading, but you can observe the root cause directly by running nix build .#ansible-upstream if you revert devel to master in the working flake. If you've already built the working version, you may have to run sudo nix store delete --ignore-liveness .#ansible-upstream first.

$ nix build .#ansible-upstream
fetching Git repository 'https://github.com/ansible/ansible'fatal: couldn't find remote ref refs/heads/master
error: program 'git' failed with exit code 128
(use '--show-trace' to show detailed location information)

DavHau was kind enough to merge the commit that resolved the buildPythonPackage issue you reference, so it's no longer necessary to use the requirements/pname/version workaround. That helper is fully flake-compatible.

@Lykos153
Copy link
Author

Lykos153 commented Dec 18, 2021

Well, I guess that kind of counts as 'doing something stupidly wrong'. :-D Thanks a lot for helping me out, it's highly appreciated! I got lost in trying to understand how the Nix expression works and surely assumed my mistake was somewhere in the expression and not in something as 'trivial' as a branch name. (Although, you did change the expression somewhat so probably the mistake was in the expression and the branch name ;) )

Also, thank you for your work on making buildPythonPackage flake-compatible. Being able to easily add Python packages from URL sources has been the last major building stone in making my workspaces reproducible.

On another note (if you forgive a short OT question): You write commands like $ nix build .#ansible-upstream and I've seen this in quite some other Nix-related places, too. Are there shells that don't interpret the # as the beginning of a comment in interactive sessions or is there a convention in the Nix-world that there are always implicit quotes when sharing commands like these?

@nat543207
Copy link
Contributor

The expression was nearly there already; most of my changes were to demonstrate the branch name issue more easily. Your original flake works perfectly fine with nix develop if you (a) change the branch name to devel, and (b) wrap the mach-nix-wrapper.buildPythonPackage { ... } call in parentheses, since otherwise you get a two-element array (one function and one attrset). Yesterday I was seeing the same error you reported using master whether or not the parentheses were present, which is why I labeled the error as "misleading" - but when the branch exists, it very helpfully indicates that buildPythonPackage is being parsed as part of packagesExtra as though it were a Python package.

And thanks for the kind words; mach-nix is a great tool, so I'm happy if my tweak could enable even one more person to use it for their own purposes.

As for your question, I personally run zsh and never see the # character interpreted as a comment marker in interactive mode, but I'm not certain if this is the default behavior:

$ echo #text
#text
$ # echo text
#: command not found

Commands in that form are meant to be run verbatim, such as the ones in the nix build manpage, and typically rely on the new CLI released as part of Nix 2.4 that in turn relies heavily on flakes.

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

No branches or pull requests

2 participants