Skip to content

Commit

Permalink
Merge pull request #122 from vlaci/flake
Browse files Browse the repository at this point in the history
Added initial flake support
  • Loading branch information
vlaci authored Jul 14, 2023
2 parents 222c8ff + 28c87a2 commit eab3c19
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 29 deletions.
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(import ./nix {}).openconnect-sso
(import ./nix { }).openconnect-sso
40 changes: 40 additions & 0 deletions flake.lock

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

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

outputs = { self, flake-utils, nixpkgs }: (flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
openconnect-sso = (import ./nix { inherit pkgs; }).openconnect-sso;
in
{
packages = { inherit openconnect-sso; };
defaultPackage = openconnect-sso;
}
) // {
overlay = import ./overlay.nix;
});
}
55 changes: 30 additions & 25 deletions nix/sources.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ let
$ niv modify <package> -a type=tarball -a builtin=true
''
builtins_fetchTarball { inherit (spec) url sha256; };
builtins_fetchTarball
{ inherit (spec) url sha256; };

fetch_builtin-url = spec:
builtins.trace
Expand Down Expand Up @@ -58,19 +59,20 @@ let
if hasNixpkgsPath
then
if hasThisAsNixpkgsPath
then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}
else import <nixpkgs> {}
then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) { }
else import <nixpkgs> { }
else
import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {};
import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) { };

sources_nixpkgs =
if builtins.hasAttr "nixpkgs" sources
then sources.nixpkgs
else abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';

hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success;
hasThisAsNixpkgsPath =
Expand Down Expand Up @@ -102,27 +104,30 @@ let
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
else
fetchTarball attrs;
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
else
fetchTarball attrs;

# fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12" then
fetchurl { inherit url; }
else
fetchurl attrs;
if lessThan nixVersion "1.12" then
fetchurl { inherit url; }
else
fetchurl attrs;

in
mapAttrs (
name: spec:
if builtins.hasAttr "outPath" spec
then abort
"The values in sources.json should not have an 'outPath' attribute"
else
spec // { outPath = fetch name spec; }
) sources
mapAttrs
(
name: spec:
if builtins.hasAttr "outPath" spec
then
abort
"The values in sources.json should not have an 'outPath' attribute"
else
spec // { outPath = fetch name spec; }
)
sources
4 changes: 2 additions & 2 deletions overlay.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
self: super: {
inherit (super.callPackage ./nix { pkgs = self; }) openconnect-sso;
final: prev: {
inherit (prev.callPackage ./nix { pkgs = final; }) openconnect-sso;
}
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(import ./nix {}).shell
(import ./nix { }).shell

0 comments on commit eab3c19

Please sign in to comment.