From e2abde8b28153c9b8a67906618d06c0fac16b563 Mon Sep 17 00:00:00 2001 From: Jan-Bulthuis Date: Sun, 9 Feb 2025 01:11:07 +0100 Subject: [PATCH] Changes --- flake.lock | 40 ++++++++++++++++++-- shell-modules/default.nix | 28 ++++++++++---- shell-modules/languages/python.nix | 35 +++++++++++++++++ shell-modules/shell.nix | 18 ++++++++- shell-modules/utilities/cuda.nix | 17 +++++++++ user-modules/development/default.nix | 2 + user-modules/development/language/python.nix | 5 +-- users/jan.nix | 10 ----- 8 files changed, 129 insertions(+), 26 deletions(-) create mode 100644 shell-modules/utilities/cuda.nix diff --git a/flake.lock b/flake.lock index ed8d5eb..379efc2 100644 --- a/flake.lock +++ b/flake.lock @@ -210,6 +210,24 @@ } }, "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { "inputs": { "systems": [ "stylix", @@ -589,7 +607,7 @@ }, "nuschtosSearch": { "inputs": { - "flake-utils": "flake-utils", + "flake-utils": "flake-utils_2", "ixx": "ixx", "nixpkgs": [ "nixvim", @@ -612,6 +630,7 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", "home-manager": "home-manager", "nix-matlab": "nix-matlab", "nixpkgs": "nixpkgs", @@ -628,12 +647,12 @@ "base16-vim": "base16-vim", "firefox-gnome-theme": "firefox-gnome-theme", "flake-compat": "flake-compat_3", - "flake-utils": "flake-utils_2", + "flake-utils": "flake-utils_3", "git-hooks": "git-hooks_2", "gnome-shell": "gnome-shell", "home-manager": "home-manager_3", "nixpkgs": "nixpkgs_3", - "systems": "systems_2", + "systems": "systems_3", "tinted-foot": "tinted-foot", "tinted-kitty": "tinted-kitty", "tinted-tmux": "tinted-tmux", @@ -683,6 +702,21 @@ "type": "github" } }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "tinted-foot": { "flake": false, "locked": { diff --git a/shell-modules/default.nix b/shell-modules/default.nix index 1eaebad..55ba908 100644 --- a/shell-modules/default.nix +++ b/shell-modules/default.nix @@ -1,8 +1,14 @@ -{ nixpkgs, flake-utils, ... }: +{ + nixpkgs, + flake-utils, + ... +}: let imports = [ + ./shell.nix ./languages/python.nix + ./utilities/cuda.nix ]; in { @@ -16,15 +22,21 @@ in inherit system; config.allowUnfree = true; }; - modules = [ - attrs - ] ++ imports; - evaluated = nixpkgs.lib.evalModules { inherit modules; }; + evaluated = + (nixpkgs.lib.evalModules { + modules = [ attrs ] ++ imports; + specialArgs = { + pkgs = pkgs; + }; + }).config; + recUpdate = nixpkgs.lib.recursiveUpdate; + shell = recUpdate { + env = evaluated.env; + packages = evaluated.packages ++ (evaluated.extraPackages pkgs); + } evaluated.override; in { - devShells.default = pkgs.mkShell { - TEST_ENV = builtins.trace evaluated.config "HELLO"; - }; + devShells.default = pkgs.mkShell shell; } )); } diff --git a/shell-modules/languages/python.nix b/shell-modules/languages/python.nix index e69de29..0d209cc 100644 --- a/shell-modules/languages/python.nix +++ b/shell-modules/languages/python.nix @@ -0,0 +1,35 @@ +{ + pkgs, + lib, + config, + ... +}: + +with lib; +{ + options.python = { + enable = mkEnableOption "Python"; + packages = mkOption { + type = types.functionTo (types.listOf types.package) // { + merge = + loc: defs: p: + lib.concatMap (def: (def.value p)) defs; + }; + default = p: [ ]; + description = "Python packages to install"; + }; + # TODO: Add option to directly read from requirements.txt, maybe with mach-nix + }; + + config = mkIf config.python.enable { + packages = + with pkgs; + let + packages = config.python.packages; + pythonPackage = python3.withPackages packages; + in + [ + pythonPackage + ]; + }; +} diff --git a/shell-modules/shell.nix b/shell-modules/shell.nix index 64015a4..5d3d1f6 100644 --- a/shell-modules/shell.nix +++ b/shell-modules/shell.nix @@ -5,7 +5,7 @@ with lib; options = { env = mkOption { type = types.attrsOf types.str; - default = [ ]; + default = { }; }; packages = mkOption { @@ -13,5 +13,21 @@ with lib; default = [ ]; description = "Packages to install"; }; + + extraPackages = mkOption { + type = types.functionTo (types.listOf types.package) // { + merge = + loc: defs: p: + lib.concatMap (def: (def.value p)) defs; + }; + default = p: [ ]; + description = "Extra packages to install"; + }; + + override = mkOption { + type = types.attrs; + default = { }; + description = "Settings in the mkShell call to override"; + }; }; } diff --git a/shell-modules/utilities/cuda.nix b/shell-modules/utilities/cuda.nix new file mode 100644 index 0000000..5781785 --- /dev/null +++ b/shell-modules/utilities/cuda.nix @@ -0,0 +1,17 @@ +{ + pkgs, + lib, + config, + ... +}: + +with lib; +{ + options.cuda = { + enable = mkEnableOption "CUDA"; + }; + + config = mkIf config.cuda.enable { + + }; +} diff --git a/user-modules/development/default.nix b/user-modules/development/default.nix index ca88216..510de54 100644 --- a/user-modules/development/default.nix +++ b/user-modules/development/default.nix @@ -4,6 +4,8 @@ imports = [ ./ide/mathematica.nix ./ide/matlab.nix + # TODO: Move languages to make clear it is just IDE configuration + # Languages should be installed with devShells, however the IDE must be configured globally ./language/cpp.nix ./language/haskell.nix ./language/js.nix diff --git a/user-modules/development/language/python.nix b/user-modules/development/language/python.nix index 0d16ac7..2680023 100644 --- a/user-modules/development/language/python.nix +++ b/user-modules/development/language/python.nix @@ -8,7 +8,6 @@ with lib; let cfg = config.modules.python; - package = pkgs.python3.withPackages cfg.extraPythonPackages; in { options.modules.python = { @@ -26,9 +25,7 @@ in config = mkIf cfg.enable { # Development packages - home.packages = [ - package - ]; + home.packages = [ ]; # Allow unfree modules.unfree.allowedPackages = [ diff --git a/users/jan.nix b/users/jan.nix index b0007aa..f20812e 100644 --- a/users/jan.nix +++ b/users/jan.nix @@ -109,16 +109,6 @@ tex.enable = true; jupyter.enable = true; - # python.extraPythonPackages = p: [ - # p.numpy - # p.scikit-learn - # p.scipy - # p.pandas - # p.matplotlib - # p.torch - # p.torchvision - # ]; - # Enable unfree unfree.enable = true; };