From 2dbccc394a4964a2a3badd192184b6d35dd63336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Thu, 23 Mar 2023 12:31:51 +0100 Subject: Rework how I pass packages to the NixOS --- devShells/apo.nix | 10 ++--- devShells/c.nix | 87 ++++++++++++++++++------------------ devShells/default.nix | 16 ++----- devShells/nuttx.nix | 15 +++---- devShells/python.nix | 109 ++++++++++++++++++++++------------------------ devShells/qt.nix | 35 +++++++-------- flake.lock | 80 +++++++++++++++++----------------- flake.nix | 25 +++-------- nixos/configurations.nix | 18 +++++--- nixos/modules/desktop.nix | 1 - nixos/modules/generic.nix | 10 +++-- pkgs/default.nix | 18 ++------ tools/common.sh | 4 +- 13 files changed, 195 insertions(+), 233 deletions(-) diff --git a/devShells/apo.nix b/devShells/apo.nix index c1049a8..a840670 100644 --- a/devShells/apo.nix +++ b/devShells/apo.nix @@ -1,12 +1,10 @@ { - system, - nixpkgs, + pkgs, default, c, }: let - pkgs = nixpkgs.legacyPackages.${system}; - riscvPkgs = import nixpkgs.outPath { - localSystem = system; + riscvPkgs = import pkgs.path { + localSystem = pkgs.buildPlatform.system; crossSystem = { config = "riscv32-none-elf"; libc = "newlib-nano"; @@ -23,5 +21,5 @@ in riscvPkgs.buildPackages.gcc ]; inputsFrom = [default c]; - meta.platforms = nixpkgs.lib.platforms.linux; + meta.platforms = pkgs.lib.platforms.linux; } diff --git a/devShells/c.nix b/devShells/c.nix index 7aba33f..e20fcc8 100644 --- a/devShells/c.nix +++ b/devShells/c.nix @@ -1,52 +1,49 @@ { - system, - nixpkgs, + pkgs, default, -}: let - pkgs = nixpkgs.legacyPackages.${system}; -in - pkgs.mkShell { - packages = with pkgs; [ - clang-tools_14 - ctags - gcc - gdb - pkg-config +}: +pkgs.mkShell { + packages = with pkgs; [ + clang-tools_14 + ctags + gcc + gdb + pkg-config - gnumake - bear - meson - ninja - cmake + gnumake + bear + meson + ninja + cmake - valgrind - lcov - massif-visualizer - cppcheck - flawfinder + valgrind + lcov + massif-visualizer + cppcheck + flawfinder - check - curl - ncurses - flex - bison - gperf - gobject-introspection - gtk3 - gtk4 + check + curl + ncurses + flex + bison + gperf + gobject-introspection + gtk3 + gtk4 - # Various libraries - openssl.dev - zlib.dev - curl.dev - libconfig - czmq - libevent.dev + # Various libraries + openssl.dev + zlib.dev + curl.dev + libconfig + czmq + libevent.dev - # LVGL - SDL2 - libffi.dev - ]; - inputsFrom = with pkgs; [default]; - meta.platforms = nixpkgs.lib.platforms.linux; - } + # LVGL + SDL2 + libffi.dev + ]; + inputsFrom = with pkgs; [default]; + meta.platforms = pkgs.lib.platforms.linux; +} diff --git a/devShells/default.nix b/devShells/default.nix index b0a1728..998a39b 100644 --- a/devShells/default.nix +++ b/devShells/default.nix @@ -1,17 +1,9 @@ -{ - nixpkgs, - shellrc, - system, -}: let - callDevelop = nixpkgs.lib.callPackageWith ({ - inherit system; - inherit nixpkgs; - } - // shells); +pkgs: let + callDevelop = pkgs.lib.callPackageWith (shells // {inherit pkgs;}); shells = { - default = nixpkgs.legacyPackages.${system}.mkShell { - inputsFrom = [shellrc.packages.${system}.default]; + default = pkgs.mkShell { + packages = []; }; armv6 = callDevelop ./nuttx.nix {arch = "armv6s-m";}; diff --git a/devShells/nuttx.nix b/devShells/nuttx.nix index 78dd9c0..33f5761 100644 --- a/devShells/nuttx.nix +++ b/devShells/nuttx.nix @@ -1,15 +1,14 @@ { - system, - nixpkgs, + pkgs, default, c, arch, fpu ? null, }: with builtins; -with nixpkgs.lib; let - pkgs = import nixpkgs.outPath { - localSystem = system; +with pkgs.lib; let + pkgsCross = import pkgs.path { + localSystem = pkgs.buildPlatform.system; crossSystem = { config = if (hasPrefix "armv" arch) @@ -24,8 +23,8 @@ with nixpkgs.lib; let }; }; in - pkgs.buildPackages.mkShell { - packages = with pkgs.buildPackages; + pkgsCross.buildPackages.mkShell { + packages = with pkgsCross.buildPackages; [ kconfig-frontends genromfs @@ -38,5 +37,5 @@ in esptool ]); inputsFrom = [default c]; - meta.platforms = nixpkgs.lib.platforms.linux; + meta.platforms = pkgsCross.lib.platforms.linux; } diff --git a/devShells/python.nix b/devShells/python.nix index 570840d..d0a40b5 100644 --- a/devShells/python.nix +++ b/devShells/python.nix @@ -1,58 +1,55 @@ { - system, - nixpkgs, + pkgs, default, -}: let - pkgs = nixpkgs.legacyPackages.${system}; -in - pkgs.mkShell { - packages = with pkgs; [ - (python3.withPackages (pypkgs: - with pypkgs; [ - ipython - - pytest - pytest-html - pytest-tap - coverage - python-lsp-black - pylint - pydocstyle - mypy - - pygraphviz - matplotlib - - python-gitlab - PyGithub - - schema - jinja2 - ruamel-yaml - msgpack - urllib3 - - influxdb-client - psycopg - paho-mqtt - - humanize - rich - - pygobject3 - - pyserial - pylibftdi - pylxd - selenium - ])) - geckodriver - chromedriver - - gobject-introspection - gtk3 - gtk4 - ]; - inputsFrom = with pkgs; [default]; - meta.platforms = nixpkgs.lib.platforms.linux; - } +}: +pkgs.mkShell { + packages = with pkgs; [ + (python3.withPackages (pypkgs: + with pypkgs; [ + ipython + + pytest + pytest-html + pytest-tap + coverage + python-lsp-black + pylint + pydocstyle + mypy + + pygraphviz + matplotlib + + python-gitlab + PyGithub + + schema + jinja2 + ruamel-yaml + msgpack + urllib3 + + influxdb-client + psycopg + paho-mqtt + + humanize + rich + + pygobject3 + + pyserial + pylibftdi + pylxd + selenium + ])) + geckodriver + chromedriver + + gobject-introspection + gtk3 + gtk4 + ]; + inputsFrom = with pkgs; [default]; + meta.platforms = pkgs.lib.platforms.linux; +} diff --git a/devShells/qt.nix b/devShells/qt.nix index eb9d3e9..2070009 100644 --- a/devShells/qt.nix +++ b/devShells/qt.nix @@ -1,22 +1,19 @@ { - system, - nixpkgs, + pkgs, default, c, -}: let - pkgs = nixpkgs.legacyPackages.${system}; -in - pkgs.mkShell { - packages = with pkgs; - with libsForQt5; [ - qtbase - qttranslations - qtserialport - qtwebsockets - doctest - qtcharts - qtwayland - ]; - inputsFrom = with pkgs; [default c]; - meta.platforms = ["x86_64-linux"]; - } +}: +pkgs.mkShell { + packages = with pkgs; + with libsForQt5; [ + qtbase + qttranslations + qtserialport + qtwebsockets + doctest + qtcharts + qtwayland + ]; + inputsFrom = with pkgs; [default c]; + meta.platforms = pkgs.lib.platforms.linux; +} diff --git a/flake.lock b/flake.lock index 9dfd6b4..e30512d 100644 --- a/flake.lock +++ b/flake.lock @@ -18,11 +18,11 @@ }, "flake-utils": { "locked": { - "lastModified": 1676283394, - "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", "owner": "numtide", "repo": "flake-utils", - "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", "type": "github" }, "original": { @@ -32,11 +32,11 @@ }, "flake-utils_2": { "locked": { - "lastModified": 1676283394, - "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", "owner": "numtide", "repo": "flake-utils", - "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", "type": "github" }, "original": { @@ -46,11 +46,11 @@ }, "flake-utils_3": { "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", "owner": "numtide", "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", "type": "github" }, "original": { @@ -60,11 +60,11 @@ }, "flake-utils_4": { "locked": { - "lastModified": 1653893745, - "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", "type": "github" }, "original": { @@ -110,11 +110,11 @@ "nixpkgs-regression": "nixpkgs-regression" }, "locked": { - "lastModified": 1678810370, - "narHash": "sha256-BdG980lgTKgk5qFf8oDM0TJgy6yE/69Lkx/bH9/t6Yg=", + "lastModified": 1679514902, + "narHash": "sha256-fjRU7bp7q6KDyYOrssYpPuY1Ysxl3y65kN8UP5p3tHI=", "owner": "NixOS", "repo": "nix", - "rev": "9ec1a3ae603c008bc135a12bcf746fdb7379e694", + "rev": "6dbce3215fa2e30e1daafcc70d6926cd97987612", "type": "github" }, "original": { @@ -128,11 +128,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1676728625, - "narHash": "sha256-AO+eWU3Dy7D2ug+gP7mww/wGVPUCwUYOBZ4BpSIxGGs=", + "lastModified": 1679429339, + "narHash": "sha256-awL8rI6jyuiTqukeFj3NPzBcGsh6NN76zVokbT3QGuE=", "owner": "cynerd", "repo": "nixbigclown", - "rev": "3b21db70b273a60380702a64160f7f6313f7be3e", + "rev": "bf268e296366dd65046781fe7fd0ecc1ab97540e", "type": "github" }, "original": { @@ -143,11 +143,11 @@ }, "nixos-hardware": { "locked": { - "lastModified": 1678397099, - "narHash": "sha256-5xq8YJe+h19TlD+EI4AE/3H3jcCcQ2AWU6CWBVc5tRc=", + "lastModified": 1679224149, + "narHash": "sha256-TSY37Zv0icF/aijR3/KWGLVBlnKKHlG9QTj7vHbF/UU=", "owner": "NixOS", "repo": "nixos-hardware", - "rev": "556101ff85bd6e20900ec73ee525b935154bc8ea", + "rev": "a4bc66709604ab78abc575b60baa6d23ae027a59", "type": "github" }, "original": { @@ -189,11 +189,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1676549890, - "narHash": "sha256-sq/WcOEAl7gWrrfGkWdnyYazRyTf+enEim/o6LOQzI8=", + "lastModified": 1679319606, + "narHash": "sha256-wyEMIZB6BnsmJWInEgDZu66hXVMGJEZFl5uDsn27f9M=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8c66bd1b68f4708c90dcc97c6f7052a5a7b33257", + "rev": "8bc6945b1224a1cfa679d6801580b1054dba1a5c", "type": "github" }, "original": { @@ -203,11 +203,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1678780369, - "narHash": "sha256-D8wM0K1EkWLwbUu9fohC57+n89zC9qQ3hdC9Bys5GYw=", + "lastModified": 1679457459, + "narHash": "sha256-2CbdQtEHH6G010dj9Y1C9sxDD9Rjs/Rfpg4WL4hb3TI=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1474943fd91fbe5567f7582acf568e0f999f4af1", + "rev": "c2111b6f27d057ab227e7a1341ea750c0cc76b7f", "type": "github" }, "original": { @@ -219,11 +219,11 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1654875595, - "narHash": "sha256-Vairke3ryPSFpgQdaYicPPhPWMGhtzm6V+1uF2Tefbk=", + "lastModified": 1678875422, + "narHash": "sha256-T3o6NcQPwXjxJMn2shz86Chch4ljXgZn746c2caGxd8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3f909fb574d9b9d7294e544981c62a4a5e4599fc", + "rev": "126f49a01de5b7e35a43fd43f891ecf6d3a51459", "type": "github" }, "original": { @@ -268,11 +268,11 @@ ] }, "locked": { - "lastModified": 1676728439, - "narHash": "sha256-SvxGjn3jWWrvqR17M1RH80IoCpkgc7/lIL0G/SRIEQE=", + "lastModified": 1679046678, + "narHash": "sha256-cey8/kfS9osL+j7wlHdoe+k1iA8S00tLXcaIqDrqBSM=", "owner": "cynerd", "repo": "nixturris", - "rev": "3e1cca1ec5f96d16afd00a2283b23e699afa4e74", + "rev": "064ae84040f3f20b691e16080dc1cf3e092ec0d8", "type": "github" }, "original": { @@ -317,11 +317,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1677148777, - "narHash": "sha256-e6UNalaZsRF+WvJG0xL/u/RnnRrzdvqIjAb0UZidyHA=", + "lastModified": 1679427965, + "narHash": "sha256-Dp3vbae4e/rbL1Gbdrt6e9CQyL5BLs/q+DvH3m8no2k=", "ref": "refs/heads/master", - "rev": "6f8f27349e074f2c9b6e7a359dad4f5656fc9db8", - "revCount": 89, + "rev": "7be0acbb1cd6b6d3c4c3df95611cb86be4b46915", + "revCount": 94, "type": "git", "url": "https://git.cynerd.cz/shellrc" }, @@ -370,11 +370,11 @@ }, "vpsadminos": { "locked": { - "lastModified": 1676020039, - "narHash": "sha256-QtbDsvjNAossXmVqrdoExe8oHDUEYzjHQgBoe1jx/Qg=", + "lastModified": 1679493489, + "narHash": "sha256-jvRGq0KMQ/e/hZLj0iqxhEVDAlX3DgRg17f1Dpda1K0=", "owner": "vpsfreecz", "repo": "vpsadminos", - "rev": "adab218ccacb0eee646ae21622bfb52f02606ce1", + "rev": "e8f56d93a6ceb5d58859219bd4a786d49447c15a", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 730ef12..74defe2 100644 --- a/flake.nix +++ b/flake.nix @@ -29,31 +29,18 @@ with flake-utils.lib; { lib = import ./lib nixpkgs.lib; - overlays.default = final: prev: - import ./pkgs { - inherit self; - nixpkgs = prev; - }; + overlays.default = final: import ./pkgs; nixosModules = import ./nixos self; nixosConfigurations = import ./nixos/configurations.nix self; } // eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages."${system}"; + pkgs = nixpkgs.legacyPackages."${system}".appendOverlays [ + shellrc.overlays.default + ]; in { - packages = filterPackages system (flattenTree ( - import ./pkgs { - inherit self; - nixpkgs = pkgs; - } - )); + packages = filterPackages system (flattenTree (import ./pkgs pkgs)); legacyPackages = pkgs.extend self.overlays.default; - devShells = - filterPackages system - (import ./devShells { - inherit nixpkgs; - inherit shellrc; - inherit system; - }); + devShells = filterPackages system (import ./devShells pkgs); formatter = pkgs.alejandra; }); } diff --git a/nixos/configurations.nix b/nixos/configurations.nix index 5dcb141..b96b0f6 100644 --- a/nixos/configurations.nix +++ b/nixos/configurations.nix @@ -26,10 +26,17 @@ with nixpkgs.lib; let system ? "x86_64-linux", extra_modules ? [], }: hostname: { - ${hostname} = nixpkgs.lib.nixosSystem { + ${hostname} = nixturris.lib.addBuildPlatform (nixpkgs.lib.nixosSystem { inherit system specialArgs; - modules = (modules hostname) ++ extra_modules; - }; + modules = + (modules hostname) + ++ extra_modules + ++ [ + { + nixpkgs.hostPlatform.system = system; + } + ]; + }); }; amd64System = genericSystem {}; vpsSystem = genericSystem { @@ -42,7 +49,6 @@ with nixpkgs.lib; let system = "armv7l-linux"; extra_modules = [ nixos-hardware.nixosModules.raspberry-pi-2 - nixturris.nixosModules.turris-crossbuild nixturris.nixosModules.armv7l-overlay ({pkgs, ...}: { boot.loader.systemd-boot.enable = false; @@ -53,7 +59,6 @@ with nixpkgs.lib; let raspi3System = genericSystem { system = "aarch64-linux"; extra_modules = [ - nixturris.nixosModules.turris-crossbuild ({pkgs, ...}: { boot.kernelPackages = pkgs.linuxPackages_rpi3; boot.initrd.includeDefaultModules = false; @@ -69,7 +74,6 @@ with nixpkgs.lib; let beagleboneSystem = genericSystem { system = "armv7l-linux"; extra_modules = [ - nixturris.nixosModules.turris-crossbuild nixturris.nixosModules.armv7l-overlay { boot.loader.grub.enable = false; @@ -83,8 +87,8 @@ with nixpkgs.lib; let genericSystem { inherit system; extra_modules = [ - nixturris.nixosModules.turris-crossbuild { + nixpkgs.hostPlatform.system = system; boot.loader.systemd-boot.enable = false; virtualisation.qemu.package = self.nixosConfigurations."${hostSystem}".pkgs.qemu; } diff --git a/nixos/modules/desktop.nix b/nixos/modules/desktop.nix index 04e5b82..3ae64a4 100644 --- a/nixos/modules/desktop.nix +++ b/nixos/modules/desktop.nix @@ -156,7 +156,6 @@ in { ]); programs = { vim.package = pkgs.vimHugeX; - shellrc.desktop = true; firefox.enable = true; light.enable = mkIf cnf.laptop true; }; diff --git a/nixos/modules/generic.nix b/nixos/modules/generic.nix index 309dd95..02498a3 100644 --- a/nixos/modules/generic.nix +++ b/nixos/modules/generic.nix @@ -5,7 +5,7 @@ ... }: with lib; let - isNative = config.nixpkgs.crossSystem == null; + isNative = config.nixpkgs.hostPlatform == config.nixpkgs.buildPlatform; in { config = { system.stateVersion = "22.05"; @@ -89,6 +89,7 @@ in { nethogs sshfs wakeonlan + speedtest-cli lm_sensors ] @@ -139,8 +140,11 @@ in { ]; }; }; - programs.zsh.enable = isNative; - programs.shellrc.enable = true; + programs.zsh = { + enable = isNative; + syntaxHighlighting.enable = isNative; + }; + programs.shellrc = true; programs.vim.defaultEditor = mkDefault true; security.sudo.extraRules = [ diff --git a/pkgs/default.nix b/pkgs/default.nix index d7d6989..f568186 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,13 +1,10 @@ -{ - self, - nixpkgs, -}: let - callPackage = nixpkgs.newScope personalpkgs; +pkgs: let + callPackage = pkgs.newScope personalpkgs; personalpkgs = rec { luks-hw-password = callPackage ./luks-hw-password {}; dev = callPackage ./dev { - devShells = self.devShells.${nixpkgs.system}; + devShells = import ../devShells pkgs; }; delft-icon-theme = callPackage ./theme/delft-icon-theme.nix {}; @@ -27,15 +24,6 @@ bigclown-leds = callPackage ./bigclown-leds {}; - # Package to be installed to the user's profile - cynerd-profile = nixpkgs.symlinkJoin { - name = "cynerd-profile"; - paths = [ - self.inputs.shellrc.packages.${nixpkgs.system}.default - nixpkgs.tig - ]; - }; - # Elektroline packages shvspy = callPackage ./shvspy {}; }; diff --git a/tools/common.sh b/tools/common.sh index 3f99479..fc4d99e 100644 --- a/tools/common.sh +++ b/tools/common.sh @@ -79,7 +79,7 @@ result() { # Get system of the device device_system() { - nix eval --raw ".#nixosConfigurations.$1.config.nixpkgs.system" + nix eval --raw ".#nixosConfigurations.$1.config.nixpkgs.hostPlatform.system" } build_system() { @@ -102,7 +102,7 @@ build() { local toplevel="config.system.build.toplevel" local bsystem="$(build_system)" if [ "$bsystem" != "$(device_system "$device")" ]; then - toplevel="config.system.build.cross.$bsystem.$toplevel" + toplevel="buildPlatform.$bsystem.$toplevel" fi stage "Building system for device: $device" -- cgit v1.2.3