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

**URL:** https://discourse.nixos.org/t/how-to-create-local-repo-custom-nix-package-instructions/35853
**Category:** Development
**Created:** [November 22, 2023, 8:17am UTC](https://discourse.nixos.org/t/how-to-create-local-repo-custom-nix-package-instructions/35853 "2023-11-22T08:17:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![picarica](https://discourse.nixos.org/user_avatar/discourse.nixos.org/picarica/32/11883_2.png) [@picarica](https://discourse.nixos.org/u/picarica)
#### Post date: [November 22, 2023, 8:17am UTC](https://discourse.nixos.org/t/how-to-create-local-repo-custom-nix-package-instructions/35853/1 "2023-11-22T08:17:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nixinator](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nixinator/32/3859_2.png) [@nixinator](https://discourse.nixos.org/u/nixinator)
#### Post date: [November 22, 2023, 8:37am UTC](https://discourse.nixos.org/t/how-to-create-local-repo-custom-nix-package-instructions/35853/2 "2023-11-22T08:37:23Z")

</div>

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. 🙂

you may find this post of interest to you.

> [@Installing only a single package from \`unstable\`](https://discourse.nixos.org/t/installing-only-a-single-package-from-unstable/5598):
>
> Hi there. I manage some NixOS machines, which are pinned to a particular stable branch from 2019, and I’m fine with this. However, the version of certbot that this branch offers is 0.31.0, while unstable has 1.0.0. I’d like to upgrade, and do so via the usual environment.systemPackages list. However, I don’t want to update the whole channel (thus bumping everything else on the system), just certbot. Is this possible? Please and thank 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…

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [November 22, 2023, 8:37am UTC](https://discourse.nixos.org/t/how-to-create-local-repo-custom-nix-package-instructions/35853/3 "2023-11-22T08:37:42Z")

</div>

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:

```auto
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:

```auto
{ 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](https://nixos.wiki/wiki/Overlays) 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:

```auto
{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`:

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

```

and in your configuration just add:

```auto
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:

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

```

where the channel contains a `default.nix` file containing:

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

```

and change your configuration using something like:

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

```

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

```auto
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!

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [November 22, 2023, 9:04am UTC](https://discourse.nixos.org/t/how-to-create-local-repo-custom-nix-package-instructions/35853/4 "2023-11-22T09:04:12Z")

</div>

Oh btw, shameful self-promotion: if you are new to nix, you might like my introduction to creating your own nix derivation [here](https://unix.stackexchange.com/questions/717168/how-to-package-my-software-in-nix-or-write-my-own-package-derivation-for-nixpkgs).

---

<div class="post-metadata">

### Author: ![drupol](https://discourse.nixos.org/user_avatar/discourse.nixos.org/drupol/32/9471_2.png) [@drupol](https://discourse.nixos.org/u/drupol)
#### Post date: [April 16, 2024, 4:54am UTC](https://discourse.nixos.org/t/how-to-create-local-repo-custom-nix-package-instructions/35853/5 "2024-04-16T04:54:43Z")

</div>

I made such a project at [GitHub - drupol/my-own-nixpkgs: Scaffold](https://github.com/drupol/my-own-nixpkgs)

Hope you’ll find it useful.
