Nix / NixOS

1839 readers
3 users here now

Main links

Videos

founded 2 years ago
MODERATORS
1
12
submitted 3 days ago* (last edited 2 days ago) by [email protected] to c/nix
 
 

Hello everyone, I'm very close to finishing my configuration files for NixOS. I have those working on my nixos installation on my external drive, but before I officially move to nixos I'd like to make sure that I'm not doing something wrong.

Could someone please check my config files? (I only use flakes.nix, configuration.nix, home.nix and hardware.nix and I'd say they aren't much complicated.)

My main concearn is that I probably use the import and modules functions wrong (yet somehow they work?). I've read and watched numerous guides for the last 3 months, but I think I still mess this upπŸ˜…. I think following a bunch of different guides and videos added to the confusion a bit. (A recent guide I read made me have doubts about my set up.)

This is the link to my nixos configs:

https://codeberg.org/BlastboomStrice/dotfiles/src/branch/main/.config/nixos-conf

Hopefully by the end of the next week I'll be posting here about having transitioned to linux/nixos:)

Sample of probably wrong usage of modules in flakes.nix

    outputs = {self, nixpkgs, ... }@inputs: {
      nixosConfigurations = {
      nixos = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = { inherit inputs; };
        modules = [
          ./hosts/default/configuration.nix

          inputs.home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;

            home-manager.users.bs = import ./hosts/default/home.nix;

            home-manager.extraSpecialArgs = { inherit inputs; };
          }

#           inputs.spicetify-nix.nixosModules.default

Sample of probably wrong usage of imports in configuration.nix

imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      #inputs.home-manager.nixosModules.default
    ];

(I think I'm not using home manager in configuration.nix, that's why I've commented it out, and I'm importing it directly in flakes.nix.)

2
 
 

Howdy y'all non-developer trying to understand nix flakes.

3
 
 

Let's make managing infrastructure on your own machine less cumbersome. Simplify it with NixOS and containers.

4
 
 

In the process of updating one of my home manager configurations to 24.11, I got an error about a package being marked as broken. It was something like python3.12-libarcus. Let me tell you, that isn't listed in my configuration, and the stack trace didn't help me...so what do you do?

I discovered a tool called nix-tree: https://github.com/utdemir/nix-tree

It will scan a nix store and allow you to interactively look at all packages and their dependency tree. I decided to look at my current profile with nix-tree ~/.nix-profile/ and look around. (note, I think there's a better way to look at a configuration itself, not just a previous build.) The tool lets me search for dependencies, so I searched for python3.12-libarcus and it brought me to where it is in the tree...

I found the broken package! It was ultimaker cura, slicing software for 3d printers, which it turns out is very outdated in nixpkgs. There's discussions on the github about just wrapping the appimage instead of building from source. In the meantime, I removed pkgs.cura from my dependencies and my build was successful!

What other methods or tricks do you have to navigating build errors, or understand the nix store or your configuration better?

5
 
 

Recently got started with Nix and Home-Manager. I thought Advent Of Code would be a good way to get more comfortable with the Nix language.

I don't think I ever made it beyond Day 6 though, even in my most comfortable language (Python) so no idea where this will strand.

I am learning a lot about Nix though!

Have you used the Nix language outside of configuration? Let's share and discuss!

6
49
submitted 1 month ago* (last edited 1 month ago) by [email protected] to c/nix
 
 

I just upgraded my NixOS machine after switching to nixos-unstable-small because I think unstable will take some time to update as getting 24.11 out has the highest priority.

Anyhow, two of my packages stopped me from applying a new configuration, as some packages have been changed when reorganizing into pkgs/by-name. I fixed it and wanted to share as this will hit others running unstable with these packages as soon as hydra catches up.

nerdfonts (now nerd-fonts)

Package was renamed, which it will state on evaluation; individual fonts are now part of the nerd-fonts attribute. I had Source Code Pro in there, there was some kind of mapping, which looked kind of like in https://wiki.nixos.org/wiki/Fonts#Installing_specific_fonts_from_nerdfonts – the new way is now to just use nerd-fonts.sauce-code-pro directly, you can probably do something like ++ with nerd-fonts; [ sauce-code-pro other-fonts ] to add multiple nerd-fonts to your fonts list, but I haven't tested this.

RetroArch

Until now, cores were specified as in https://wiki.nixos.org/wiki/RetroArch, however override doesn't seem to work anymore. There's now the withCores attribute / function that expects a function that returns a list. The easiest way I found to just specify a fixed list of cores was (retroarch.withCores (_: with libretro; [ snes9x mupen64plus fbneo flycast ])). Maybe other options are easier / cleaner.

Word of warning on compiling nixos-unstable-small

There are currently a lot of packages to be built if you change into that channel (I'm using flakes, but you get my point). Due to the default value of auto for nix.settings.max-jobs, this meant nix tried to build 24 derivations at the same time. This is fine if these are just downloaded from hydra, but if you try to build 24 big derivations at the same time, each trying to use 24 threads because nix.settings.cores is also 0 by default, which means all threads, build processes quickly ate all of my 32GB of RAM so that the OOM killer had to intervene, however often too late with my system dying. I recommend to set nix.settings.max-jobs to something more reasonable before attempting this (I used 1).

7
 
 

I experimented with several ways to run my services:

  1. "regular" systemd services (services.glance = { ... };)
  2. nix containers (containers.glance = { ... };)
  3. podman containers (virtualisation.oci-containers.containers.glance = { ... })

and I must say I'm starting to appreciate the last option (the least nixos-y) more and more.

Specifically, I appreciate that:

  • I just have to learn the app/container configuration, instead of also backwards-translating from their config into the various nixos options (of course the .yaml or whatever configuration files are still generated from my nixos config, I just do that in a derivation instead on relying on a module doing it for me)
  • Services are sometimes outdated in nixpks (even in unstable - and juggling packages between stable and unstable is yet another complication)
  • I feel like it's more secure (very arguable and also of very little consequence since everything is on my homelab... it's mainly for the warm fuzzies)

Do you guys use one of the options above? Something different?

8
 
 

This is a group chat to discuss anything nix-related

9
15
submitted 1 month ago* (last edited 1 month ago) by [email protected] to c/nix
 
 

I've been trying nixos recently and after watching a bunch of tutorials from various people, I have managed to enable home-manager and flakes.

My question is: where should I write the packages I want to install? In home.nix? In flakes.nix? In configuration.nix (probably not)? I'm probably only gonna have a single user on this machine.

So far, I think the only difference between writing the packages in home.nix compared to flakes.nix is that in the 1st senario, the apps will only be available for the user, while in the 2nd, it will be available for the whole system. Also, I could use the home.nix for non-nixos systems too. Other than that, I can probably write them the same way either on home.nix or flakes.nix and have the same result on my machine.

PS. On search.nixos.org there is an option to search for flakes. What is this? I am planing to get my packages from the packages tab, but I'm wondering that maybe I should search in the flakes tab instead (though it doesn't seem to have many packages).

PPS. Those are some resources I've found (I've mainly watched the videos and have started reading some of the guides):

10
 
 

I try to add an application that was installed with homebrew (managed by nix darwin) to the "Open at Login" settings under "General -> Login Items & Extensions".

I tried to add a launchd.user.agents entry, but that didn't work. The app is only adeded to the "Allow in the Background" settings and does not start on login.

  launchd.user.agents = {
    sanesidebuttons = {
      serviceConfig = {
        Label = "com.thealpa.sanesidebuttons";
        RunAtLoad = true;
        Program = "/Applications/SaneSideButtons.app";
      };
    };
  };

Any ideas how to add an entry to the "Open at Login" settings with nix darwin? launchd.agents and launchd.daemons seems to be the wrong place as well.

11
5
submitted 1 month ago* (last edited 1 month ago) by [email protected] to c/nix
 
 

edit: for the solution, see my comment below

I'm trying to package a go application (beszel) that bundles a bunch of html stuff built with bun (think, npm).

The html is generated by running bun install and bun run and then embedded in the go binary with //go:embed.

Being completely ignorant of the javascript ecosystem, my first idea was to just replicate what they do in the Makefile

postConfigure = ''
bun install --cwd ./site
bun run     --cwd ./site build
'' 

but, since bun install downloads dependencies from the net, that fails.

I guess the "clean" solution would be to look for buildNpmPackage or similar (assuming that exists) and let nix manage all the dependencies, but... it's some 800+ dependencies (at least, bun install ... --dry-run lists 800+ things) so that's a hard pass.

I then tried to look at how buildGoPackage handles the vendoring of dependencies, with the idea of replicating that (it dowloads what's needed and then compare a hash of what was downloaded with a hash provided in the nix package definition), but... I can't for the life of me decipher how nixpkgs' pkgs/build-support/go/module.nix works.

Do you know how to implement this kind of vendoring in a nix derivation?

12
33
The future of software is Nix (determinate.systems)
submitted 2 months ago by starman to c/nix
13
12
submitted 2 months ago by [email protected] to c/nix
14
50
Announcing Determinate Nix (determinate.systems)
submitted 2 months ago by starman to c/nix
15
16
 
 

Homebrew is the most popular package manager on MacOS, and for good reason. However personally, I believe that Nix is more powerful.

17
 
 

edit: for the solution, see my comment below

I need/want to build aeson and its subproject attoparsec-aeson from source (it's a fork of the "official" aeson), but I'm stuck... can you help out?

The sources of attoparsec-aeson live in a subdirectory of the aeson ones, so I have the sources:

aeson-src = fetchFromGitHub {
  ...
};

and the "main" aeson library:

aeson = haskellPackages.mkDerivation {
  pname = "aeson";
  src = aeson-src;
  ...
};

When I get to attoparsec-aeson however I run into a wall: I tried to follow the documentation about sourceRoot:

attoparsec-aeson = haskellPackages.mkDerivation {
  pname = "attoparsec-aeson";
  src = aeson-src;
  sourceRoot = "./attoparsec-aeson"; # maybe this should be "${aeson-src}/attoparsec-aeson"?
                                     # (it doesn't work either way)
  ...
};

but I get

 error: function 'anonymous lambda' called with unexpected argument 'sourceRoot'

Did I fail to spot some major blunder (I am nowhere near an expert)? Does sourceRoot not apply to haskellPackages.mkDerivation? What should I do to make it work?

BTW:

IDK if this may cause issues, but the attoparsec-aeson sources include symlinks to files in the "main" attoparsec sources:

~/git-clone-of-attoparsec-sources $ tree attoparsec-aeson/
attoparsec-aeson/
β”œβ”€β”€ src
β”‚Β Β  └── Data
β”‚Β Β      └── Aeson
β”‚Β Β          β”œβ”€β”€ Internal
β”‚Β Β          β”‚Β Β  β”œβ”€β”€ ByteString.hs -> ../../../../../src/Data/Aeson/Internal/ByteString.hs
β”‚Β Β          β”‚Β Β  β”œβ”€β”€ Text.hs -> ../../../../../src/Data/Aeson/Internal/Text.hs
β”‚Β Β          β”‚Β Β  └── Word8.hs -> ../../../../../src/Data/Aeson/Internal/Word8.hs
β”‚Β Β          β”œβ”€β”€ Parser
β”‚Β Β          β”‚Β Β  └── Internal.hs
β”‚Β Β          └── Parser.hs
β”œβ”€β”€ attoparsec-aeson.cabal
└── LICENSE
18
19
20
21
13
Flatpaks in app menu (lemmy.sdf.org)
submitted 3 months ago by [email protected] to c/nix
 
 

I believe I solved this problem before, but I can't find the solution again. I have some Flatpaks installed on my NixOS system, but they aren't showing up in the app menu. Does anyone know what might be causing this or how to fix it?

22
 
 
23
5
Git hashes in Nix (wastedintel.ca)
submitted 3 months ago by [email protected] to c/nix
 
 
24
23
submitted 3 months ago* (last edited 3 months ago) by [email protected] to c/nix
25
 
 

I'm trying to set up a simple script (linked to a hotkey in my window manager) that can launch a terminal window with a nix-shell containing packages I specify. So far, I got this:

set packages (fuzzel -d --lines 0 --prompt 'packages for nix-shell > ')
kitty nix-shell --packages $packages --run fish

If I type a single package into my runlauncher (fuzzel) (e.g. grim), the window spawns with a nix-shell as expected; if, however, I attempt to launch a shell with multiple packages (e.g. grim slurp), it fails to launch with the following error:

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'shell'
         whose name attribute is located at /nix/store/cjz8w4dgc3rd2n3dqv5c208vygndjyba-source/pkgs/stdenv/generic/make-derivation.nix:336:7

       … while evaluating attribute 'buildInputs' of derivation 'shell'

         at /nix/store/cjz8w4dgc3rd2n3dqv5c208vygndjyba-source/pkgs/stdenv/generic/make-derivation.nix:383:7:

          382|       depsHostHost                = elemAt (elemAt dependencies 1) 0;
          383|       buildInputs                 = elemAt (elemAt dependencies 1) 1;
             |       ^
          384|       depsTargetTarget            = elemAt (elemAt dependencies 2) 0;

       error: attempt to call something which is not a function but a set

       at Β«stringΒ»:1:107:

            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (grim slurp) ]; } ""
             |                                                                                                           ^

This happens with or without launching a new kitty window, and it happens with other runlaunchers as well. Why on earth isn't this working?

Any help appreciated---thanks, everyone.

view more: next β€Ί