Stream: social-media

Topic: StackOverflow


view this post on Zulip Zapier (Nov 30 2023 at 01:55):

Loop over a list in NixOS using the value as an identifier?

Link: https://stackoverflow.com/questions/77569447/loop-over-a-list-in-nixos-using-the-value-as-an-identifier

In vhost.nix I want to add the users in a loop like the working example in httpd.virtualHosts.

This is the configuration.nix I am using in a virtual machine:

vm.nix

{ lib, config, ... }:

{

imports = [

./vhosts.nix

];

services.httpd.enable = true;

vhosts = {

"test.example.de" = {

customer = "web2";

phpuser = "web2www1";

};

"test2.example.de" = {

customer = "web3";

phpuser = "web3www1";

};

};

}

this my module vhost.nix

{ config, pkgs, lib, ... }:

with lib;

let

cfg = config.vhosts;

in

{

options.vhosts = lib.mkOption {

type = with lib.types; attrsOf (submodule ({domain, ... }: {

options = {

customer = mkOption {

type = str;

};

phpuser = mkOption {

type = str;

};

};

}));

};

config = {

services.httpd.virtualHosts = lib.mapAttrs (domain: cfg: {

documentRoot = "/srv/www/${cfg.customer}/${domain}";

}) cfg;

how do I solve this in a loop like above ?

users.users.web2www1.isNormalUser = true;

users.users.web3www1.isNormalUser = true;

};

}

how do I solve this in a loop like above ?

Published Date: 2023-11-29T08:06:37Z

view this post on Zulip Zapier (Dec 01 2023 at 12:37):

How to allow "unfree" packages in Nix, for each situation?: {NixOS, Nix, Nix with Flakes, Nix with Flakes and Home Manager}

Link: https://stackoverflow.com/questions/77585228/how-to-allow-unfree-packages-in-nix-for-each-situation-nixos-nix-nix-wit

I'm trying to enable allow "unfree" packages, either globally or per-package, when using MyNixOS (excellent Flake configuration app for Nix) with Nix Flakes on Mac OS.

When trying to install any unfree package after the following Flake update and Darwin rebuild command:

cd ~/.nix/mynixos-nix-darwin-loader;

nix flake update;

darwin-rebuild switch --show-trace --flake .#name_of_my_config'

I get the following help message, which isn't very helpful because it doesn't consider the Flake scenario:

error: Package ‘ec2-api-tools-1.7.5.1’ in /nix/store/${hash}-source/pkgs/tools/virtualization/e

c2-api-tools/default.nix:36 has an unfree license (‘amazonsl’), refusing to evaluate.

a) To temporarily allow unfree packages, you can use an environment variable

for a single invocation of the nix tools.

$ export NIXPKGS_ALLOW_UNFREE=1

Note: For nix shell, nix build, nix develop or any other Nix 2.4+

(Flake) command, --impure must be passed in order to read this

environment variable.

b) For nixos-rebuild you can set

{ nixpkgs.config.allowUnfree = true; }

in configuration.nix to override this.

Alternatively you can configure a predicate to allow specific packages:

{ nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [

"ec2-api-tools"

];

}

c) For nix-env, nix-build, nix-shell or any other Nix command you can add

{ allowUnfree = true; }

to ~/.config/nixpkgs/config.nix.

Using MyNixOS downloads the following Flake file, and

/nix/store/${hash}-source/homeConfigurations/my_flake_name.nix :

{ inputs, ... }@flakeContext:

let

homeModule = { config, lib, pkgs, ... }: {

config = {

home = {

packages = [

ec2-api-tools

... more packages

];

stateVersion = "23.11";

};

nixpkgs = {

config = {

allowUnfree = true;

allowUnfreePredicate = (_: true);

allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [

"ec2-api-tools"

];

};

};

Which results in a configuration path for the allowUnfreePredicate setting: homeModule.config.nixpkgs.config.allowUnfreePredicate . Does that seem correct?

This configuration seems to make no difference, and installing unfree packages always results in the same error.

Exactly what needs to be done to allow unfree packages in each of these distinct scenarios?

NixOS

Nix

Nix with Flakes

Nix with Flakes and Home Manager

(Please edit the list or let me know if it doesn't make sense)

The advice from the following web pages didn't seem to apply, or I couldn't figure out how to apply it:

NixOS Discourse: Allow unfree in flakes

GitHub: nix-community/home-manager: #2942: bug: Flake config cannot use unfree packages despite nixpkgs.config.allowUnfree = true

GitHub: nix-community/home-manager: #2720: modules/default.nix: Add useNixpkgsModule parameter

Abandoned merge request

Published Date: 2023-12-01T12:21:17Z

view this post on Zulip Zapier (Dec 10 2023 at 17:32):

How to override packages in a nix derivation?

Link: https://stackoverflow.com/questions/77635748/how-to-override-packages-in-a-nix-derivation

While developing a nix package, my default.nix looks like this:

let

pkgs = import <nixpkgs> {

config = { ... }

}

in pkgs.path.to.derivation

But when turning that into an actual package, the pkgs comes in as an argument. But adding a config to that doesn't seem to work:

{ pkgs, ... }:

let

pkgs_ = pkgs // { config = { ... } };

in pkgs_.path.to.derivation

How do I add the same config to an already existing package set?

Published Date: 2023-12-10T17:30:37Z

view this post on Zulip Zapier (Dec 11 2023 at 07:11):

How to setup zsh-users/antigen with nix-env (non NixOS)?

Link: https://stackoverflow.com/questions/77637908/how-to-setup-zsh-users-antigen-with-nix-env-non-nixos

I installed antigen with nix-env -iA nixpkgs.antigen . After that, I have to source the antigen.zsh file into .zshrc but how do I get this file path from nix? Note that I am using macOS with nix-env . One way that I found is to get it from .nix-profile/shared/antigen/antigen.zsh but is it the best way to do it; if so, does it have any cons? Also, is there a $(brew --prefix) version for nix?

Published Date: 2023-12-11T06:58:55Z

view this post on Zulip Zapier (Dec 13 2023 at 22:31):

How can I make a shell.nix that runs some code, only using inbuilt derivation function?

Link: https://stackoverflow.com/questions/77656854/how-can-i-make-a-shell-nix-that-runs-some-code-only-using-inbuilt-derivation-fu

I basically want to create my own simple version of mkShell , so now I'm trying to understand how it would even be possible to execute some code before the shell actually pops up. I googled for a bit, and came up with this:

let pkgs = import <nixpkgs> {}; in

derivation {

name = "hello";

shellHook = ''

echo "hello world!"

'';

system = builtins.currentSystem;

builder = "${pkgs.bash}/bin/bash";

args = [ ./setup.sh ];

}

From nix-shell documentation:

If the derivation defines the variable shellHook, it will be run after $stdenv/setup has been sourced. Since this hook is not executed by regular Nix builds, it allows you to perform initialisation specific to nix-shell. For example, the derivation attribute

shellHook =

''

echo "Hello shell"

export SOME_API_TOKEN="$(cat ~/.config/some-app/api-token)"

'';

But that doesn't output anything, although if I replace derivation {} with pkgs.mkShell {} , then it does. How can I make this behaviour work without actually using pkgs.mkShell ?

Published Date: 2023-12-13T22:25:51Z

view this post on Zulip Zapier (Dec 14 2023 at 16:11):

How can I make home-manager use nixpkgs-23.11 in flake system configuration?

Link: https://stackoverflow.com/questions/77661475/how-can-i-make-home-manager-use-nixpkgs-23-11-in-flake-system-configuration

My flake.nix in /etc/nixos directory:

{

description = "A very basic flake";

inputs = {

nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";

home-manager = {

url = "github:nix-community/home-manager";

inputs.nixpkgs.follows = "nixpkgs";

};

};

outputs = { self, nixpkgs, home-manager, ... }@inputs:

let

system = "x86_64-linux";

pkgs = import nixpkgs {

inherit system;

config.allowUnfree = true;

};

in {

nixosConfigurations = rec {

default = nixpkgs.lib.nixosSystem {

specialArgs = { inherit inputs system; };

modules = [ ./configuration.nix home-manager.nixosModules.home-manager ];

};

nixos = default;

};

};

}

When I run it (installing home-manager for the first time), I get this log:

warning: creating lock file '/etc/nixos/flake.lock'

building the system configuration...

trace: warning: monkpatch profile: You are using

Home Manager version 24.05 and

Nixpkgs version 23.11.

Using mismatched versions is likely to cause errors and unexpected

behavior. It is therefore highly recommended to use a release of Home

Manager that corresponds with your chosen release of Nixpkgs.

If you insist then you can disable this warning by adding

home.enableNixpkgsReleaseCheck = false;

to your configuration.

And if I replace nixos-23.11 with nixos-unstable in nixpkgs.url (line 5), then the error disappears. But what if I want to use nixos-23.11 ? What do I do?

Published Date: 2023-12-14T15:58:41Z

view this post on Zulip Zapier (Dec 14 2023 at 19:23):

How can I write a shell.nix for a Python environment that uses a custom PyPi location?

Link: https://stackoverflow.com/questions/77662568/how-can-i-write-a-shell-nix-for-a-python-environment-that-uses-a-custom-pypi-loc

I have a project that includes Python packages from a custom PyPi. How can I write a Nix shell.nix to use those packages, alongside others which are in the standard PyPi?

Published Date: 2023-12-14T19:11:11Z

view this post on Zulip Zapier (Dec 19 2023 at 14:10):

How can I change group of /dev/usb on NixOs?

Link: https://stackoverflow.com/questions/77685716/how-can-i-change-group-of-dev-usb-on-nixos

I can't seem to change the group of /dev/usb on nixos. It remains root no matter what I try. I can change the mode though and that has an effect. Here is my configuration for this.

Configuration.nix:

services.udev.extraRules = ''

SUBSYSTEMS=="usb", MODE="0660", GROUP="plugdev" # Not working

SUBSYSTEM=="usb", MODE="0666" # Tested and has an effect

'';

users.groups.plugdev.members = [ "mcmah309" ];

cat /etc/group shows plugdev is created and my user is assigned.

ls -l /dev is still showing usb is in the root group.

I expect the group of /dev/usb to be plugdev .

Published Date: 2023-12-19T13:58:03Z


Last updated: Nov 21 2024 at 10:18 UTC