What is the configuration I would use to enable my wireless adapter WITHOUT having any X Server/Desktop installed. The install is simply a terminal install. Also I want to specify a static IP address for the machine. If someone could share the nixos configuration to achieve that, it would be appreciated.
This code will do it:
networking = {
interfaces.wlp1s0.ip4 = [ { address = "192.168.0.150"; prefixLength = 24; } ];
defaultGateway = "192.168.0.1";
nameservers = [ "8.8.8.8" ];
wireless = {
enable = true;
interfaces = ["wlp1s0"];
userControlled.enable = true;
userControlled.group = "wheel";
networks = {
"1529-upstairs-2.4" = {
psk = "abc7654321";
};
};
};
hostName = "delldesk";
};
environment.systemPackages = with pkgs; [
dhcpcd wpa_supplicant
];
my wireless device is: wlp1s0.
I have a network called: 1529-upstairs-2.4
The password to that WIFI is: abc7654321
Related
How do I run a docker container declaratively on nixos server ? I am trying to run whoogle on a nix server and I don't wish to manually restart the whoogle container everytime I restart the server.
After bit of guidance from the r/nixos community settled with this.
{ config, pkgs, ... }:
let
host = "mydomain";
in
{
virtualisation = {
podman = {
enable = true;
dockerCompat = true;
};
oci-containers = {
backend = "podman";
containers.whoogle-search = {
image = "benbusby/whoogle-search";
autoStart = true;
ports = [ "8080:5000" ]; #server locahost : docker localhost
};
};
};
services.nginx.virtualHosts = {
"search.${host}" = {
enableACME = true;
forceSSL = true;
locations."/".proxyPass = "http://localhost:8080";
};
};
}
Use --restart always with docker command at initial start
enable docker service to start at boot
And your container will start at boot
I'm trying to setup withHoogle in my default.nix, but I'm getting this error:
developPackage, error: attempt to call something which is not a function but a set(at line 26).
Here is my default.nix code:
let
pkgs = import <nixpkgs> {};
compilerVersion = "ghc865";
compiler = pkgs.haskell.packages."${compilerVersion}";
in
compiler.developPackage
{
# returnShellEnv = false;
root = ./.;
# source-overrides = {};
modifier = drv:
let pkg = pkgs.haskell.lib.addBuildTools drv (with pkgs.haskellPackages;
[
cabal-install
cabal2nix
ghcid
control
text
brick
]);
in pkg // {
env = (pkg.env { withHoogle = true; }).overrideAttrs (old: {
shellHook =
''
export PS1='\n\[\033[1;32m\][\[\e]0;nix-shell: \W\a\]nix-shell:/\W]\$ \[\033[0m\]'
'';
});
};
}
I had a similar error message when trying to nix-build a seemingly correct derivation (default.nix).
Eventually I found out using the --show-trace parameter to nix-build, that the error lie in an overlay I had in my user's ~/.config/nixpkgs/overlays directory lying around.
HTH
I'm trying to override the stable nvidia package from my configuration.nix from nvidia driver 410 to 390, however, it doesn't seem to work using the override config below.
I am enabling the driver using the services.xserver.videoDrivers = [ "nvidia" ] option and am subscribed to the unstable channel.
configuration.nix:
nixpkgs.config = {
allowUnfree = true;
packageOverrides = super: let self = super.pkgs; in
{
linuxPackages = super.linuxPackages_latest.extend (self: super: {
nvidiaPackages = super.nvidiaPackages // {
stable = super.nvidiaPackages.stable_390;
};
});
};
};
I also tried changing from super to self in the following line:
stable = super.nvidiaPackages.stable_390;
But this doesn't have any affect either.
From what I've been able to figure out, you'll need to override both the linux packages and nvidia_x11 in the core package set. If I didn't, I encountered a silent fallback to the default nvidia drivers.
The following is an example that is less fine-grained than your attempt. My thinking was that there was a possibility of a mismatch between kernel dependencies used to build and loaded at runtime, so I instead swapped out the entire linuxPackage set.
At present (01/10/2019), nvidia 410.7x is broken (see Issue 53708). So I've pinned my configuration to the last commit with nvidia 410.6x. For more information on pinning nixpkgs, see the wiki page. You can still pin against master and add an unstable namespace to your package set without interfering with the kernel.
{ config, pkgs, nixpkgs, ... }:
let
# get the last working revision with nvidia 410.x
nixos-unstable-pinned = import (builtins.fetchTarball {
name = "nixos-unstable_nvidia-410-66_2018-11-03";
url = https://github.com/nixos/nixpkgs/archive/bf084e0ed7a625b50b1b0f42b98358dfa23326ee.tar.gz;
sha256 = "0w05cw9s2pa07vqy21ack7g7983ig67lhwkdn24bzah3z49c2d8k";
}) { };
# We'll use this twice
pinnedKernelPackages = nixos-unstable-pinned.linuxPackages_latest;
in
{
# allow nvidia drivers to be loaded
nixpkgs.config.allowUnfree = true;
nixpkgs.config.packageOverrides = pkgs: {
# swap out all of the linux packages
linuxPackages_latest = pinnedKernelPackages;
# make sure x11 will use the correct package as well
nvidia_x11 = nixos-unstable-pinned.nvidia_x11;
};
# line up your kernel packages at boot
boot.kernelPackages = pinnedKernelPackages;
}
Hope this helps!
using nixops one can easily configure services like:
{
network.description = "Web server";
webserver = { config, pkgs, ... }:
{
services.mysql = {
enable = true;
package = pkgs.mysql51;
};
but i want to extend services. for example by using override as done for pkgs below:
let
myfoo = callPackage ...
in
pkgs = pkgs.override {
overrides = self: super: {
myfoo-core = myfoo;
};
}
question
how to do that for services?
Adding a service requires that you first write a service definition for your service. That is, a nix file that declares the options of your service and provides an implementation.
Let's say our service is called foo, then we write a service definition for it an save it as the file foo.nix:
{ config, lib, pkgs, ... }:
with lib; # use the functions from lib, such as mkIf
let
# the values of the options set for the service by the user of the service
foocfg = config.services.foo;
in {
##### interface. here we define the options that users of our service can specify
options = {
# the options for our service will be located under services.foo
services.foo = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable foo.
'';
};
barOption = {
type = types.str;
default = "qux";
description = ''
The bar option for foo.
'';
};
};
};
##### implementation
config = mkIf foocfg.enable { # only apply the following settings if enabled
# here all options that can be specified in configuration.nix may be used
# configure systemd services
# add system users
# write config files, just as an example here:
environment.etc."foo-bar" = {
text = foocfg.bar; # we can use values of options for this service here
};
};
For example, for Hydra, this file can be found here: https://github.com/NixOS/hydra/blob/dd32033657fc7d6a755c2feae1714148ee43fc7e/hydra-module.nix.
After having written the service definition, we can use it our main configuration like this:
{
network.description = "Web server";
webserver = { config, pkgs, ... }: {
imports = [ ./foo.nix ]; # import our service
services.mysql = {
enable = true;
package = pkgs.mysql51;
};
services.foo = {
enable = true;
bar = "hello nixos modules!";
};
};
}
Disclaimer: there might be some typos in this, I have not tested it.
according to aszlig, we can do this:
configuration.nix
{ config, lib, ... }:
{
disabledModules = [ "services/monitoring/nagios.nix" ];
options.services.nagios.enable = lib.mkOption {
# Make sure that this option type conflicts with the one in
# the original NixOS module for illustration purposes.
type = lib.types.str;
default = "of course";
description = "Really enable nagios?";
};
config = lib.mkIf (config.services.nagios.enable == "of course") {
systemd.services.nagios = {
description = "my own shiny nagios service...";
};
};
}
evaluate it
$ nix-instantiate --eval '<nixpkgs/nixos>' --arg configuration ./test-disable.nix -A config.systemd.services.nagios.description
"my own shiny nagios service..."

versus without disabledModules:
$ nix-instantiate --eval '<nixpkgs/nixos>' --arg configuration ./test-disable.nix -A config.systemd.services.nagios.description
error: The option `services.nagios.enable' in `/home/aszlig/test-disable.nix' is already declared in `/nix/var/nix/profiles/per-user/root/channels/vuizvui/nixpkgs/nixos/modules/services/monitoring/nagios.nix'.
(use '--show-trace' to show detailed location information)
I'm not referring to
127.0.0.1
But rather the one that other computers would use to access the machine e.g.
192.168.1.6
http://nodejs.org/api/os.html#os_os_networkinterfaces
var os = require('os');
var interfaces = os.networkInterfaces();
var addresses = [];
for (var k in interfaces) {
for (var k2 in interfaces[k]) {
var address = interfaces[k][k2];
if (address.family === 'IPv4' && !address.internal) {
addresses.push(address.address);
}
}
}
console.log(addresses);
https://github.com/indutny/node-ip
var ip = require("ip");
console.dir ( ip.address() );
$ npm install --save quick-local-ip
follwed by
var myip = require('quick-local-ip');
//getting ip4 network address of local system
myip.getLocalIP4();
//getting ip6 network address of local system
myip.getLocalIP6();
My version which was needed for a compact and single file script, hope to be useful for others:
var ifs = require('os').networkInterfaces();
var result = Object.keys(ifs)
.map(x => [x, ifs[x].filter(x => x.family === 'IPv4')[0]])
.filter(x => x[1])
.map(x => x[1].address);
Or to answer the original question:
var ifs = require('os').networkInterfaces();
var result = Object.keys(ifs)
.map(x => ifs[x].filter(x => x.family === 'IPv4' && !x.internal)[0])
.filter(x => x)[0].address;
https://github.com/dominictarr/my-local-ip
$ npm install -g my-local-ip
$ my-local-ip
or
$ npm install --save my-local-ip
$ node
> console.log(require('my-local-ip')())
A very small module that does just this.
savage one-liner incoming
based on accepted answer, this one will build an array of objects with conditional entries depending on address properties
[{name: {interface name}, ip: {ip address}}, ...]
const ips = Object.entries(require("os").networkInterfaces()).reduce((acc, iface) => [...acc, ...(iface[1].reduce((acc, address) => acc || (address.family === "IPv4" && !address.internal), false) ? [{name: iface[0], ip: iface[1].filter(address => address.family === "IPv4" && !address.internal).map(address => address.address)[0]}] : [])], []);
console.log(ips);
Explained :
const ips = Object.entries(require("os").networkInterfaces()) // fetch network interfaces
.reduce((acc, iface) => [ // reduce to build output object
...acc, // accumulator
...(
iface[1].reduce((acc, address) => acc || (address.family === "IPv4" && !address.internal), false) ? // conditional entry
[ // validate, insert it in output
{ // create {name, ip} object
name: iface[0], // interface name
ip: iface[1] // interface IP
.filter(address => address.family === "IPv4" && !address.internal) // check is IPv4 && not internal
.map(address => address.address)[0] // get IP
}
]
:
[] // ignore interface && ip
)
], []);
Output example :
Array(4) [Object, Object, Object, Object]
length:4
__proto__:Array(0) [, …]
0:Object {name: "vEthernet (WSL)", ip: "172.31.xxx.x"}
1:Object {name: "Ethernet", ip: "10.0.x.xx"}
2:Object {name: "VMware Network Adapter VMnet1", ip: "192.168.xxx.x"}
3:Object {name: "VMware Network Adapter VMnet8", ip: "192.168.xx.x"}
Ever since Node version 0.9.6 there is a simple way to get the server's IP address based on each request. This could be important if your machine has multiple IP addresses or even if you are doing something on localhost.
req.socket.localAddress will return the address of the machine node is running on based on the current connection.
If you have a public IP address of 1.2.3.4 and someone hits your node server from the outside then the value for req.socket.localAddress will be "1.2.3.4".
If you hit the same server from localhost then the address will be "127.0.0.1"
If your server has multiple public addresses then the value of req.socket.localAddress will be the correct address of the socket connection.
Modified a bit Ebrahim's answer with some es6 and module syntax, for leaner code:
import { networkInterfaces } from "os";
const netInterfaces = networkInterfaces();
const [{ address }] = Object.values(netInterfaces).flatMap((netInterface) =>
netInterface.filter((prop) => prop.family === "IPv4" && !prop.internal)
);
console.log(address) // -> '192.168...'