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

fix(build): update nix flake to work with current NixOS unstable #152

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ venv.bak/

# pre-commit
.pre-commit-cache

# direnv
/.direnv

# Nix
result
115 changes: 106 additions & 9 deletions flake.lock

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

53 changes: 47 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,60 @@
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};

poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nix-github-actions.follows = "nix-github-actions";
inputs.treefmt-nix.follows = "treefmt-nix";
inputs.systems.follows = "systems";
};


# Unused but allows downstream to override versions and avoids duplicates

nix-github-actions = {
url = "github:nix-community/nix-github-actions";
inputs.nixpkgs.follows = "nixpkgs";
};

systems.url = "github:nix-systems/default";

treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, flake-utils, nixpkgs }: (flake-utils.lib.eachDefaultSystem (
outputs = { self, nixpkgs, ... }@inputs: (inputs.flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
openconnect-sso = (import ./nix { inherit pkgs; }).openconnect-sso;
poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; };

openconnect-pkgs = import ./nix {
inherit pkgs poetry2nix;
sources = null; # make sure we don't mix flakes and Niv
};
in
{
packages = { inherit openconnect-sso; };
defaultPackage = openconnect-sso;
packages = rec {
inherit (openconnect-pkgs) openconnect-sso;

default = openconnect-sso;
};

devShells.default = openconnect-pkgs.shell;
}
) // {
overlay = import ./overlay.nix;
overlays = rec {
default = openconnect-sso;

openconnect-sso = import ./overlay.nix;
};
});
}
27 changes: 10 additions & 17 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
{ sources ? import ./sources.nix
, pkgs ? import <nixpkgs> {
overlays = [ (import "${sources.poetry2nix}/overlay.nix") ];
}
, pkgs ? import <nixpkgs> { }
, poetry2nix ? import sources.poetry2nix { inherit pkgs; }
}:

let
qtLibsFor = with pkgs.lib; dep:
let
qtbase = head (filter (d: getName d.name == "qtbase") dep.nativeBuildInputs);
version = splitVersion qtbase.version;
majorMinor = concatStrings (take 2 version);
in
pkgs."libsForQt${majorMinor}";
inherit (pkgs) python3Packages qt6Packages;

inherit (qtLibsFor pkgs.python3Packages.pyqt5) callPackage;
pythonPackages = pkgs.python3Packages;

openconnect-sso = callPackage ./openconnect-sso.nix { inherit (pkgs) python3Packages; };
openconnect-sso = qt6Packages.callPackage ./openconnect-sso.nix { inherit poetry2nix; };

shell = pkgs.mkShell {
buildInputs = with pkgs; [
Expand All @@ -29,7 +19,7 @@ let
nixpkgs-fmt # To format Nix source files
poetry # Dependency manager for Python
] ++ (
with pythonPackages; [
with python3Packages; [
pre-commit # To check coding style during commit
]
) ++ (
Expand All @@ -50,7 +40,7 @@ let
'';
};

niv = if pkgs ? niv then pkgs.nim else pkgs.haskellPackages.niv;
niv = if pkgs ? niv then pkgs.niv else pkgs.haskellPackages.niv;

qtwrapper = pkgs.stdenv.mkDerivation {
name = "qtwrapper";
Expand All @@ -59,7 +49,10 @@ let
"\${qtWrapperArgs[@]}"
];
unpackPhase = ":";
nativeBuildInputs = [ pkgs.qt5.wrapQtAppsHook ];
nativeBuildInputs = with qt6Packages; [
wrapQtAppsHook qtbase
];

installPhase = ''
mkdir -p $out/bin
cat > $out/bin/wrap-qt <<'EOF'
Expand Down
56 changes: 45 additions & 11 deletions nix/openconnect-sso.nix
Original file line number Diff line number Diff line change
@@ -1,32 +1,66 @@
{ lib
, stdenv
, openconnect
, python3
, python3Packages
, poetry2nix
, substituteAll
, qt6Packages
, wrapQtAppsHook
}:

# Nixpkgs' qutebrowser derivation is a good reference to check if something breaks

poetry2nix.mkPoetryApplication {
src = lib.cleanSource ../.;
pyproject = ../pyproject.toml;
poetrylock = ../poetry.lock;
projectDir = ../.;
python = python3;
buildInputs = [ wrapQtAppsHook ];
propagatedBuildInputs = [ openconnect ];

dontWrapQtApps = true;
makeWrapperArgs = [
"\${qtWrapperArgs[@]}"
# Skip dev-dependencies (doesn't seem to work, but doesn't hurt)
groups = [ ];
checkGroups = [ ];

buildInputs = [
python3Packages.setuptools
];

nativeBuildInputs = [
wrapQtAppsHook
];

preferWheels = true;
propagatedBuildInputs = [
openconnect
] ++ lib.optional (stdenv.isLinux) qt6Packages.qtwayland;

dontWrapQtApps = true;
preFixup = ''
makeWrapperArgs+=(
# Force the app to use QT_PLUGIN_PATH values from wrapper
--unset QT_PLUGIN_PATH
"''${qtWrapperArgs[@]}"
# avoid persistant warning on starup
--set QT_STYLE_OVERRIDE Fusion
)
'';

# preferWheels = true;

overrides = [
poetry2nix.defaultPoetryOverrides
(
self: super: {
inherit (python3Packages) cryptography pyqt6 pyqt6-sip pyqt6-webengine six more-itertools;
inherit (python3Packages)
cryptography
lxml
more-itertools
pyqt6
pyqt6-sip
pyqt6-webengine
pysocks
requests
six;

coverage-enable-subprocess = super.coverage-enable-subprocess.overridePythonAttrs (old: {
propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.setuptools ];
});
}
)
];
Expand Down
14 changes: 7 additions & 7 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
"homepage": "https://github.com/nmattia/niv",
"owner": "nmattia",
"repo": "niv",
"rev": "351d8bc316bf901a81885bab5f52687ec8ccab6e",
"sha256": "1yzhz7ihkh6p2sxhp3amqfbmm2yqzaadqqii1xijymvl8alw5rrr",
"rev": "f7c538837892dd2eb83567c9f380a11efb59b53f",
"sha256": "0xl33k24vfc29cg9lnp95kvcq69qbq5fzb7jk9ig4lgrhaarh651",
"type": "tarball",
"url": "https://github.com/nmattia/niv/archive/351d8bc316bf901a81885bab5f52687ec8ccab6e.tar.gz",
"url": "https://github.com/nmattia/niv/archive/f7c538837892dd2eb83567c9f380a11efb59b53f.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"poetry2nix": {
"branch": "1.41.0",
"branch": "master",
"description": "Convert poetry projects to nix automagically [maintainer=@adisbladis] ",
"homepage": "",
"owner": "nix-community",
"repo": "poetry2nix",
"rev": "585f19cce38a7f75d5bc567b17060ec45bc63ed0",
"sha256": "0dj2a1wzcyilrc9fmfffx6d3bgq7zpawjadd7rphkkq8imh18y6a",
"rev": "d11c01e58587e5f21037ed6477465a7f26a32e27",
"sha256": "1z1m85izjn6gvghi9lqssbraz0gxkyi6ws8nlxy2l7lqs4dnq0sw",
"type": "tarball",
"url": "https://github.com/nix-community/poetry2nix/archive/585f19cce38a7f75d5bc567b17060ec45bc63ed0.tar.gz",
"url": "https://github.com/nix-community/poetry2nix/archive/d11c01e58587e5f21037ed6477465a7f26a32e27.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
2 changes: 1 addition & 1 deletion overlay.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
final: prev: {
inherit (prev.callPackage ./nix { pkgs = final; }) openconnect-sso;
inherit (import ./nix { pkgs = prev; }) openconnect-sso;
}
Loading