Skip to content
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

[Feature] Nix Flake #459

Merged
merged 23 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ stregsystem/*-tokens.json.bak

# ignore default log file location
stregsystem.log

# nix
.direnv
.envrc
result
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ For Ubuntu with virtual envs:
5. ???
6. Profit

For systems running the Nix package manager:
1. Configure Nix to use nix-command and flakes
- `echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf`
2. Start shell
- `nix develop`
2. Or run the system
- `nix run . testserver stregsystem/fixtures/testdata.json`
3. ???
4. Profit

For Mac users with virtual envs:
1. Install python3.11 with pip
- `brew install [email protected]`
Expand All @@ -43,7 +53,6 @@ For Mac users with virtual envs:
5. ???
6. Profit


Using Testdata
--------
In order to simplify development for all, we have included a test fixture.
Expand Down
26 changes: 26 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
description = "F-klubbens Stregsystem";

# define nixpkgs version to use
inputs = {
nixpkgs.url = "nixpkgs/nixos-24.05";
};

outputs = { self, nixpkgs }: let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };

dependencies = import ./nix-support { inherit pkgs; };

in {
# Define the shell, here we're just setting the packages required for the devshell
devShells.${system}.default = pkgs.mkShell {
packages = (dependencies pkgs.python311Packages) ++ [pkgs.mailhog pkgs.black];
};

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

installPhase = ''
mkdir -p $out/bin
mkdir -p $out/share/stregsystemet

cp local.cfg.skel local.cfg
echo "${env.interpreter} $out/share/stregsystemet/manage.py \$@" > $out/bin/stregsystemet
sed -i '1 i #!${pkgs.bash}/bin/bash' $out/bin/stregsystemet
chmod +x $out/bin/stregsystemet

sed -i '1d' manage.py

cp ./* $out/share/stregsystemet -r
'';
};
};
}
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
20 changes: 20 additions & 0 deletions nix-support/django-select2.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{pkgs, py}:

py.buildPythonPackage {
pname = "Django-Select2";
version = "8.1.2";
src = pkgs.fetchurl {
url = "https://files.pythonhosted.org/packages/7f/af/2fc371e1dea6686b588ab9cd445e55b63248a525f8c90550767a42dd77bb/django_select2-8.1.2.tar.gz";
sha256 = "sha256-9EaF7hw5CQqt4B4+vCVnAvBWIPPHijwmhECtmmYHCHY=";
};
format = "pyproject";
doCheck = false;
buildInputs = [];
checkInputs = [];
nativeBuildInputs = [];
propagatedBuildInputs = [
py.django-appconf
py.flit-scm
];
}