Use package defined in flake repo within flake nixos configuration

Dear all, I defined a flake for a program I want to use here, how could I include this in a nixos configuration also with flakes? I include the repo as input but have no clue how to get the actual package into my config. It looks like this at the moment:

  description = "System configuration for all my computers";
  inputs = {
    nixos.url = "github:NixOS/nixpkgs/nixos-21.11";
    nixos-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    emacs-overlay.url = "github:nix-community/emacs-overlay/master";
    doom-emacs = {
      url = "github:hlissner/doom-emacs/develop";
      flake = false;
    };
    flake-utils = {
      url = "github:numtide/flake-utils";
      inputs.nixpkgs.follows = "nixos";
    };
    nix-doom-emacs = {
      url = "github:nix-community/nix-doom-emacs/master";
      inputs = {
        doom-emacs.follows = "doom-emacs";
        nixpkgs.follows = "nixos";
        emacs-overlay.follows = "emacs-overlay";
        flake-utils.follows = "flake-utils";
      };
    };
    home-manager = {
      url = "github:nix-community/home-manager/release-21.11";
      inputs = { nixpkgs.follows = "nixos"; };
    };
    agenix = {
      url = "github:ryantm/agenix/main";
      inputs.nixpkgs.follows = "nixos";
    };
    mage = {
      url = "github:timhae/mage/release";
      inputs.nixpkgs.follows = "nixos";
      inputs.flake-utils.follows = "flake-utils";
    };
  };
  outputs = { self, nixos, nixos-unstable, emacs-overlay, nix-doom-emacs
    , doom-emacs, home-manager, agenix, mage, ... }:
    let
      system = "x86_64-linux";
      user = "tim";
      pkgs = mkPkgs (import nixos) [
        (_: super: {
          steam = super.steam.override { extraPkgs = pkgs: [ pkgs.libpng ]; };
        })
      ];
      pkgs-unstable = mkPkgs (import nixos-unstable) [ ];
      mkPkgs = pkgs: overlays:
        pkgs {
          inherit system;
          overlays = [ emacs-overlay.overlay ] ++ overlays;
          config.allowUnfree = true;
        };
      cfg = machine:
        nixos.lib.nixosSystem {
          inherit pkgs system;
          specialArgs = { inherit pkgs pkgs-unstable agenix mage; };
          modules = [
            (./. + "/${machine}.nix")
            nixos.nixosModules.notDetected
            home-manager.nixosModules.home-manager
            {
              home-manager = {
                useGlobalPkgs = true;
                useUserPackages = true;
                users."${user}" = { pkgs, ... }: {
                  imports =
                    [ nix-doom-emacs.hmModule (./. + "/${machine}Home.nix") ];
                };
              };
            }
            agenix.nixosModules.age
          ];
        };
    in {
      nixosConfigurations.nixosLaptop = cfg "laptop";
      nixosConfigurations.nixosDesktop = cfg "desktop";
      nixosConfigurations.nixosServer = cfg "server";
    };
}

and in laptop.nix I have:

{ config, lib, pkgs, mage, ... }: {
  imports = [ ./common/common.nix ./common/gaming.nix ./common/udev.nix ];
  boot = {
    kernelModules = [ "kvm-intel" ];
    extraModulePackages = [ ];
    initrd = {
      availableKernelModules =
        [ "xhci_pci" "nvme" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ];
      kernelModules = [ "dm-snapshot" ];
      luks.devices.root = {
        device = "/dev/nvme0n1p2";
        preLVM = true;
      };
    };
  };
  environment.systemPackages = with pkgs; [
    acpi # for info script
    iw # wifi signal strength
    xorg.xbacklight # enable backlight function keys
    mage.defaultPackage.x86_64-linux # how????
  ];
  fileSystems."/" = {
    device = "/dev/disk/by-uuid/7649fbf8-3ab1-4991-a283-bcb872a5e0c3";
    fsType = "ext4";
  };
  fileSystems."/boot" = {
    device = "/dev/disk/by-uuid/AF89-3C32";
    fsType = "vfat";
  };
  swapDevices =
    [{ device = "/dev/disk/by-uuid/b3749b7b-f9c4-4af9-a8fe-ef1b93b37159"; }];
  powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
  networking.hostName = "nixosLaptop"; # Define your hostname
  powerManagement.powertop.enable = true;
  services.upower.enable = true;
  services.xserver = {
    dpi = 144;
    libinput = {
      touchpad = {
        accelSpeed = "1";
        naturalScrolling = true;
      };
    };
  };
}

What do I need to put in my environment.systemPackages to get the progam I defined in the flake? can someone please point me to documentation covering this topic? Or maybe give me a hint what I am doing wrong? :smiley: thanks a lot!!

1 Like

You’d use mage.defaultPackage in environment.systemPackages. If it’s in your flake.nix, that’s all you need to do, but if you instead define it in your imported modules you need to make mage available to them somehow.

The documentation on anything flakes-related is sparse, but by reading the module resolution code in nixpkgs you can deduce this answer: Install agenix in "environment.systemPackages" on nixos with flakes - #2 by ilkecan

Personally I’m not a big fan of that solution, so I still suggest doing what I recommend in my comment further down on that same thread. For that you would need to add an overlay to timhae/mage, much like the one I link to in my comment.

Thanks, I had to append my system architecture as in mage.defaultPackage.x86_64-linux

I would like to avoid that if possible :smiley: I just want to use nix as a package manager but I guess given the sparse documentation it would be helpful to read the source from time to time. Thanks for your help!

Yep, didn’t mean to suggest you should, just explaining where I got that from! Ideally you wouldn’t need to, hopefully we can get there one day - flakes are hot off the press, so things can be a bit rough.