# How to manage nixos and nixpkgs using flakes

**URL:** https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463
**Category:** Help
**Created:** [April 1, 2025, 1:45am UTC](https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463 "2025-04-01T01:45:05Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![0x-Avant-Garde](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/0/4bbf92/32.png) [@0x-Avant-Garde](https://discourse.nixos.org/u/0x-Avant-Garde)
#### Post date: [April 1, 2025, 1:45am UTC](https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463/1 "2025-04-01T01:45:05Z")

</div>

While I admit I’m rather new to nix, I have not been able to find any clear information on this.

Using channels I know you just do  
… nixpkgs  
… nixos

And when you rebuild and/or upgrade it knows where to pull from (although I’ve had this act weird as well)

But I can’t find how to, for example, use the nixos-unstable branch for nixpkgs only, and the 24.11 branch for nixos using flakes.

---

<div class="post-metadata">

### Author: ![cig0](https://discourse.nixos.org/user_avatar/discourse.nixos.org/cig0/32/31645_2.png) [@cig0](https://discourse.nixos.org/u/cig0)
#### Post date: [April 1, 2025, 2:14am UTC](https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463/2 "2025-04-01T02:14:02Z")

</div>

Vimjoyer does a great job explaining how they work; his content helped me greatly when I started looking at them a year ago:

[![](https://img.youtube.com/vi/vYc6IzKvAJQ/maxresdefault.jpg "Modularize NixOS and Home Manager | Great Practices") ](https://www.youtube.com/watch?v=vYc6IzKvAJQ&t=207s)

[![](https://img.youtube.com/vi/JCeYq72Sko0/maxresdefault.jpg "Ultimate Nix Flakes Guide") ](https://www.youtube.com/watch?v=JCeYq72Sko0)

[![](https://img.youtube.com/vi/rEovNpg7J0M/maxresdefault.jpg "Move your NixOS into a Flake!") ](https://www.youtube.com/watch?v=rEovNpg7J0M)

[![](https://img.youtube.com/vi/S3VBi6kHw5c/maxresdefault.jpg "Nix flakes explained") ](https://www.youtube.com/watch?v=S3VBi6kHw5c)

Many other NixOS users have fantastic videos about how to get started with flakes, too, for instance:

[![](https://img.youtube.com/vi/ACybVzRvDhs/maxresdefault.jpg "You Should Use Flakes Right Away in NixOS!") ](https://www.youtube.com/watch?v=ACybVzRvDhs)

[![](https://img.youtube.com/vi/ARjAsEJ9WVY/maxresdefault.jpg "NixOS Flake Tour") ](https://www.youtube.com/watch?v=ARjAsEJ9WVY)

[![](https://img.youtube.com/vi/Hox4wByw5pY/maxresdefault.jpg "NixOS 40: Converting an Existing NixOS Configuration To Flakes") ](https://www.youtube.com/watch?v=Hox4wByw5pY)

[![](https://img.youtube.com/vi/CwfKlX3rA6E/maxresdefault.jpg "NixOS: Everything Everywhere All At Once") ](https://www.youtube.com/watch?v=CwfKlX3rA6E)

The past LinuxFest event has some great NixOS content too:

[![](https://img.youtube.com/vi/IDFuOCHXdzI/maxresdefault.jpg "LinuxFest Northwest 2024: 5 Reasons to Love NixOS") ](https://www.youtube.com/watch?v=IDFuOCHXdzI)

Personally, IIRC this was **the** talk that made me rethink my whole existence as a GNU/Linux user:

[![](https://img.youtube.com/vi/0uixRE8xlbY/maxresdefault.jpg "Matthew Croughan - Use flake.nix, not Dockerfile - MCH2022") ](https://www.youtube.com/watch?v=0uixRE8xlbY)

All praise to these great folks 🙌

There’s a lot to unpack there so take your time, start small, and iterate → repeat 🙂

---

<div class="post-metadata">

### Author: ![0x-Avant-Garde](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/0/4bbf92/32.png) [@0x-Avant-Garde](https://discourse.nixos.org/u/0x-Avant-Garde)
#### Post date: [April 1, 2025, 2:33am UTC](https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463/3 "2025-04-01T02:33:16Z")

</div>

I’ve watched a few of these videos, I will watch the rest, thanks!

I think I might have a core misunderstanding in how the OS itself is updated.

I just read a bit deeper into the --upgrade flag and it says it updates the channel of the root user before rebuilding.

I wasn’t having any issues really until I tried to use the nixos-unstable-small branch to get some packages that were updated there but not on the main unstable branch, which led to lots of weird behavior such as nothing being updated at all.

Maybe I should, for simplicity sake, just leave my nixos channel as 24.11 and use flakes for packages, although I’m still curious how I could manage both from flakes

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [April 1, 2025, 3:18am UTC](https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463/4 "2025-04-01T03:18:12Z")

</div>

Stop using `--upgrade` with flakes. You can also delete your channels.

> <https://github.com/eclairevoyant/flake-migration/blob/d9e00d26de6fbf4aaf2ced29ea95542c3a795525/nixos.md>

Very simple.

---

<div class="post-metadata">

### Author: ![0x-Avant-Garde](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/0/4bbf92/32.png) [@0x-Avant-Garde](https://discourse.nixos.org/u/0x-Avant-Garde)
#### Post date: [April 1, 2025, 3:32am UTC](https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463/5 "2025-04-01T03:32:35Z")

</div>

Yes I understand this much, but how can I update the os separate from the packages, and vice versa.

For instance if I was using nixos-unstable channel in flakes, but I want to use the 24.11 channel for the OS itself, how do I accomplish that.

Or maybe easier to understand, what if I install nixos 24.11, make a flake for my packages using nixos-unstable, and then want to change my OS to nixos-23.11.

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [April 1, 2025, 3:45am UTC](https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463/6 "2025-04-01T03:45:17Z")

</div>

> [@0x-Avant-Garde](#):
>
> want to change my OS to nixos-23.11.

You don’t, because 23.11 doesn’t get updates.

I don’t understand your question, this is my best guess at what you’re looking for.  
I also would not recommend this, though. Just pick either stable or unstable and stick with it, don’t mix.

> [@Mixing stable and unstable packages on flake-based NixOS system](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/4):
>
> EDIT: Huge caveat - I strongly recommend not mixing stable with unstable on the same system. It’s unsupported and can lead to confusing errors when going to run programs, due to glibc and graphics driver mismatches. Never set pkgs directly in the NixOS module system, as the other answers are indicating. Here’s a couple of concepts you need to know: If you want to access some inputs, or some other value across your config without creating an explicit option for it, use specialArgs or \_module.…

---

<div class="post-metadata">

### Author: ![0x-Avant-Garde](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/0/4bbf92/32.png) [@0x-Avant-Garde](https://discourse.nixos.org/u/0x-Avant-Garde)
#### Post date: [April 1, 2025, 3:50am UTC](https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463/7 "2025-04-01T03:50:10Z")

</div>

So the TLDR is if I want to use the unstable branch for packages, I should also use it for the OS?

I guess that makes sense as the packages in each branch are tested against the rest of that branch.

I thought I could get more granular, like using unstable for OS related things (gnome 48 for example) while using stable branch for packages ( or vice versa using 24.11 branch for OS but unstable for newer packages, like code-cursor which is only up to date on unstable currently)

I guess for the latter I could keep the channel as 24.11 and have the flake use the unstable?

---

<div class="post-metadata">

### Author: ![cig0](https://discourse.nixos.org/user_avatar/discourse.nixos.org/cig0/32/31645_2.png) [@cig0](https://discourse.nixos.org/u/cig0)
#### Post date: [April 1, 2025, 5:02am UTC](https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463/8 "2025-04-01T05:02:10Z")

</div>

Oh yeah, you can if you do it properly.

I’ve a `packages.nix` module where, alongside declaring the packages I want to pull from `stable` and `nixpkgs-unstable`, I define this variable `pkgsUnstable`:

```nix
  pkgsUnstable = import inputs.nixpkgs-unstable {
    inherit system;
    config = {
      allowUnfree = true;
    };
  };

```

That allows me to define groups of attribute sets for the packages I want to install from either OR both channels, this way:

```nix
  packagesBaseline =
    with pkgs;
    [
      # Nix - Security
      vulnix # NixOS vulnerability scanner :: https://github.com/nix-community/vulnix

      # Networking
      httping # Ping with HTTP requests :: https://vanheusden.com/httping

      # Python
      python312 # High-level dynamically-typed programming language :: https://www.python.org
      python312Packages.ipython # IPython: Productive Interactive Computing :: https://ipython.org/

      # Storage
      nfstrace # NFS and CIFS tracing/monitoring/capturing/analyzing tool :: NFS and CIFS tracing/monitoring/capturing/analyzing tool
    ]
    ++ (with pkgsUnstable; [
      # Misc
      at
      bat
      broot # Interactive tree view, a fuzzy search, a balanced BFS descent and customizable commands :: https://dystroy.org/broot/
      chezmoi
...
...
]);

```

And do:

```nix
    environment.systemPackages =
      [] # Start with an empty list or your base packages
      ++ lib.optionals cfg.baseline packagesBaseline
      ++ lib.optionals cfg.cli._all (builtins.concatLists (builtins.attrValues packagesCli))
      ++ lib.optionals cfg.cli.ai packagesCli.ai
      ++ lib.optionals cfg.cli.backup packagesCli.backup
      ++ lib.optionals cfg.cli.cloudNativeTools packagesCli.cloudNativeTools
      ++ lib.optionals cfg.cli.comms packagesCli.comms
      ++ lib.optionals cfg.cli.databases packagesCli.databases
      ++ lib.optionals cfg.cli.misc packagesCli.misc # TODO_ properly categorize the packages
      ++ lib.optionals cfg.cli.multimedia packagesCli.multimedia
      ++ lib.optionals cfg.cli.programming packagesCli.programming
      ++ lib.optionals cfg.cli.secrets packagesCli.secrets
      ++ lib.optionals cfg.cli.security packagesCli.security
      ++ lib.optionals cfg.cli.vcs packagesCli.vcs
      ++ lib.optionals cfg.cli.web packagesCli.web
      ++ lib.optionals cfg.gui packagesGui
      ++ lib.optionals cfg.guiShell.kde packagesGuiShell.kde
      ++ lib.optionals cfg.nvidia packagesNvidia
      ++ config.mySystem.myOptions.packages.modulePackages; # Add packages contributed by other modules

```

To assemble the final list of packages to install from both channels, I created several options that allow me to easily toggle what set of packages I want to install on each different host–each host has a profile where you can choose not only what packages to install, but also configure everything else.

There’s a bunch of community flakes I rely on too, so properly defining both channels in the flake, like this:

```nix
 inputs = {
    nixpkgs.url = "nixpkgs/nixos-24.11"; # NixOS release channel
    nixpkgs-unstable.url = "nixpkgs/nixos-unstable"; # The unstable release channel to allow for fresher packages
}

```

It’s super important to configure them, e.g.:

```nix
    # Snapd support for NixOS
    nix-snapd = {
      inputs.nixpkgs.follows = "nixpkgs-unstable";
      url = "github:nix-community/nix-snapd";
    };

    # A Neovim configuration system for Nix
    nixvim = {
      inputs.nixpkgs.follows = "nixpkgs";
      url = "github:nix-community/nixvim/nixos-24.11";
    };

```

Notice how the `nix-snapd` flake input follows `nixpkgs-unstable` and `nixvim` follows the stable channel.

HTH

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [April 1, 2025, 11:41am UTC](https://discourse.nixos.org/t/how-to-manage-nixos-and-nixpkgs-using-flakes/62463/9 "2025-04-01T11:41:12Z")

</div>

I would not mix flakes and channels, you’ll end up confusing yourself even more when you go to update your system.  
And again, I would strongly not recommend that you try to mix flake inputs. But if you want to, I linked instructions on how to do so.
