Skip to content

Commit

Permalink
Merge pull request #2 from Mast3rwaf1z/fix-nix-flake
Browse files Browse the repository at this point in the history
rewrote the functionality of the nix flake, removed hashes from requi…
  • Loading branch information
Mast3rwaf1z authored Sep 25, 2024
2 parents 44b6b7f + a47faa0 commit 4d71d9a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 57 deletions.
52 changes: 3 additions & 49 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,7 @@
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };

# Custom package as django-select2 is not in nixpkgs
django-select2 = pkgVersion: pkgs.python311Packages.buildPythonPackage rec {
pname = "django_select2";
name = "django_select2";
version = pkgVersion;
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "sha256-9EaF7hw5CQqt4B4+vCVnAvBWIPPHijwmhECtmmYHCHY=";
};
format = "pyproject";
doCheck = false;
propagatedBuildInputs = [pkgs.python311Packages.flit-scm pkgs.python311Packages.django-appconf];
};

# Based on requirements.txt, determine dependencies to fetch from nixpkgs
requirements = ./requirements.txt;
# Read file and split it into lines
lines = pkgs.lib.lists.remove "" (pkgs.lib.strings.splitString "\n" (builtins.readFile requirements));

# Map a function to convert the list of strings into a list of derivations
dependencies = ver: builtins.map
(package: let
# pkgList is a function defined here via currying, it will just return the item at index in the list generated after splitting by ==
pkgList = builtins.elemAt (pkgs.lib.strings.splitString "==" package);
pkgName = pkgs.lib.strings.toLower (pkgList 0);
pkgVersion = builtins.elemAt (pkgs.lib.strings.splitString " #" (pkgList 1)) 0;
pkgHash = builtins.elemAt (pkgs.lib.strings.splitString " #" (pkgList 1)) 1;
# Instead of fetching from nixpkgs, evaluate a custom version of django-select2
in if pkgName == "django-select2" then
django-select2 pkgVersion
else
# Add the standard derivation of the package, attempt to set the version
ver."${pkgName}".overrideAttrs {
version = pkgVersion;
src = pkgs.fetchPypi {
pname = if pkgName == "django" then
"Django"
else if pkgName == "django-debug-toolbar" then
"django_debug_toolbar"
else pkgName;
version = pkgVersion;
sha256 = pkgHash;
};
installCheckPhase = ''echo "lmao django borked"'';
}
)
lines;
dependencies = import ./nix-support { inherit pkgs; };

in {
# Define the shell, here we're just setting the packages required for the devshell
Expand All @@ -66,9 +20,9 @@

# Default package for the stregsystem
packages.${system}.default = let
env = pkgs.python3.withPackages (py: dependencies);
env = pkgs.python311.withPackages dependencies;
in pkgs.stdenv.mkDerivation {
pname = "Stregsystemet";
pname = "stregsystemet";
version = "latest";
src = ./.;

Expand Down
8 changes: 8 additions & 0 deletions nix-support/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{pkgs}: let
# Based on requirements.txt, determine dependencies to fetch from nixpkgs
requirements = ../requirements.txt;
# Read file and split it into lines
lines = pkgs.lib.lists.remove "" (pkgs.lib.strings.splitString "\n" (builtins.readFile requirements));
packages = map (pkg: builtins.elemAt (pkgs.lib.strings.splitString "==" pkg) 0) lines;
filteredPackages = builtins.filter (pkg: pkg != "Django-Select2") packages;
in py: [(pkgs.callPackage ./django-select2.nix { inherit pkgs py; })] ++ map (pkg: py.${pkgs.lib.toLower pkg}) filteredPackages
19 changes: 19 additions & 0 deletions nix-support/django-select2.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{pkgs, py}:

py.buildPythonPackage {
pname = "Django-Select2";
version = "5.11.1";
src = pkgs.fetchurl {
url = "https://files.pythonhosted.org/packages/a9/67/4a511634562a3108261d6497bd2d6e40af957b9d3d75f30ec95cc68ccf0b/Django-Select2-5.11.1.tar.gz";
sha256 = "06gb79wikwcwbsny6dz9vp8qv66k0ri8xfd0h3hay58rc7mkrg2a";
};
format = "setuptools";
doCheck = false;
buildInputs = [];
checkInputs = [];
nativeBuildInputs = [];
propagatedBuildInputs = [
(py.django-appconf)
];
}

16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Django==4.1.13 #sha256-lKP0cegzyPEk7not4R6S9jOZHZdeP6W92R6KvWZCYxg=
Pillow==10.3.0 #sha256-nSRV+/RMkUhAx5PomqgtDhdjoUJToAB0NxmuWUaBSy0=
Coverage==7.5.1 #sha256-VN6e86namB96+T6v3k7eGZ4IRs2BnrJ8iOK3EqrpcIw=
pytz==2024.1 #sha256-KilzXqnBi68UtEiEa95aSAMO0mdXhHLYlVzQ50Q6mBI=
freezegun==1.5.1 #sha256-sp3t/NptXo4IPOcbK1QnU61Iz+xEA3s/x5cC4pgKiek=
Django==4.1.13
Pillow==10.3.0
Coverage==7.5.1
pytz==2024.1
freezegun==1.5.1
Django-Select2==8.1.2 #
django-debug-toolbar==4.3.0 #sha256-Cw3d7l6im5y2eFk7wNem12sh13mcto4JGiFINBqA88Q=
requests==2.32.0 #sha256-+lSQMZR0yC7x0sm8RZ02UuOuTvTE690YohFFpHyktrg=
qrcode==7.4.2 #sha256-ndlpRUgn4Sfb2TaWsgdHI55tVA4IKTfJDxSslbMPWEU=
django-debug-toolbar==4.3.0
requests==2.32.0
qrcode==7.4.2

0 comments on commit 4d71d9a

Please sign in to comment.