How to create local repo/custom .nix package instructions?

so hello, i i wonder i am coming from gentoo, in gento i have my own local repo, wia eselect repository, and i update old packages not update in main repo, or in any overlay, or create my own for packages that are not support, for example i have some for newest prusa slicer, and orca slicer, also freecad dev, etc.

how is this possible in nixos? like i dont want to write .nix and then just install it via nix-shell, i want to set a repo include it, so when i do nixos-rebuild --upgrade-all switch, i get the newest package, which probably will be mine in my local repo, is there a way to do this?

this is only thing keeping me from switching, i’d like to keep som of my most essential packages most up to date without stable channel or relying on other devs

1 Like

Hmm, you don’t want to write any nix?

If you learn even a basic subset of the nix expression language (nixel) , you’ll unlock the true power of the operating system. :slight_smile:

you may find this post of interest to you.

for more advanced configuration you can fork nixpkgs into your own repo, and build you packages from that, nix doesn’t really care, because in effect your building transparent statically linked ‘containers’. however if any of those ‘containers’ share a library, then it it shared. You can achieve the same effects with nix ‘overlays’ or ‘overrides’.

So, nix is a hybrid linker… pretty neat huh.

Being a gentoo user for many years, i had to rewrite my brain to the nix way. It was worth it, but maybe guix would be more suited to you if you know scheme already?

There is a ton of resources to learn nixel, it’s also sometime a ‘gateway’ drug to functional programming in general… so you never know, you could be committing to nix in a matter of months, a be part of the operating system , you’ll start to rely on yourself for everything…

as you said in your original post ‘with out relying on other devs’… nix can certainly do that. if fact nix can almost do anything, and you can ‘share’ those reproducible results with others…

sometimes, i have to shake myself to the brilliance nix, and tell myself ‘does it really exist?’.

Nix means nothing , so i guess that answers that question is ‘no’.

A ‘flake’ might be the way to go for your problem, you can then have a lot more control.

May the nix be with you,
Always…

1 Like

Sure, you can do it easily, with multiple methods. Since nix considers channels and programs as just variables, you can do many different things. If you really want to, you can clone the whole nixpkgs and just point your channel to this clone, e.g. via:

nix-channel --add https://your/nixpkgs/clone nixos

but maintaining a clone of nixpkgs might be a bit tedious. You can also create a channel (a channel is nothing more that a set of programs) containing only the programs you wish to install this way, read below for more details. Another, more recommended option, is to use overlays:

{ config, pkgs, lib, ... }:
{
   # [...]
   nixpkgs.overlays = [ (final: prev: { yourPackage = pkgs.stdenv.mkDerivation {…}; } ];
}

This also allows you to change only the version of a package based on a package already existing in nixpkgs, for instance using overrideAttrs, you can read more here Overlays - NixOS Wiki or in the manual. Overlays have the advantage that if you modify an existing package, it will also use that version in NixOs modules (e.g. the gitea module), which might not be the case by default with other methods.

Since programs are just variables, you can also just install a program like:

{config, ...}:
{
  environment.systemPackages = [
    # create a new package from scratch
    (pkgs.stdenv.mkDerivation {…})
    # Install a package from nixpkgs
    emacs
    # Create a new package from an old one coming from nixpkgs
    (vim.overrideAttrs {…})
  ];
}

If your derivation is getting long/complex, you can also put in a different file myProgram.nix:

{stdenv, any, other, dependency, like, gtk3}:
stdenv.mkDerivation {
  …
}

and in your configuration just add:

environment.systemPackages = [
  (pkgs.callPackage ./myProgram.nix {})
];

(this is the method I choose most of the time as it is simple to maintain, and packages are directly included in the git repository of my configuration)

Finally, you can also create a channel containing only the programs you like (so no need to take the whole nixpkgs), and do something like:

nix-channel --add https://your/channel yourchannel

where the channel contains a default.nix file containing:

{ pkgs ? import <nixpkgs> {} }:
{
  yourFirstPackage = pkgs.stdenv.mkDerivation {};
}

and change your configuration using something like:

{config, pkgs, ...}:
let yourChannel = import <yourchannel> { inherit pkgs; }; in
{
  environment.systemPackages = [
    yourChannel.yourFirstPackage
  ];
}

You can also “pin” yourChannel to a precise url like:

let yourChannel = import (builtins.fetchGit {
  # Descriptive name to make the store path easier to identify
  name = "nixos-unstable-2018-09-12";
  url = "https://github.com/nixos/nixpkgs/";
  # Commit hash for nixos-unstable as of 2018-09-12
  # `git ls-remote https://github.com/nixos/nixpkgs nixos-unstable`
  ref = "refs/heads/nixos-unstable";
  rev = "ca2ba44cab47767c8127d1c8633e2b581644eb8f";
}) {}

Many options!

2 Likes

Oh btw, shameful self-promotion: if you are new to nix, you might like my introduction to creating your own nix derivation here.

2 Likes

I made such a project at GitHub - drupol/my-own-nixpkgs: Scaffold

Hope you’ll find it useful.