-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage with Nix Flakes #153
Comments
Mach-nix does currently not propose a module. Also I'm not sure what would be the benefit. Mach-nix is just a package. There is nothing that needs to be integrated with the system. |
Ah; could you show me how to use it in a flake for the NixOS Configuration, then? I'm a bit confused on how to pass it to the config; do I just add it to the list of arguments I pass to |
A nixos configuration with the mach-nix cmdline tool inside the system environment could look like this: { pkgs, ... }:
let
mach-nix = (import (builtins.fetchGit {
url = "https://github.com/DavHau/mach-nix.git";
ref = "refs/heads/master" ;
rev ="70b6328ca28b54a135a19d8d7267a3d1639c3b3d";
})).mach-nix;
in
{
environment.systemPackages = [
mach-nix
];
} |
But what if I were to include it in the inputs set in |
Maybe it helps to play around with it in
|
Yeah, I'm still kinda' stuck on where to put |
Sorry, I was busy finishing the 3.0.0 release. Were you able to solve your problem in the meantime? |
No problem! I think the problem was actually solved by the PR I sent; now I'm wondering how to include mach-nix in the list of modules sent to my configuration file. I can't seem to find that anywhere in the NixOS / Nix Flakes documentation! I really need to help with that, actually... |
Not sure what you actually try to achieve, but wouldn't it be the easiest way to just import a mach-nix expression directly into your config? |
I don't want to keep manually updating the module rev and hash, though... It's why I use the master branch everywhere; I wanted to copy a rolling-release model. Flakes seemed to finally be the easiest way to do it. |
Actually, I figured I'll just pass mach-nix directly to my overlays as an argument, so problem solved! More or less... I eagerly await your opinion on the matter! |
Turns out I get stuck on unpacking channels...
building the system configuration...
warning: updating lock file '/etc/nixos/flake.lock':
* Updated 'mach-nix': 'path:/etc/nixos/extras/mach-nix?narHash=sha256-Omm0wC5aBAKag7Ev4TupSmTNAYDvZgx9BwoNcyawhMA=' -> 'github:davhau/mach-nix/8db91624a6413aefe142d126e749b38b725087fd'
error: --- EvalError --- nix
at: (12:19) in file: /nix/store/ikrq860lflwqcbw0jiick0pfd25y05db-source/shared/global/xonsh.nix
11| # build a mach-nix python env
12| machnixPy = mach-nix.mkPython {
| ^
13| packagesExtra = [
attribute 'mkPython' missing
---- show-trace ----
trace: while evaluating the attribute 'xonsh'
at: (91:37) in file: /nix/store/ikrq860lflwqcbw0jiick0pfd25y05db-source/shared/global/xonsh.nix
90| # make a final overlay with the modified xonsh
91| finalOverlay = self: super: { xonsh = xonsh_with_pkgs; };
| ^
92| in
trace: while evaluating anonymous lambda
at: (1:1) in file: /nix/store/ikrq860lflwqcbw0jiick0pfd25y05db-source/shared/global/xonsh.nix
1| {
| ^
2| pkgs,
trace: from call site
at: (31:33) in file: /nix/store/ikrq860lflwqcbw0jiick0pfd25y05db-source/shared/global/_nixpkgs.nix
30| (self: super: { qtile = import ./qtile.nix base.mach-nix; })
31| (self: super: { xonsh = import ./xonsh.nix (base.mach-nix // { inherit lib; }); })
| ^
32| mozilla
trace: while evaluating the attribute 'xonsh'
at: (31:25) in file: /nix/store/ikrq860lflwqcbw0jiick0pfd25y05db-source/shared/global/_nixpkgs.nix
30| (self: super: { qtile = import ./qtile.nix base.mach-nix; })
31| (self: super: { xonsh = import ./xonsh.nix (base.mach-nix // { inherit lib; }); })
| ^
32| mozilla
trace: while evaluating the attribute 'value.content'
at: (654:14) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/modules.nix
653| { _type = "override";
654| inherit priority content;
| ^
655| };
trace: while evaluating the attribute 'value._type'
at: (594:73) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/modules.nix
593| highestPrio = foldl' (prio: def: min (getPrio def) prio) 9999 defs;
594| strip = def: if def.value._type or "" == "override" then def // { value = def.value.content; } else def;
| ^
595| in {
trace: while evaluating anonymous lambda
at: (493:19) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/modules.nix
492| # Avoid sorting if we don't have to.
493| if any (def: def.value._type or "" == "order") defs''.values
| ^
494| then sortProperties defs''.values
trace: from call site
at: (493:14) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/modules.nix
492| # Avoid sorting if we don't have to.
493| if any (def: def.value._type or "" == "order") defs''.values
| ^
494| then sortProperties defs''.values
trace: while evaluating the attribute 'values'
at: (497:9) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/modules.nix
496| in {
497| values = defs''';
| ^
498| inherit (defs'') highestPrio;
trace: while evaluating the attribute 'mergedValue'
at: (503:5) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/modules.nix
502| # Type-check the remaining definitions, and merge them. Or throw if no definitions.
503| mergedValue =
| ^
504| if isDefined then
trace: while evaluating the option `users.users.root.shell':
trace: while evaluating the attribute 'value'
at: (471:9) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/modules.nix
470| in warnDeprecation opt //
471| { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
| ^
472| inherit (res.defsFinal') highestPrio;
trace: while evaluating anonymous lambda
at: (98:72) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/modules.nix
97| # For definitions that have an associated option
98| declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
| ^
99|
trace: from call site
at: (279:20) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/attrsets.nix
278| then recurse (path ++ [name]) value
279| else f (path ++ [name]) value;
| ^
280| in mapAttrs g set;
trace: while evaluating 'g'
at: (276:19) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/attrsets.nix
275| g =
276| name: value:
| ^
277| if isAttrs value && cond value
trace: from call site
trace: while evaluating the attribute 'shell'
trace: while evaluating 'isDerivation'
at: (305:18) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/attrsets.nix
304| */
305| isDerivation = x: isAttrs x && x ? type && x.type == "derivation";
| ^
306|
trace: from call site
at: (280:18) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/types.nix
279| name = "package";
280| check = x: isDerivation x || isStorePath x;
| ^
281| merge = loc: defs:
trace: while evaluating 'check'
at: (280:15) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/types.nix
279| name = "package";
280| check = x: isDerivation x || isStorePath x;
| ^
281| merge = loc: defs:
trace: from call site
at: (287:19) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/types.nix
286| shellPackage = package // {
287| check = x: (package.check x) && (hasAttr "shellPath" x);
| ^
288| };
trace: while evaluating 'check'
at: (287:15) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/types.nix
286| shellPackage = package // {
287| check = x: (package.check x) && (hasAttr "shellPath" x);
| ^
288| };
trace: from call site
at: (28:8) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/nixos/lib/utils.nix
27| toShellPath = shell:
28| if types.shellPackage.check shell then
| ^
29| "/run/current-system/sw${shell.shellPath}"
trace: while evaluating 'toShellPath'
at: (27:17) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/nixos/lib/utils.nix
26| # Returns a system path for a given shell package
27| toShellPath = shell:
| ^
28| if types.shellPackage.check shell then
trace: from call site
at: (399:17) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/nixos/modules/config/users-groups.nix
398| initialPassword initialHashedPassword;
399| shell = utils.toShellPath u.shell;
| ^
400| }) cfg.users;
trace: while evaluating the attribute 'text' of the derivation 'users-groups.json'
at: (7:7) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/pkgs/build-support/trivial-builders.nix
6| stdenv.mkDerivation ({
7| name = lib.strings.sanitizeDerivationName name;
| ^
8| inherit buildCommand;
trace: while evaluating the attribute 'text'
at: (77:38) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/strings-with-deps.nix
76|
77| stringAfter = deps: text: { inherit text deps; };
| ^
78|
trace: while evaluating the attribute 'text'
at: (9:5) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/nixos/modules/system/activation/activation-script.nix
8| addAttributeName = mapAttrs (a: v: v // {
9| text = ''
| ^
10| #### Activation script snippet ${a}:
trace: while evaluating 'id'
at: (14:5) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/trivial.nix
13| # The value to return
14| x: x;
| ^
15|
trace: from call site
trace: while evaluating 'textClosureMap'
at: (70:35) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/lib/strings-with-deps.nix
69|
70| textClosureMap = f: predefined: names:
| ^
71| concatStringsSep "\n" (map f (textClosureList predefined names));
trace: from call site
at: (89:18) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/nixos/modules/system/activation/activation-script.nix
88| withHeadlines = addAttributeName set';
89| in textClosureMap id (withHeadlines) (attrNames withHeadlines)
| ^
90| }
trace: while evaluating the attribute 'system.activationScripts.script'
at: (68:9) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/nixos/modules/system/activation/activation-script.nix
67| apply = set: {
68| script =
| ^
69| ''
trace: while evaluating the attribute 'activationScript' of the derivation 'nixos-system-siluam-21.03.20201011.9e51c25'
at: (95:5) in file: /nix/store/ih6jlh451lf0whq63pxgcb2wy8yajsxm-source/nixos/modules/system/activation/top-level.nix
94| baseSystem = pkgs.stdenvNoCC.mkDerivation {
95| name = "nixos-system-${config.system.name}-${config.system.nixos.label}";
| ^
96| preferLocalBuild = true; This is my {
description = "shadowrylander";
inputs = rec {
home-manager = {
url = "github:nix-community/home-manager/master";
# https://github.com/nix-community/home-manager/blob/master/flake.nix#L4
# HM takes 'nixpkgs' as input
inputs.nixpkgs.follows = "nixpkgs";
};
mach-nix = {
url = "github:davhau/mach-nix/master";
# url = "/home/shadowrylander/mach-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
impermanence = {
url = "github:nix-community/impermanence";
flake = false;
};
flake-utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
nur = {
url = github:nix-community/NUR;
inputs.nixpkgs.follows = "nixpkgs";
};
r2003.url = "github:NixOS/nixpkgs/nixos-20.03";
r2009.url = "github:NixOS/nixpkgs/nixos-20.09";
unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
small.url = "github:NixOS/nixpkgs/nixos-unstable-small";
master.url = "github:NixOS/nixpkgs/master";
nixpkgs.follows = "master";
nix = { url = "github:NixOS/nix/master"; };
};
outputs = inputs@{ self, nixpkgs, flake-utils, ... }: let
stdenvs = (import (./. + "${global}/stdenvs.nix") {
inherit nixpkgs;
});
systems = {
imd = let _imd = stdenvs.imd; in {
x64 = _imd.x64.system;
x86 = _imd.x86.system;
};
arm = let _arm = stdenvs.arm; in {
x64 = _arm.x64.system;
x86 = _arm.x86.system;
};
};
system = systems.imd.x64;
r2003 = final: prev: { r2003 = inputs.r2003.legacyPackages.${system}; };
r2009 = final: prev: { r2009 = inputs.r2009.legacyPackages.${system}; };
unstable = final: prev: { unstable = inputs.unstable.legacyPackages.${system}; };
small = final: prev: { small = inputs.small.legacyPackages.${system}; };
global = "/shared/global";
_pkgs = (import nixpkgs {});
__pkgs = _: (import nixpkgs _);
lib = _pkgs.lib;
pkgs = __pkgs (import (./. + "${global}/_nixpkgs.nix") {
inherit lib;
###############################################
mach-nix = inputs.mach-nix.packages.${system}.mach-nix;
###############################################
stdenv = {
inherit system;
package = _pkgs.gcc10.stdenv;
};
pkgs = _pkgs;
});
in {
overlays = [ r2003 r2009 unstable small inputs.nur.overlay ];
nixosConfigurations = let
base = {
global = {
modules = with inputs; [
home-manager.nixosModules.home-manager
# impermanence
];
};
create = { inherit system pkgs; };
};
create = { hostname, system, pkgs }: let
config = ./. + "/configs/${hostname}.nix";
in nixpkgs.lib.nixosSystem {
inherit system pkgs;
modules = base.global.modules ++ [ (import config) ];
};
in {
siluam = create (base.create // { hostname = "siluam"; });
};
};
} This is my {
stdenv,
pkgs,
lib,
# mach-nix ? (import (builtins.fetchGit {
# url = "https://github.com/DavHau/mach-nix/";
# ref = "master";
# }) { inherit pkgs; python = "python38"; }),
mach-nix,
...
}:
let
mozilla = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
base = {
mach-nix = { inherit pkgs mach-nix; };
};
in {
config = {
allowUnfree = true;
allowBroken = true;
allowUnsupportedSystem = true;
# preBuild = ''
# makeFlagsArray+=(CFLAGS="-w")
# buildFlagsArray+=(CC=cc)
# '';
buildEnv.override = { inherit stdenv; };
};
overlays = [
(self: super: { qtile = import ./qtile.nix base.mach-nix; })
(self: super: { xonsh = import ./xonsh.nix (base.mach-nix // { inherit lib; }); })
mozilla
];
} And this is {
pkgs,
lib,
mach-nix,
...
}:
let
xonshOverlay = {pkgs, lib, ...}:
let
# build a mach-nix python env
machnixPy = mach-nix.mkPython {
packagesExtra = [
# "https://github.com/psf/requests/tarball/v2.22.0"
# "https://gitlab.com/picotech/nanotech/nanite/-/archive/master/nanite-master.tar.gz"
(mach-nix.buildPythonPackage {
src = builtins.fetchGit{
url = "https://gitlab.com/picotech/nanotech/nanite";
ref = "master";
};
})
"https://files.pythonhosted.org/packages/bc/ab/c49f97516f78c2b0cacb4f45873abc4ca9872942a9c4c19ded8052c8edda/python-wifi-0.6.1.tar.bz2"
];
requirements = ''
# add requirements here
# jedi
borgmatic
dephell
ply
prompt_toolkit
pygments
pipx
yubico-client
# add xontribs here
# xonsh-direnv
# xonsh-docker-tabcomplete
# xonsh-vox-tabcomplete
# xontrib-prompt-bar
# xontrib-ssh-agent
xonsh-autoxsh
xontrib-autojump
xontrib-fzf-widgets
xontrib-kitty
xontrib-pipeliner
xontrib-powerline2
xontrib-prompt-vi-mode
xontrib-readable-traceback
xontrib-schedule
xontrib-z
'';
};
# get mach-nix modified nixpkgs
newPkgs = machnixPy.nixpkgs;
### modify the xonsh package
pythonPackages = newPkgs.python38.pkgs;
# switch xonsh to python 3.8
xonsh_py_38 = newPkgs.xonsh.override {
python3Packages = newPkgs.python38Packages;
};
# add extra packages to PYTHONPATH of xonsh
xonsh_with_pkgs = xonsh_py_38.overrideAttrs (oa: rec {
version = "0.9.23";
# fetch from github because the pypi package ships incomplete tests
src = pkgs.fetchFromGitHub {
owner = "xonsh";
repo = "xonsh";
rev = version;
sha256 = "1by13ryq9ldc9wln3fk5mm6zvjp4aim57ikw49v0dfmz8irnpglp";
};
pythonPath =
(if (builtins.hasAttr "pythonPath" oa) then oa.pythonPath else [])
++ machnixPy.selectPkgs pythonPackages
++ (with pythonPackages; [
ply
prompt_toolkit
pygments
pipx
yubico-client
nixpkgs
]);
});
# make a final overlay with the modified xonsh
finalOverlay = self: super: { xonsh = xonsh_with_pkgs; };
in
finalOverlay;
in
let
pkgs = import (builtins.fetchGit {
url = "https://github.com/NixOS/nixpkgs/";
ref = "master";
}) { config = {}; overlays = [];};
overlay = xonshOverlay { inherit pkgs lib; };
in
(import pkgs.path { overlays = [ overlay ]; }).xonsh Interestingly, this does not seem to be affecting my {
pkgs,
mach-nix,
...
}:
let
qtileOverlay = {pkgs, ...}:
let
# build a mach-nix python env
machnixPy = mach-nix.mkPython {
packagesExtra = [
# "https://github.com/psf/requests/tarball/v2.22.0"
# "https://gitlab.com/picotech/nanotech/nanite/-/archive/master/nanite-master.tar.gz"
(mach-nix.buildPythonPackage {
src = builtins.fetchGit {
url = "https://gitlab.com/picotech/nanotech/nanite";
ref = "master";
};
})
"https://files.pythonhosted.org/packages/bc/ab/c49f97516f78c2b0cacb4f45873abc4ca9872942a9c4c19ded8052c8edda/python-wifi-0.6.1.tar.bz2"
];
requirements = ''
iwlib
'';
_.iwlib.buildInputs.add = [ pkgs.wirelesstools ];
};
# get mach-nix modified nixpkgs
newPkgs = machnixPy.nixpkgs;
### modify the qtile package
pythonPackages = newPkgs.python38.pkgs;
# switch qtile to python 3.8
qtile_py_38 = newPkgs.qtile.override {
python37Packages = newPkgs.python38Packages;
};
# add extra packages to PYTHONPATH of qtile
qtile_with_pkgs = qtile_py_38.overrideAttrs (oa: {
pythonPath =
oa.pythonPath
++ machnixPy.selectPkgs pythonPackages
++ (with pythonPackages; [
# From https://github.com/NixOS/nixpkgs/issues/45039
dateutil
dbus-python
keyring
mpd2
psutil
pyxdg
nixpkgs
]);
});
# make a final overlay with the modified qtile
finalOverlay = self: super: { qtile = qtile_with_pkgs; };
in
finalOverlay;
in
let
pkgs = import (builtins.fetchGit {
url = "https://github.com/NixOS/nixpkgs/";
ref = "master";
}) { config = {}; overlays = [];};
overlay = qtileOverlay { inherit pkgs; };
in
(import pkgs.path { overlays = [ overlay ]; }).qtile |
Pinging @DavHau! Sorry, I'm really excited for this! 😅😻 |
I think the problem is that the mach-nix flake doesn't expose the |
How would I do that, though? If I'm passing |
Hi! I've run into this too. I was thinking about exposing To keep the graph strongly connected, I also raised the question in https://discourse.nixos.org/t/flake-nix-interface-nix-show-fails-with-aarch64-linux-required-to-build/9561 but this issue seems much more appropriate place for discussion Thanks! P.S. I'm still unsure if |
The way I'm thinking of doing it is either by passing my module all the |
@newkozlukov Thanks for looking into this! Feel free to just open a WIP PR with your changes and we can try to fix it from there. |
It seems as though none of my changes work; any help on them would be greatly appreciated! |
@shadowrylander Tbh, I'm pretty occupied lately and made no progress since last comment |
Aw! 😹 Ah well; whenever you get around to it, if you do! |
Flake inputs actually have some special handling that causes
However, functions like |
If I may ask something slightly off-topic: if anyone here has experience extending the default Afterwards, I can continue helping debug the |
I can confirm that @nat543207's method works. |
I suppose I'll close this then! |
I merged some commits of @nat543207 and @newkozlukov and added the library functions to flakes.nix. |
Hey, I've tried the approach @nat543207 suggested, but
My
I'm on macOS. Any ideas? |
@ae-mo You might want to check on that error; it seems to be screaming. 😹 |
It seems to be a problem related to the |
@ae-mo you could try settings the provider for scs to nixpkgs. Or try with the 'conda-beta' brach of mach-nix which can take packages from conda. |
@DavHau I switched to Linux in the end and it worked, after fiddling with providers. Thanks! |
Run into this again and it wasn't immediately obvious to me how to use this, so posting the snippet here (as probably the easiest googlable place). TLDR is Note that
Snippet that currently worksStep 0:
Step 1:
Step 2: |
@SomeoneSerge Thanks for noticing this. |
@DavHau Hmm, if Does anything in |
Hello!
I was just wondering how I would go about using this with Nix Flakes, as in what module I would have to import in
nixpkgs.lib.nixosSystem.modules
? Wouldmach-nix.nixosModules.mach-nix
work?Thank you kindly for the help!
The text was updated successfully, but these errors were encountered: