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

flake based on Nixpkgs Python #163

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
64 changes: 64 additions & 0 deletions flake.lock

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

31 changes: 31 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
description = "Description for the project";

inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:hercules-ci/nixpkgs/update-nixops_unstable";
};

outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
];
debug = true;
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }: {
packages.nixops_with_aws =
(pkgs.nixops_unstable_minimal.addAvailablePlugins (self: super: {
nixops-aws = super.callPackage ./nix/nixops-aws.nix { };
})).withPlugins (plugins: [ plugins.nixops-aws ]);
packages.plugin = config.packages.nixops_with_aws.availablePlugins.nixops-aws;
# `plugin` would have been a valid choice, but a nixops is more useful. It builds fast.
packages.default = config.packages.nixops_with_aws;
devShells.default =
pkgs.mkShell {
inputsFrom = [ config.packages.plugin ];
};
};
flake = {
};
};
}
62 changes: 62 additions & 0 deletions nix/nixops-aws.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{ lib
, buildPythonPackage
, fetchFromGitHub
, unstableGitUpdater
, poetry-core
, boto
, boto3
, nixops
, nixos-modules-contrib
, typing-extensions
}:

buildPythonPackage {
pname = "nixops-aws";
version = "unstable-2023-08-09";
pyproject = true;

src =
with lib.fileset;
toSource {
root = ../.;
fileset = unions [
../nixops_aws
../pyproject.toml
../setup.cfg
../tests
../tests.py
];
};

postPatch = ''
substituteInPlace pyproject.toml \
--replace poetry.masonry.api poetry.core.masonry.api \
--replace "poetry>=" "poetry-core>="
'';

nativeBuildInputs = [
poetry-core
];

buildInputs = [
nixops
];

propagatedBuildInputs = [
boto
boto3
nixos-modules-contrib
typing-extensions
];

pythonImportsCheck = [ "nixops_aws" ];

passthru.updateScript = unstableGitUpdater {};

meta = with lib; {
description = "AWS plugin for NixOps";
homepage = "https://github.com/NixOS/nixops-aws";
license = licenses.lgpl3Only;
maintainers = nixops.meta.maintainers;
};
}
39 changes: 26 additions & 13 deletions nixops_aws/nix/ec2.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Configuration specific to the EC2 backend.

{ config, pkgs, lib, utils, ... }:
{ config, pkgs, lib, options, utils, ... }:

with utils;
with lib;
with import ./lib.nix lib;

let
throwIf = lib.throwIf or (cond: msg: if cond then throw msg else x: x);

types =
if lib.types ? either then
Expand Down Expand Up @@ -165,7 +166,21 @@ let

nixosVersion = builtins.substring 0 5 (config.system.nixos.version or config.system.nixosVersion);

amis = import <nixpkgs/nixos/modules/virtualisation/ec2-amis.nix>;
amisLegacy = import (pkgs.path + "/nixos/modules/virtualisation/ec2-amis.nix");

amisPath = pkgs.path + "/nixos/modules/virtualisation/amazon-ec2-amis.nix";
amis = import amisPath;

lookupAMI = { nixosVersion, region, system, virtType }:
assert builtins.trace "Looking up AMI for ${nixosVersion} in ${region} for ${system} with ${virtType}..." true;
if builtins.pathExists amisPath
then
(((amis.${nixosVersion} or amis.latest)
.${region} or (throw "No AMIs for region ${region}"))
.${system} or (throw "No AMIs for instance type ${system} in region ${region}"))
.${virtType} or (throw "No AMI for virtualisation type ${virtType} on instance type ${system} in region ${region}")
else
(amisLegacy.${nixosVersion} or amisLegacy.latest).${region}.${virtType};

in

Expand Down Expand Up @@ -484,7 +499,7 @@ in

config = mkIf (config.deployment.targetEnv == "ec2") {

nixpkgs.hostPlatform =
nixpkgs.${if options?nixpkgs.hostPlatform then "hostPlatform" else "system"} =
let
checked =
throwIf (config.deployment.ec2.physicalProperties.platforms or [] == [])
Expand All @@ -507,7 +522,7 @@ in
< ranking.${b.cpu} or unrankedRank;

systemString =
lib.throwIf (plat.os or "linux" != "linux")
throwIf (plat.os or "linux" != "linux")
"Instance does not seem to be intended for running Linux. Please set nixpkgs.hostPlatform manually."
plat.cpu + "-linux";
in
Expand All @@ -516,20 +531,18 @@ in
deployment.ec2.ami = mkDefault (
let
# FIXME: select hvm-s3 AMIs if appropriate.
type =
virtType =
if isEc2Hvm then
if cfg.ebsBoot then "hvm-ebs" else "hvm-s3"
else
if cfg.ebsBoot then "pv-ebs" else "pv-s3";
amis' = amis."${nixosVersion}" or amis.latest;
in
with builtins;
if hasAttr cfg.region amis' then
let r = amis'."${cfg.region}";
in if hasAttr type r then r."${type}" else
throw "I don't know an AMI for virtualisation type ${type} with instance type ${cfg.instanceType}"
else
throw "I don't know an AMI for region ‘${cfg.region}’ and platform type ‘${config.nixpkgs.hostPlatform.system}’"
lookupAMI {
inherit virtType;
inherit nixosVersion;
inherit (cfg) region;
system = config.nixpkgs.hostPlatform.system or config.nixpkgs.system;
}
);

# Workaround: the evaluation of blockDeviceMapping requires fileSystems to be defined.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ python = "^3.7"
boto = "^2.49.0"
boto3 = "^1.13.7"
nixops = {git = "https://github.com/NixOS/nixops.git", rev = "master"}
typing-extensions = "^3.7.4"
typing-extensions = ">=3.7 <=5"
nixos-modules-contrib = {git = "https://github.com/nix-community/nixos-modules-contrib.git", rev = "master"}

[tool.poetry.dev-dependencies]
Expand Down
Loading