From f37924aa77febf720d91a644351e8a15edbc55fa Mon Sep 17 00:00:00 2001 From: Mathis Laroche Date: Wed, 30 Oct 2024 17:29:47 -0400 Subject: [PATCH 1/4] feat: added an easy way of adding more languages + added python313 to the languages --- flake.nix | 95 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 33 deletions(-) diff --git a/flake.nix b/flake.nix index 894891b..7dae8c0 100644 --- a/flake.nix +++ b/flake.nix @@ -9,44 +9,73 @@ # Helper functions forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); - nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; - overlays = [ self.overlay ]; }); + nixpkgsFor = forAllSystems (system: import nixpkgs { + inherit system; + overlays = [ self.overlays.default ]; + }); makeMerger = self: packageset: packagesetfunc: - let - gen = name: paths: self.buildEnv { - inherit name; - paths = [ - (packagesetfunc (ps: paths)) - ] ++ paths ; - ignoreCollisions = true; - meta.mainProgram = let - last = self.lib.last paths; in last.meta.mainProgram - or (builtins.parseDrvName last.name).name; - - # Use lists not attrsets because order matters - passthru = with builtins; mapAttrs (n: v: gen - (if length paths > 5 then "merged-environment" else "${name}-${n}") - (paths ++ [ v ]) - ) (self // packageset); - }; - in gen "merged" [ ]; - in { - overlay = self: super: { - "-" = self.pkgsMerge; - "+" = self.pkgsMerge; - pkgsMerge = makeMerger self super (paths: paths {}); - python2With = makeMerger self super.python2Packages super.python2.withPackages; - python3With = makeMerger self super.python3Packages super.python3.withPackages; - python39With = makeMerger self super.python39Packages super.python39.withPackages; - python310With = makeMerger self super.python310Packages super.python310.withPackages; - haskellWith = makeMerger self super.haskellPackages super.haskellPackages.ghcWithPackages; - perlWith = makeMerger self super.perlPackages super.perl.withPackages; + let + gen = name: paths: self.buildEnv { + inherit name; + paths = [ + (packagesetfunc (ps: paths)) + ] ++ paths; + ignoreCollisions = true; + meta.mainProgram = + let + last = self.lib.last paths; + in + last.meta.mainProgram + or (builtins.parseDrvName last.name).name; + + # Use lists not attrsets because order matters + passthru = with builtins; mapAttrs + (n: v: gen + (if length paths > 5 then "merged-environment" else "${name}-${n}") + (paths ++ [ v ]) + ) + (self // packageset); + }; + in + gen "merged" [ ]; + + addLanguage = { lang, langPackages ? lang + "Packages", withPackages ? "withPackages", langWith ? lang + "With" }: { + inherit lang langPackages withPackages langWith; }; + languages = [ + (addLanguage { lang = "python2"; }) + (addLanguage { lang = "python3"; }) + (addLanguage { lang = "python310"; }) + (addLanguage { lang = "python311"; }) + (addLanguage { lang = "python312"; }) + (addLanguage { lang = "python313"; }) + (addLanguage { lang = "perl"; }) + (addLanguage { lang = "haskel"; withPackages = "ghcWithPackages"; }) + ]; + + mergeLang = self: super: lang: makeMerger self super.${lang.langPackages} super.${lang.lang}.${lang.withPackages}; + in + { + overlays.default = final: prev: + let + self = final; + super = prev; + mergedLangs = builtins.map (lang: { ${lang.langWith} = mergeLang self super lang; }) languages; + in + builtins.foldl' (x: y: x // y) + { + "-" = self.pkgsMerge; + "+" = self.pkgsMerge; + pkgsMerge = makeMerger self super (paths: paths { }); + } + mergedLangs; + legacyPackages = forAllSystems (system: nixpkgsFor.${system}); - packages = forAllSystems (system: { inherit (nixpkgsFor.${system}) - pkgsMerge "+" "-" python3With ;}); + packages = forAllSystems (system: { + inherit (nixpkgsFor.${system}) pkgsMerge"+" "-" python3With; + }); defaultPackage = forAllSystems (system: self.packages."${system}".pkgsMerge); }; From c73fab686649df31eee42fa3506140cb358d73b2 Mon Sep 17 00:00:00 2001 From: Mathis Laroche Date: Wed, 30 Oct 2024 17:41:35 -0400 Subject: [PATCH 2/4] FIXED - a bug with haskell implementation --- flake.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 7dae8c0..43f33fd 100644 --- a/flake.nix +++ b/flake.nix @@ -40,8 +40,8 @@ in gen "merged" [ ]; - addLanguage = { lang, langPackages ? lang + "Packages", withPackages ? "withPackages", langWith ? lang + "With" }: { - inherit lang langPackages withPackages langWith; + addLanguage = { lang, langRepo ? lang, langPackages ? lang + "Packages", withPackages ? "withPackages", langWith ? lang + "With" }: { + inherit lang langPackages withPackages langWith langRepo; }; languages = [ @@ -52,10 +52,10 @@ (addLanguage { lang = "python312"; }) (addLanguage { lang = "python313"; }) (addLanguage { lang = "perl"; }) - (addLanguage { lang = "haskel"; withPackages = "ghcWithPackages"; }) + (addLanguage { lang = "haskell"; langRepo = "haskellPackages"; withPackages = "ghcWithPackages"; }) ]; - mergeLang = self: super: lang: makeMerger self super.${lang.langPackages} super.${lang.lang}.${lang.withPackages}; + mergeLang = self: super: lang: makeMerger self super.${lang.langPackages} super.${lang.langRepo}.${lang.withPackages}; in { overlays.default = final: prev: From 4adf92c6845f8e5a49428a6cfe82d8e713a78f32 Mon Sep 17 00:00:00 2001 From: Mathis Laroche Date: Wed, 30 Oct 2024 17:50:25 -0400 Subject: [PATCH 3/4] UPDATED README - to add missing supported languages --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index b15ad7f..c53a003 100644 --- a/README.md +++ b/README.md @@ -49,5 +49,8 @@ See the [documentation](https://nixos.org/manual/nix/stable/command-ref/new-cli/ - Python3 (`python3With`) - Python39 (`python39With`) - Python310 (`python310With`) +- Python311 (`python311With`) +- Python312 (`python312With`) +- Python313 (`python313With`) - Haskell (`haskellWith`) - Perl (`perlWith`) From 6b7300b93fdef4437b69c9b9a4b679ebba88edda Mon Sep 17 00:00:00 2001 From: Mathis Laroche Date: Wed, 30 Oct 2024 18:10:32 -0400 Subject: [PATCH 4/4] UPDATED README Specified a way of making the PATH shorter by using the registry system in nix. --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index c53a003..c25a400 100644 --- a/README.md +++ b/README.md @@ -13,16 +13,34 @@ nix shell #[.. ...] - `LANGUAGE` is the name of the language (see [Supported Languages](#supported-languages)) - `PKGS` are the package names (separated by `.`) that will be included with the language + +### Make the `` shorter + +To avoid having to write `github:tomberek/-` each time (which can be quite verbose), +you can run this command in your shell: +```sh +nix registry add flake:lang github:tomberek/- +``` +> PS: you can change the registry name to anything you like, `lang` is just an example :) + +After, you only have to prefix `lang` as the `` of the command. + ### Examples Start a shell environment with python and the packages `scipy`, `matplotlib`, and `numpy`: ```sh nix shell github:tomberek/-#python3With.scipy.matplotlib.numpy + +# If you added the registry +nix shell lang#python3With.scipy.matplotlib.numpy ``` Start a shell environment with perl and the packages `HTMLTokeParserSimple` and `LWP`: ```sh nix shell github:tomberek/-#perlWith.HTMLTokeParserSimple.LWP + +# If you added the registry +nix shell lang#perlWith.HTMLTokeParserSimple.LWP ```