GithubHelp home page GithubHelp logo

Comments (9)

szlend avatar szlend commented on June 2, 2024 3

You can override pkgs like so:

{
  perSystem = { pkgs, system, ... }: {
    _module.args.pkgs = import nixpkgs { inherit system; overlays = [ myOverlay ]; };
  };
}

By default it's set to inputs'.nixpkgs.legacyPackages.

from flake-parts.

szlend avatar szlend commented on June 2, 2024 2

It feels a bit hacky yeah, but this is essentially how you define special args in the standard nixos module system. From what I gather, the long term plan is to remove nixpkgs entirely from the default flake-parts setup (#41) and replace it with an easily configurable nixpkgs module (#74) that you can import.

from flake-parts.

dhess avatar dhess commented on June 2, 2024

You can override pkgs like so:

Thanks, that was very timely, as we're going through a similar process to @antifuchs.

FYI, we do this sort of thing in nearly all of our flakes, so it would be nice if it were more ergonomic.

from flake-parts.

antifuchs avatar antifuchs commented on June 2, 2024

Thank you very much, @szlend, that is exactly what I was hoping for. Agreed that this would be an excellent thing to allow for a customization, but there are many nixpkgs options people might want to set - privileging overlays like that might make the other options annoying (I am thinking of #105 here, but other options exist too).

from flake-parts.

ParetoOptimalDev avatar ParetoOptimalDev commented on June 2, 2024

So the best way to use something like emacs-overlay in a flake-parts flake would be this (working) flake?

{
  description = "Description for the project";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    emacs-overlay.url = "github:nix-community/emacs-overlay";
  };

  outputs = inputs@{ flake-parts, nixpkgs, emacs-overlay, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      systems = [ "x86_64-linux" "aarch64-darwin" ];
      perSystem = { config, self', inputs', pkgs, system, ... }: {
        _module.args.pkgs = import nixpkgs
          {
            inherit system;
            overlays = [ emacs-overlay.overlays.default ];
          };
        packages.default = pkgs.emacsGit;
      };
      flake = { };
    };
}

_module.args.pkgs = import nixpkgs seems hacky and _module seems like something that's internal. Is that untrue?

from flake-parts.

ParetoOptimalDev avatar ParetoOptimalDev commented on June 2, 2024

@szlend Thank you so much for that context, that sounds like a good plan.

from flake-parts.

antifuchs avatar antifuchs commented on June 2, 2024

Just came up against another scenario where I don't quite get how to set the arguments on a flake part: I'm trying to define dockerContainers, and so (AIUI) I need to use withSystem, as they're not supported by perSystem.

My flake part defining these docker containers does the following:

{
  self,
  lib,
  pkgs',
  inputs,
  withSystem,
  ...
}: {
  flake.dockerContainers.boinkornet-monitor = withSystem "x86_64-linux" ({pkgs, ...}: pkgs.callPackage ./monitor {});
  flake.dockerContainers.boinkornet-media-forwarder = withSystem "x86_64-linux" ({pkgs, ...}: pkgs.callPackage ./media-forwarder {});
}

And the monitor/default.nix calls dockerTools.buildLayeredImage; I'd like the withSystem's pkgs argument to be augmented with overlays, but I don't quite see where to put the _module.args.pkgs in this scheme such that flake.parts can define the container with the right pkgs definition.

Update: The trick seems to be to use perSystem in my flake part and set a different argument (pkgs is already getting overridden with overlays in another part, and setting that leads to an infinite recursion). The following seems to work:

{
  self,
  lib,
  pkgs',
  inputs,
  withSystem,
  ...
}: {
  perSystem = {
    config,
    system,
    self',
    inputs',
    pkgs,
    ...
  }: {
    _module.args = {
      finalPkgs = import inputs.nixpkgs-linux {
        inherit system;
        overlays = [
          self.overlays.default # Pulls in the overlay defined by this flake
        ];
      };
    };
  };
  flake.dockerContainers.boinkornet-monitor = withSystem "x86_64-linux" ({finalPkgs, ...}: finalPkgs.callPackage ./monitor {}); # Uses the packages augmented with our flake's overlay
  flake.dockerContainers.boinkornet-media-forwarder = withSystem "x86_64-linux" ({pkgs, ...}: pkgs.callPackage ./media-forwarder {});
}

from flake-parts.

sandangel avatar sandangel commented on June 2, 2024

Hi, could someone help me, how to use easyOverlay with _module.args.pkgs?

from flake-parts.

sandangel avatar sandangel commented on June 2, 2024
      perSystem = { config, self', inputs', pkgs, system, lib, devenv, ... }: {
        _module.args = {
          pkgs = import nixpkgs {
            inherit system;
            # For ssm-session-manager-plugin
            config.allowUnfree = true;
            overlays = [
              (_: _: {
                inherit (config.packages) neovim-nightly vcluster kubeswitch yamlfmt comic-code flypie;
              })
            ];
          };
        };
        devenv.shells.default = {
          languages.nix.enable = true;
        };
        packages = with pkgs; {
          neovim-nightly = neovim.packages.${system}.neovim;
          vcluster = callPackage ./pkgs/vcluster { };
          kubeswitch = callPackage ./pkgs/kubeswitch { };
          yamlfmt = callPackage ./pkgs/yamlfmt { };
          comic-code = callPackage ./pkgs/comic-code { };
          flypie = callPackage ./pkgs/flypie { };
        };
        overlayAttrs = {
          inherit (config.packages) neovim-nightly vcluster kubeswitch yamlfmt comic-code flypie;
        };
      };

This is what I have so far. It's working but I like to do something like this:

        _module.args = {
          pkgs = import nixpkgs {
            inherit system;
            # For ssm-session-manager-plugin
            config.allowUnfree = true;
            overlays = [ config.flake.overlays.default ];
          };
        };
        overlayAttrs = {
          inherit (config.packages) neovim-nightly vcluster kubeswitch yamlfmt comic-code flypie;
        };

But it will generate error config.flake is not available.

from flake-parts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.